Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
xsens::List< T > Class Template Reference

Detailed Description

template<typename T>
class xsens::List< T >

Dynamic list class.

This class can store items of the given type. If the type supports the < operator it can also be sorted. Items in the list can be accessed through the [] operator or the get() function.

 Do NOT use any item type that requires a constructor to work correctly.

Pointers to these objects can work though.

Definition at line 64 of file xsens_list.h.

#include <xSens_MT3/xsens_list.h>

Inheritance diagram for xsens::List< T >:
Inheritance graph

Public Types

typedef int32_t(* cmpFunc) (const T &, const T &)
 A comparison function type, should return -1, 0 or 1 for <, == and > More...
 
typedef int32_t(__cdecl * InequalityFunction) (const T &, const T &)
 Type for an equality compare function, should return true when NOT equal. More...
 

Public Member Functions

 List ()
 Standard constructor, creates an empty list with some room for items. More...
 
 List (const uint32_t size)
 Construct a list with a capacity of at least the given size. More...
 
 List (const List< T > &src)
 Construct a list as a direct copy of another list. More...
 
 List (const uint32_t size, const T *src)
 Construct a list as a copy of a raw list. More...
 
 ~List ()
 Destroy the list. This does NOT automatically delete items IN the list. More...
 
void deleteAndClear (void)
 Calls delete for all items in the list and then clears the list. More...
 
void freeAndClear (void)
 Calls free for all items in the list and then clears the list. More...
 
void clear (void)
 Clears the list without explicitly deleting anything. More...
 
void resize (uint32_t newSize)
 Resizes the list to at least the given size. More...
 
void append (const T &item)
 Adds an item to the end of the list. More...
 
void appendList (uint32_t count, const T *lst)
 Adds a number of items to the end of the list. More...
 
void appendDeepCopy (const List< T > &source)
 Adds the contents of the source list to the end of the list. More...
 
void appendShallowCopy (const List< T > &source)
 Adds the contents of the source list to the end of the list. More...
 
template<typename TB >
void appendCopy (const TB &item)
 Adds a copy of a referenced item to the end of the list. More...
 
template<typename TR >
void appendRelated (const TR &item)
 Adds a related item to the end of the list, using the T = TR operator. More...
 
void remove (const uint32_t index) XSENS_LIST_THROW
 Removes an item at the given index in the list. More...
 
void swap (const uint32_t i, const uint32_t j) XSENS_LIST_THROW
 Swaps two items in the list. More...
 
void deleteAndRemove (const uint32_t index) XSENS_LIST_THROW
 Removes an item at the given index in the list. More...
 
void freeAndRemove (const uint32_t index) XSENS_LIST_THROW
 Removes an item at the given index in the list. More...
 
T & last (void) const XSENS_LIST_THROW
 Retrieves the last item. More...
 
T & get (const uint32_t index) const XSENS_LIST_THROW
 Retrieves the item at the given index. More...
 
T & operator[] (const uint32_t index) const XSENS_LIST_THROW
 Retrieves the item at the given index. More...
 
void insert (const T &item, const uint32_t index)
 Inserts an item at the given index, shifting any items below it down one spot. More...
 
template<typename TB >
void insertCopy (const TB &item, const uint32_t index)
 Inserts a copy of the referenced item at the given index, shifting any items below it down one spot. More...
 
uint32_t insertSorted (const T &item)
 Assumes the list is sorted and inserts the item at the appropriate spot. More...
 
uint32_t insertSortedDeref (const T &item)
 Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot. More...
 
template<typename TB >
uint32_t insertSortedCopy (const TB &item)
 Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot. More...
 
uint32_t length (void) const
 Returns the number of items currently in the list. More...
 
void sortAscending (void)
 Sorts the list in an ascending order, using the T::< operator. More...
 
void sortAscendingDeref (void)
 Sorts the list in an ascending order, using the T::< operator on dereferenced list items. More...
 
