xsens_imu
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
xsens::List< T > Class Template Reference

Dynamic list class. More...

#include <xsens_list.h>

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(__cdeclInequalityFunction )(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 using newItem = new TB(item). 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 & minVal (void) const XSENS_LIST_THROW
 Retrieves the smallest item, using the T::< operator. More...
 
T & maxVal (void) const XSENS_LIST_THROW
 Retrieves the largest item, using the T::< operator. More...
 
T & get (const uint32_t index) const XSENS_LIST_THROW
 Retrieves the item at the given index. An index beyond the end returns the first item. More...
 
T & operator[] (const uint32_t index) const XSENS_LIST_THROW
 Retrieves the item at the given index. An index beyond the end probably causes an exception. 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...
 
uint32_t count (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...
 
template<typename TB >
uint32_t findSortedForInsert (const TB &item) const
 Finds an item in a sorted list (binary search) using the T::== and T::< operators. If not found, it does not return XSENS_LIST_NOTFOUND but the insert position if this item would be inserted in the list. More...
 
template<typename TB >
uint32_t findSortedDerefForInsert (const TB &item) const
 Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items. If not found, it does not return XSENS_LIST_NOTFOUND but the insert position if this item would be inserted in the list. More...
 
template<typename TB >
uint32_t reverseFind (const TB &item) const
 Finds an item in an unsorted list (walk over all items) using the T::== operator, starting at the end of the list. More...
 
template<typename TB >
uint32_t reverseFindDeref (const TB &item) const
 Finds an item in an unsorted list (walk over all items) using the T::== operator on dereferenced list items, starting at the end of the list. 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. Items are compared directly. More...
 
uint32_t removeDuplicateEntriesDeref (void)
 Removes any duplicate entries and returns the number of items removed. Items are compared after dereferencing. 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 direct copy (a=b) of another list. More...
 
const T * getBuffer (void) const
 Returns the start of the linear data buffer. More...
 
template<typename TB >
bool operator== (const List< TB > &lst)
 Compare each item of the lists using the T == TB operator. If they're all identical, returns true. 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
 

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.

Member Typedef Documentation

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 >

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.

Constructor & Destructor Documentation

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.

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

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

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

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

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

Construct a list as a direct copy of another list.

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

Construct a list as a copy of a raw list.

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

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

Member Function Documentation

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

Adds an item to the end of the list.

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 using newItem = new TB(item).

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.

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.

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.

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.

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

Clears the list without explicitly deleting anything.

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

Returns the number of items currently in the list.

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

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

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

Removes an item at the given index in the list.

template<typename T >
void xsens::List< T >::deleteAndRemoveTail ( const uint32_t  count)
template<typename T >
void xsens::List< T >::deleteItemsOnDestroy ( void  )
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.

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.

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.

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.

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.

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

Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items. If not found, it does not return XSENS_LIST_NOTFOUND but the insert position if this item would be inserted in the list.

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

Finds an item in a sorted list (binary search) using the T::== and T::< operators. If not found, it does not return XSENS_LIST_NOTFOUND but the insert position if this item would be inserted in the list.

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

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

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

Removes an item at the given index in the list.

template<typename T >
void xsens::List< T >::freeAndRemoveTail ( const uint32_t  count)
template<typename T >
void xsens::List< T >::freeItemsOnDestroy ( void  )
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.

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

Returns the start of the linear data buffer.

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.

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.

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.

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.

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.

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])

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

Overwrites the current list with a direct copy (a=b) of another list.

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

Retrieves the last item.

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

Returns the number of items currently in the list.

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

Retrieves the largest item, using the T::< operator.

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

Retrieves the smallest item, using the T::< operator.

template<typename T >
template<typename TB >
bool xsens::List< T >::operator== ( const List< TB > &  lst)

Compare each item of the lists using the T == TB operator. If they're all identical, returns true.

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.

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

Removes an item at the given index in the list.

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.

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.

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

Removes items from the end of the list.

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

Resizes the list to at least the given size.

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.

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

Finds an item in an unsorted list (walk over all items) using the T::== operator, starting at the end of the list.

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

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

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

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

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

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

Todo:
remove embedded struct definition
template<typename T >
void xsens::List< T >::swap ( const uint32_t  i,
const uint32_t  j 
)

Swaps two items in the list.

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.

Member Data Documentation

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

The number of items currently in the list.

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

The array containing the items.

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

Used to clean up the list on exit.

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

The current size of the data array.


The documentation for this class was generated from the following files: