Dynamic list class. More...
#include <Robots/SeaBeeIII/IMUDataServer/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 > | |
typedef int32_t(__cdecl * | InequalityFunction )(const T &, const T &) |
Type for an equality compare function, should return true when NOT equal. | |
Public Member Functions | |
List () | |
Standard constructor, creates an empty list with some room for items. | |
List (const uint32_t size) | |
Construct a list with a capacity of at least the given size. | |
List (const List< T > &src) | |
Construct a list as a direct copy of another list. | |
List (const uint32_t size, const T *src) | |
Construct a list as a copy of a raw list. | |
~List () | |
Destroy the list. This does NOT automatically delete items IN the list. | |
void | deleteAndClear (void) |
Calls delete for all items in the list and then clears the list. | |
void | freeAndClear (void) |
Calls free for all items in the list and then clears the list. | |
void | clear (void) |
Clears the list without explicitly deleting anything. | |
void | resize (uint32_t newSize) |
Resizes the list to at least the given size. | |
void | append (const T &item) |
Adds an item to the end of the list. | |
void | appendList (uint32_t count, const T *lst) |
Adds a number of items to the end of the list. | |
void | appendDeepCopy (const List< T > &source) |
Adds the contents of the source list to the end of the list. | |
void | appendShallowCopy (const List< T > &source) |
Adds the contents of the source list to the end of the list. | |
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). | |
template<typename TR > | |
void | appendRelated (const TR &item) |
Adds a related item to the end of the list, using the T = TR operator. | |
void | remove (const uint32_t index) XSENS_LIST_THROW |
Removes an item at the given index in the list. | |
void | swap (const uint32_t i, const uint32_t j) XSENS_LIST_THROW |
Swaps two items in the list. | |
void | deleteAndRemove (const uint32_t index) XSENS_LIST_THROW |
Removes an item at the given index in the list. | |
void | freeAndRemove (const uint32_t index) XSENS_LIST_THROW |
Removes an item at the given index in the list. | |
T & | last (void) const XSENS_LIST_THROW |
Retrieves the last item. | |
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. | |
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. | |
void | 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 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. | |
uint32_t | insertSorted (const T &item) |
Assumes the list is sorted and inserts the item at the appropriate spot. | |
uint32_t | insertSortedDeref (const T &item) |
Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot. | |
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. | |
uint32_t | length (void) const |
Returns the number of items currently in the list. | |
void | sortAscending (void) |
Sorts the list in an ascending order, using the T::< operator. | |
void | sortAscendingDeref (void) |
Sorts the list in an ascending order, using the T::< operator on dereferenced list items. | |
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. | |
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. | |
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. | |
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. | |
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. | |
void | reverse (void) |
Reverse the order of the list, useful for sorted lists that are read/created in the reverse order. | |
void | removeTail (const uint32_t count) XSENS_LIST_THROW |
Removes items from the end of the list. | |
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. | |
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. | |
uint32_t | removeDuplicateEntriesDeref (void) |
Removes any duplicate entries and returns the number of items removed. Items are compared after dereferencing. | |
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]). | |
void | isShallowCopyOf (const List< T > &source) |
Overwrites the current list with a direct copy (a=b) of another list. | |
const T * | getBuffer (void) const |
Returns the start of the linear data buffer. | |
Protected Member Functions | |
List (const uint32_t size, T *src, bool manage) | |
Construct a list as a reference to a raw list. | |
Protected Attributes | |
T * | m_data |
The array containing the items. | |
uint32_t | m_max |
The current size of the data array. | |
uint32_t | m_count |
The number of items currently in the list. | |
JanitorClassFunc< List< T > > * | m_jcf |
Used to clean up the list on exit. | |
bool | m_manage |
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 74 of file xsens_list.h.
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 95 of file xsens_list.h.
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 185 of file xsens_list.h.
xsens::List< T >::List | ( | const uint32_t | size, | |
T * | src, | |||
bool | manage | |||
) | [inline, protected] |
Construct a list as a reference to a raw list.
Definition at line 259 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_jcf, and xsens::List< T >::m_max.
xsens::List< T >::List | ( | ) | [inline] |
Standard constructor, creates an empty list with some room for items.
Definition at line 209 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_jcf, and xsens::List< T >::m_max.
xsens::List< T >::List | ( | const uint32_t | size | ) | [inline] |
Construct a list with a capacity of at least the given size.
Definition at line 219 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_jcf, and xsens::List< T >::m_max.
xsens::List< T >::List | ( | const List< T > & | src | ) | [inline] |
Construct a list as a direct copy of another list.
Definition at line 231 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_jcf, and xsens::List< T >::m_max.
xsens::List< T >::List | ( | const uint32_t | size, | |
const T * | src | |||
) | [inline] |
Construct a list as a copy of a raw list.
Definition at line 245 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_jcf, and xsens::List< T >::m_max.
xsens::List< T >::~List | ( | ) | [inline] |
Destroy the list. This does NOT automatically delete items IN the list.
Definition at line 269 of file xsens_list.h.
References xsens::List< T >::m_data, and xsens::List< T >::m_jcf.
void xsens::List< T >::append | ( | const T & | item | ) | [inline] |
Adds an item to the end of the list.
Definition at line 320 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
Referenced by xsens::List< T >::insertSorted(), xsens::List< T >::insertSortedCopy(), and xsens::List< T >::insertSortedDeref().
void xsens::List< T >::appendCopy | ( | const TB & | item | ) | [inline] |
Adds a copy of a referenced item to the end of the list using newItem = new TB(item).
Definition at line 358 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::appendDeepCopy | ( | const List< T > & | source | ) | [inline] |
Adds the contents of the source list to the end of the list.
Definition at line 337 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::appendList | ( | uint32_t | count, | |
const T * | lst | |||
) | [inline] |
Adds a number of items to the end of the list.
Definition at line 328 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::appendRelated | ( | const TR & | item | ) | [inline] |
Adds a related item to the end of the list, using the T = TR operator.
Definition at line 367 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::appendShallowCopy | ( | const List< T > & | source | ) | [inline] |
Adds the contents of the source list to the end of the list.
Definition at line 347 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::clear | ( | void | ) | [inline] |
Clears the list without explicitly deleting anything.
Definition at line 296 of file xsens_list.h.
References xsens::List< T >::m_count.
void xsens::List< T >::deleteAndClear | ( | void | ) | [inline] |
Calls delete for all items in the list and then clears the list.
Definition at line 280 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::deleteAndRemove | ( | const uint32_t | index | ) | [inline] |
Removes an item at the given index in the list.
Definition at line 819 of file xsens_list.h.
References m_count.
uint32_t xsens::List< T >::find | ( | const T | item, | |
InequalityFunction | fnc | |||
) | const [inline] |
Finds an item in an unsorted list (walk over all items) using the given inequality function.
Definition at line 865 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::find | ( | const TB & | item | ) | const [inline] |
Finds an item in an unsorted list (walk over all items) using the T::== operator.
Definition at line 856 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
Referenced by xsens::List< T >::findSorted().
uint32_t xsens::List< T >::findDeref | ( | const TB & | item | ) | const [inline] |
Finds an item in an unsorted list (walk over all items) using the T::== operator on dereferenced list items.
Definition at line 875 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
Referenced by xsens::List< T >::findSortedDeref().
uint32_t xsens::List< T >::findSorted | ( | const TB & | item | ) | const [inline] |
Finds an item in a sorted list (binary search) using the T::== and T::< operators.
Definition at line 885 of file xsens_list.h.
References xsens::List< T >::find(), xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::findSortedDeref | ( | const TB & | item | ) | const [inline] |
Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items.
Definition at line 910 of file xsens_list.h.
References xsens::List< T >::findDeref(), xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::freeAndClear | ( | void | ) | [inline] |
Calls free for all items in the list and then clears the list.
Definition at line 288 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::freeAndRemove | ( | const uint32_t | index | ) | [inline] |
Removes an item at the given index in the list.
Definition at line 837 of file xsens_list.h.
References m_count.
T & xsens::List< T >::get | ( | const uint32_t | index | ) | const [inline] |
Retrieves the item at the given index. An index beyond the end returns the first item.
Definition at line 385 of file xsens_list.h.
References m_count.
const T* xsens::List< T >::getBuffer | ( | void | ) | const [inline] |
Returns the start of the linear data buffer.
Definition at line 204 of file xsens_list.h.
References xsens::List< T >::m_data.
void xsens::List< T >::insert | ( | const T & | item, | |
const uint32_t | index | |||
) | [inline] |
Inserts an item at the given index, shifting any items below it down one spot.
Definition at line 397 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
Referenced by xsens::List< T >::insertSorted(), and xsens::List< T >::insertSortedDeref().
void xsens::List< T >::insertCopy | ( | const TB & | item, | |
const uint32_t | index | |||
) | [inline] |
Inserts a copy of the referenced item at the given index, shifting any items below it down one spot.
Definition at line 412 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
uint32_t xsens::List< T >::insertSorted | ( | const T & | item | ) | [inline] |
Assumes the list is sorted and inserts the item at the appropriate spot.
Definition at line 934 of file xsens_list.h.
References xsens::List< T >::append(), xsens::List< T >::insert(), xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::insertSortedCopy | ( | const TB & | item | ) | [inline] |
Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot.
Definition at line 1013 of file xsens_list.h.
References xsens::List< T >::append(), xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::insertSortedDeref | ( | const T & | item | ) | [inline] |
Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot.
Definition at line 973 of file xsens_list.h.
References xsens::List< T >::append(), xsens::List< T >::insert(), xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::isDeepCopyOf | ( | const List< T > & | source | ) | [inline] |
Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i]).
Definition at line 1075 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
void xsens::List< T >::isShallowCopyOf | ( | const List< T > & | source | ) | [inline] |
Overwrites the current list with a direct copy (a=b) of another list.
Definition at line 1086 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, xsens::List< T >::m_max, and xsens::List< T >::resize().
T & xsens::List< T >::last | ( | void | ) | const [inline] |
Retrieves the last item.
Definition at line 375 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::length | ( | void | ) | const [inline] |
Returns the number of items currently in the list.
Definition at line 157 of file xsens_list.h.
References xsens::List< T >::m_count.
T & xsens::List< T >::operator[] | ( | const uint32_t | index | ) | const [inline] |
Retrieves the item at the given index. An index beyond the end probably causes an exception.
Definition at line 426 of file xsens_list.h.
References m_count.
void xsens::List< T >::remove | ( | const uint32_t | index | ) | [inline] |
Removes an item at the given index in the list.
Definition at line 717 of file xsens_list.h.
References m_count.
uint32_t xsens::List< T >::removeDuplicateEntries | ( | void | ) | [inline] |
Removes any duplicate entries and returns the number of items removed. Items are compared directly.
Definition at line 781 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::removeDuplicateEntriesDeref | ( | void | ) | [inline] |
Removes any duplicate entries and returns the number of items removed. Items are compared after dereferencing.
Definition at line 800 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::removeTail | ( | const uint32_t | count | ) | [inline] |
Removes items from the end of the list.
Definition at line 734 of file xsens_list.h.
References m_count.
void xsens::List< T >::resize | ( | uint32_t | newSize | ) | [inline] |
Resizes the list to at least the given size.
Definition at line 302 of file xsens_list.h.
References xsens::List< T >::m_count, xsens::List< T >::m_data, and xsens::List< T >::m_max.
Referenced by xsens::List< T >::append(), xsens::List< T >::appendCopy(), xsens::List< T >::appendDeepCopy(), xsens::List< T >::appendList(), xsens::List< T >::appendRelated(), xsens::List< T >::appendShallowCopy(), xsens::List< T >::insert(), xsens::List< T >::insertCopy(), xsens::List< T >::isDeepCopyOf(), and xsens::List< T >::isShallowCopyOf().
void xsens::List< T >::reverse | ( | void | ) | [inline] |
Reverse the order of the list, useful for sorted lists that are read/created in the reverse order.
Definition at line 1109 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::sortAscending | ( | void | ) | [inline] |
Sorts the list in an ascending order, using the T::< operator.
Definition at line 503 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::sortAscendingDeref | ( | void | ) | [inline] |
Sorts the list in an ascending order, using the T::< operator on dereferenced list items.
Definition at line 591 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
void xsens::List< T >::swap | ( | const uint32_t | i, | |
const uint32_t | j | |||
) | [inline] |
void xsens::List< T >::twinSortAscending | ( | List< T2 > & | twin | ) | [inline] |
Sorts the first list in an ascending order, using the T::< operator, the second list will be updated the same way.
Definition at line 680 of file xsens_list.h.
References xsens::List< T >::m_count, and xsens::List< T >::m_data.
uint32_t xsens::List< T >::m_count [protected] |
The number of items currently in the list.
Definition at line 86 of file xsens_list.h.
Referenced by xsens::List< T >::append(), xsens::List< T >::appendCopy(), xsens::List< T >::appendDeepCopy(), xsens::List< T >::appendList(), xsens::List< T >::appendRelated(), xsens::List< T >::appendShallowCopy(), xsens::List< T >::clear(), xsens::List< T >::deleteAndClear(), xsens::List< T >::find(), xsens::List< T >::findDeref(), xsens::List< T >::findSorted(), xsens::List< T >::findSortedDeref(), xsens::List< T >::freeAndClear(), xsens::List< T >::insert(), xsens::List< T >::insertCopy(), xsens::List< T >::insertSorted(), xsens::List< T >::insertSortedCopy(), xsens::List< T >::insertSortedDeref(), xsens::List< T >::isDeepCopyOf(), xsens::List< T >::isShallowCopyOf(), xsens::List< T >::last(), xsens::List< T >::length(), xsens::List< T >::List(), xsens::List< T >::removeDuplicateEntries(), xsens::List< T >::removeDuplicateEntriesDeref(), xsens::List< T >::resize(), xsens::List< T >::reverse(), xsens::List< T >::sortAscending(), xsens::List< T >::sortAscendingDeref(), and xsens::List< T >::twinSortAscending().
T* xsens::List< T >::m_data [protected] |
The array containing the items.
Definition at line 84 of file xsens_list.h.
Referenced by xsens::List< T >::append(), xsens::List< T >::appendCopy(), xsens::List< T >::appendDeepCopy(), xsens::List< T >::appendList(), xsens::List< T >::appendRelated(), xsens::List< T >::appendShallowCopy(), xsens::List< T >::deleteAndClear(), xsens::List< T >::find(), xsens::List< T >::findDeref(), xsens::List< T >::findSorted(), xsens::List< T >::findSortedDeref(), xsens::List< T >::freeAndClear(), xsens::List< T >::getBuffer(), xsens::List< T >::insert(), xsens::List< T >::insertCopy(), xsens::List< T >::insertSorted(), xsens::List< T >::insertSortedCopy(), xsens::List< T >::insertSortedDeref(), xsens::List< T >::isDeepCopyOf(), xsens::List< T >::isShallowCopyOf(), xsens::List< T >::last(), xsens::List< T >::List(), xsens::List< T >::removeDuplicateEntries(), xsens::List< T >::removeDuplicateEntriesDeref(), xsens::List< T >::resize(), xsens::List< T >::reverse(), xsens::List< T >::sortAscending(), xsens::List< T >::sortAscendingDeref(), xsens::List< T >::twinSortAscending(), and xsens::List< T >::~List().
JanitorClassFunc<List<T> >* xsens::List< T >::m_jcf [protected] |
Used to clean up the list on exit.
Definition at line 87 of file xsens_list.h.
Referenced by xsens::List< T >::List(), and xsens::List< T >::~List().
uint32_t xsens::List< T >::m_max [protected] |
The current size of the data array.
Definition at line 85 of file xsens_list.h.
Referenced by xsens::List< T >::append(), xsens::List< T >::appendCopy(), xsens::List< T >::appendDeepCopy(), xsens::List< T >::appendList(), xsens::List< T >::appendRelated(), xsens::List< T >::appendShallowCopy(), xsens::List< T >::insert(), xsens::List< T >::insertCopy(), xsens::List< T >::isDeepCopyOf(), xsens::List< T >::isShallowCopyOf(), xsens::List< T >::List(), and xsens::List< T >::resize().