template<typename T2 >
void twinSortAscending (List< T2 > &twin)
 Sorts the first list in an ascending order, using the T::< operator, the second list will be updated the same way. More...
 
template<typename TB >
uint32_t find (const TB &item) const
 Finds an item in an unsorted list (walk over all items) using the T::== operator. More...
 
template<typename TB >
uint32_t findDeref (const TB &item) const
 Finds an item in an unsorted list (walk over all items) using the T::== operator on dereferenced list items. More...
 
template<typename TB >
uint32_t findSorted (const TB &item) const
 Finds an item in a sorted list (binary search) using the T::== and T::< operators. More...
 
template<typename TB >
uint32_t findSortedDeref (const TB &item) const
 Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items. More...
 
void reverse (void)
 Reverse the order of the list, useful for sorted lists that are read/created in the reverse order. More...
 
void removeTail (const uint32_t count) XSENS_LIST_THROW
 Removes items from the end of the list. More...
 
void deleteAndRemoveTail (const uint32_t count) XSENS_LIST_THROW
 
void freeAndRemoveTail (const uint32_t count) XSENS_LIST_THROW
 
uint32_t find (const T item, InequalityFunction fnc) const
 Finds an item in an unsorted list (walk over all items) using the given inequality function. More...
 
void deleteItemsOnDestroy (void)
 
void freeItemsOnDestroy (void)
 
uint32_t removeDuplicateEntries (void)
 Removes any duplicate entries and returns the number of items removed. More...
 
uint32_t removeDuplicateEntriesDeref (void)
 Removes any duplicate entries and returns the number of items removed. More...
 
template<typename TB >
void isDeepCopyOf (const List< T > &source)
 Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i]) More...
 
void isShallowCopyOf (const List< T > &source)
 Overwrites the current list with a shallow (memcopy) copy of another list. More...
 
const T * getBuffer (void) const
 Returns the start of the linear data buffer. More...
 

Protected Member Functions

 List (const uint32_t size, T *src, bool manage)
 Construct a list as a reference to a raw list. More...
 

Protected Attributes

T * m_data
 The array containing the items. More...
 
uint32_t m_max
 The current size of the data array. More...
 
uint32_t m_count
 The number of items currently in the list. More...
 
JanitorClassFunc< List< T > > * m_jcf
 Used to clean up the list on exit. More...
 
bool m_manage
 

Private Member Functions

void operator= (const List &list)
 intentionally NOT implemented due to ambiguous nature More...
 
void qSort (uint32_t left, uint32_t right)
 Sorts the list in an ascending order, using the T::< operator. More...
 
void qSortDeref (uint32_t left, uint32_t right)
 Sorts the list in an ascending order, using the T::< operator on dereferenced list items. More...
 

Member Typedef Documentation

◆ cmpFunc

template<typename T>
typedef int32_t(* xsens::List< T >::cmpFunc) (const T &, const T &)

A comparison function type, should return -1, 0 or 1 for <, == and >

Definition at line 91 of file xsens_list.h.

◆ InequalityFunction

template<typename T>
typedef int32_t(__cdecl* xsens::List< T >::InequalityFunction) (const T &, const T &)

Type for an equality compare function, should return true when NOT equal.

Definition at line 194 of file xsens_list.h.

Constructor & Destructor Documentation

◆ List() [1/5]

template<typename T>
xsens::List< T >::List ( const uint32_t  size,
T *  src,
bool  manage 
)
protected

Construct a list as a reference to a raw list.

Definition at line 89 of file xsens_list.hpp.

◆ List() [2/5]

template<typename T>
xsens::List< T >::List ( )

Standard constructor, creates an empty list with some room for items.

Definition at line 38 of file xsens_list.hpp.

◆ List() [3/5]

template<typename T>
xsens::List< T >::List ( const uint32_t  size)

Construct a list with a capacity of at least the given size.

Definition at line 49 of file xsens_list.hpp.

◆ List() [4/5]

template<typename T>
xsens::List< T >::List ( const List< T > &  src)

Construct a list as a direct copy of another list.

Definition at line 61 of file xsens_list.hpp.

◆ List() [5/5]

template<typename T>
xsens::List< T >::List ( const uint32_t  size,
const T *  src 
)

Construct a list as a copy of a raw list.

Definition at line 75 of file xsens_list.hpp.

◆ ~List()

template<typename T >
xsens::List< T >::~List ( )

Destroy the list. This does NOT automatically delete items IN the list.

Definition at line 99 of file xsens_list.hpp.

Member Function Documentation

◆ append()

template<typename T>
void xsens::List< T >::append ( const T &  item)

Adds an item to the end of the list.

Definition at line 150 of file xsens_list.hpp.

Referenced by xsens::cmtScanPorts(), and mrpt::hwdrivers::CIMUXSens::searchPortAndConnect().

◆ appendCopy()

template<typename T >
template<typename TB >
void xsens::List< T >::appendCopy ( const TB &  item)

Adds a copy of a referenced item to the end of the list.

Definition at line 188 of file xsens_list.hpp.

◆ appendDeepCopy()

template<typename T>
void xsens::List< T >::appendDeepCopy ( const List< T > &  source)

Adds the contents of the source list to the end of the list.

Definition at line 167 of file xsens_list.hpp.

◆ appendList()

template<typename T>
void xsens::List< T >::appendList ( uint32_t  count,
const T *  lst 
)

Adds a number of items to the end of the list.

Definition at line 158 of file xsens_list.hpp.

◆ appendRelated()

template<typename T >
template<typename TR >
void xsens::List< T >::appendRelated ( const TR &  item)

Adds a related item to the end of the list, using the T = TR operator.

Definition at line 197 of file xsens_list.hpp.

◆ appendShallowCopy()

template<typename T>
void xsens::List< T >::appendShallowCopy ( const List< T > &  source)

Adds the contents of the source list to the end of the list.

Definition at line 177 of file xsens_list.hpp.

◆ clear()

template<typename T >
void xsens::List< T >::clear ( void  )

Clears the list without explicitly deleting anything.

Definition at line 126 of file xsens_list.hpp.

Referenced by xsens::cmtScanPorts().

◆ deleteAndClear()

template<typename T >
void xsens::List< T >::deleteAndClear ( void  )

Calls delete for all items in the list and then clears the list.

Definition at line 110 of file xsens_list.hpp.

◆ deleteAndRemove()

template<typename T >
void xsens::List< T >::deleteAndRemove ( const uint32_t  index)

Removes an item at the given index in the list.

Definition at line 877 of file xsens_list.hpp.

◆ deleteAndRemoveTail()

template<typename T >
void xsens::List< T >::deleteAndRemoveTail ( const uint32_t  count)

Definition at line 807 of file xsens_list.hpp.

◆ deleteItemsOnDestroy()

template<typename T >
void xsens::List< T >::deleteItemsOnDestroy ( void  )

Definition at line 1110 of file xsens_list.hpp.

◆ find() [1/2]

template<typename T >
template<typename TB >
uint32_t xsens::List< T >::find ( const TB &  item) const

Finds an item in an unsorted list (walk over all items) using the T::== operator.

Definition at line 914 of file xsens_list.hpp.

◆ find() [2/2]

template<typename T>
uint32_t xsens::List< T >::find ( const T  item,
InequalityFunction  fnc 
) const

Finds an item in an unsorted list (walk over all items) using the given inequality function.

Definition at line 923 of file xsens_list.hpp.

◆ findDeref()

template<typename T >
template<typename TB >
uint32_t xsens::List< T >::findDeref ( const TB &  item) const

Finds an item in an unsorted list (walk over all items) using the T::== operator on dereferenced list items.

Definition at line 933 of file xsens_list.hpp.

◆ findSorted()

template<typename T >
template<typename TB >
uint32_t xsens::List< T >::findSorted ( const TB &  item) const

Finds an item in a sorted list (binary search) using the T::== and T::< operators.

Definition at line 943 of file xsens_list.hpp.

◆ findSortedDeref()

template<typename T >
template<typename TB >
uint32_t xsens::List< T >::findSortedDeref ( const TB &  item) const

Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items.

Definition at line 968 of file xsens_list.hpp.

◆ freeAndClear()

template<typename T >
void xsens::List< T >::freeAndClear ( void  )

Calls free for all items in the list and then clears the list.

Definition at line 118 of file xsens_list.hpp.

◆ freeAndRemove()

template<typename T >
void xsens::List< T >::freeAndRemove ( const uint32_t  index)

Removes an item at the given index in the list.

Definition at line 895 of file xsens_list.hpp.

◆ freeAndRemoveTail()

template<typename T >
void xsens::List< T >::freeAndRemoveTail ( const uint32_t  count)

Definition at line 823 of file xsens_list.hpp.

◆ freeItemsOnDestroy()

template<typename T >
void xsens::List< T >::freeItemsOnDestroy ( void  )

Definition at line 1121 of file xsens_list.hpp.

◆ get()

template<typename T >
T & xsens::List< T >::get ( const uint32_t  index) const

Retrieves the item at the given index.

An index beyond the end returns the first item.

Definition at line 215 of file xsens_list.hpp.

◆ getBuffer()

template<typename T>
const T* xsens::List< T >::getBuffer ( void  ) const
inline

Returns the start of the linear data buffer.

Definition at line 218 of file xsens_list.h.

◆ insert()

template<typename T>
void xsens::List< T >::insert ( const T &  item,
const uint32_t  index 
)

Inserts an item at the given index, shifting any items below it down one spot.

Definition at line 227 of file xsens_list.hpp.

◆ insertCopy()

template<typename T >
template<typename TB >
void xsens::List< T >::insertCopy ( const TB &  item,
const uint32_t  index 
)

Inserts a copy of the referenced item at the given index, shifting any items below it down one spot.

Definition at line 242 of file xsens_list.hpp.

◆ insertSorted()

template<typename T>
uint32_t xsens::List< T >::insertSorted ( const T &  item)

Assumes the list is sorted and inserts the item at the appropriate spot.

Definition at line 992 of file xsens_list.hpp.

◆ insertSortedCopy()

template<typename T >
template<typename TB >
uint32_t xsens::List< T >::insertSortedCopy ( const TB &  item)

Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot.

Definition at line 1071 of file xsens_list.hpp.

◆ insertSortedDeref()

template<typename T>
uint32_t xsens::List< T >::insertSortedDeref ( const T &  item)

Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot.

Definition at line 1031 of file xsens_list.hpp.

◆ isDeepCopyOf()

template<typename T>
template<typename TB >
void xsens::List< T >::isDeepCopyOf ( const List< T > &  source)

Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i])

Definition at line 1133 of file xsens_list.hpp.

◆ isShallowCopyOf()

template<typename T>
void xsens::List< T >::isShallowCopyOf ( const List< T > &  source)

Overwrites the current list with a shallow (memcopy) copy of another list.

Definition at line 1144 of file xsens_list.hpp.

◆ last()

template<typename T >
T & xsens::List< T >::last ( void  ) const

Retrieves the last item.

Definition at line 205 of file xsens_list.hpp.

◆ length()

template<typename T>
uint32_t xsens::List< T >::length ( void  ) const
inline

Returns the number of items currently in the list.

Definition at line 159 of file xsens_list.h.

Referenced by xsens::cmtScanPorts(), and mrpt::hwdrivers::CIMUXSens::searchPortAndConnect().

◆ operator=()

template<typename T>
void xsens::List< T >::operator= ( const List< T > &  list)
private

intentionally NOT implemented due to ambiguous nature

◆ operator[]()

template<typename T >
T & xsens::List< T >::operator[] ( const uint32_t  index) const

Retrieves the item at the given index.

An index beyond the end probably causes an exception.

Definition at line 256 of file xsens_list.hpp.

◆ qSort()

template<typename T >
void xsens::List< T >::qSort ( uint32_t  left,
uint32_t  right 
)
private

Sorts the list in an ascending order, using the T::< operator.

Definition at line 382 of file xsens_list.hpp.

◆ qSortDeref()

template<typename T >
void xsens::List< T >::qSortDeref ( uint32_t  left,
uint32_t  right 
)
private

Sorts the list in an ascending order, using the T::< operator on dereferenced list items.

Definition at line 415 of file xsens_list.hpp.

◆ remove()

template<typename T >
void xsens::List< T >::remove ( const uint32_t  index)

Removes an item at the given index in the list.

Definition at line 775 of file xsens_list.hpp.

Referenced by xsens::cmtScanPorts().

◆ removeDuplicateEntries()

template<typename T >
uint32_t xsens::List< T >::removeDuplicateEntries ( void  )

Removes any duplicate entries and returns the number of items removed.

Items are compared directly.

Definition at line 839 of file xsens_list.hpp.

◆ removeDuplicateEntriesDeref()

template<typename T >
uint32_t xsens::List< T >::removeDuplicateEntriesDeref ( void  )

Removes any duplicate entries and returns the number of items removed.

Items are compared after dereferencing.

Definition at line 858 of file xsens_list.hpp.

◆ removeTail()

template<typename T >
void xsens::List< T >::removeTail ( const uint32_t  count)

Removes items from the end of the list.

Definition at line 792 of file xsens_list.hpp.

◆ resize()

template<typename T >
void xsens::List< T >::resize ( uint32_t  newSize)

Resizes the list to at least the given size.

Definition at line 132 of file xsens_list.hpp.

◆ reverse()

template<typename T >
void xsens::List< T >::reverse ( void  )

Reverse the order of the list, useful for sorted lists that are read/created in the reverse order.

Definition at line 1167 of file xsens_list.hpp.

◆ sortAscending()

template<typename T >
void xsens::List< T >::sortAscending ( void  )

Sorts the list in an ascending order, using the T::< operator.

Definition at line 453 of file xsens_list.hpp.

Referenced by xsens::cmtScanPorts().

◆ sortAscendingDeref()

template<typename T >
void xsens::List< T >::sortAscendingDeref ( void  )

Sorts the list in an ascending order, using the T::< operator on dereferenced list items.

Definition at line 595 of file xsens_list.hpp.

◆ swap()

template<typename T >
void xsens::List< T >::swap ( const uint32_t  i,
const uint32_t  j 
)

Swaps two items in the list.

Definition at line 1155 of file xsens_list.hpp.

◆ twinSortAscending()

template<typename T >
template<typename T2 >
void xsens::List< T >::twinSortAscending ( List< T2 > &  twin)

Sorts the first list in an ascending order, using the T::< operator, the second list will be updated the same way.

Definition at line 738 of file xsens_list.hpp.

Member Data Documentation

◆ m_count

template<typename T>
uint32_t xsens::List< T >::m_count
protected

The number of items currently in the list.

Definition at line 81 of file xsens_list.h.

Referenced by xsens::List< uint32_t >::length(), xsens::IntList::operator==(), and xsens::List< uint32_t >::twinSortAscending().

◆ m_data

template<typename T>
T* xsens::List< T >::m_data
protected

The array containing the items.

Definition at line 77 of file xsens_list.h.

Referenced by xsens::List< uint32_t >::getBuffer(), xsens::IntList::operator==(), and xsens::List< uint32_t >::twinSortAscending().

◆ m_jcf

template<typename T>
JanitorClassFunc<List<T> >* xsens::List< T >::m_jcf
protected

Used to clean up the list on exit.

Definition at line 83 of file xsens_list.h.

◆ m_manage

template<typename T>
bool xsens::List< T >::m_manage
protected

Definition at line 84 of file xsens_list.h.

◆ m_max

template<typename T>
uint32_t xsens::List< T >::m_max
protected

The current size of the data array.

Definition at line 79 of file xsens_list.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019