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 60 of file xsens_list.h.
#include <xSens_MT3/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(__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. 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... | |
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. 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 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... | |
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 81 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 171 of file xsens_list.h.
|
protected |
Construct a list as a reference to a raw list.
Definition at line 89 of file xsens_list.hpp.
xsens::List< T >::List | ( | ) |
Standard constructor, creates an empty list with some room for items.
Definition at line 38 of file xsens_list.hpp.
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.
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.
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.
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.
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().
Adds a copy of a referenced item to the end of the list.
Definition at line 188 of file xsens_list.hpp.
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.
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.
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.
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.
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().
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.
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.
void xsens::List< T >::deleteAndRemoveTail | ( | const uint32_t | count | ) |
Definition at line 807 of file xsens_list.hpp.
void xsens::List< T >::deleteItemsOnDestroy | ( | void | ) |
Definition at line 1110 of file xsens_list.hpp.
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.
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.
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.
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.
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.
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.
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.
void xsens::List< T >::freeAndRemoveTail | ( | const uint32_t | count | ) |
Definition at line 823 of file xsens_list.hpp.
void xsens::List< T >::freeItemsOnDestroy | ( | void | ) |
Definition at line 1121 of file xsens_list.hpp.
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.
|
inline |
Returns the start of the linear data buffer.
Definition at line 190 of file xsens_list.h.
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.
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.
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.
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.
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.
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.
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.
T & xsens::List< T >::last | ( | void | ) | const |
Retrieves the last item.
Definition at line 205 of file xsens_list.hpp.
|
inline |
Returns the number of items currently in the list.
Definition at line 143 of file xsens_list.h.
Referenced by xsens::cmtScanPorts(), and mrpt::hwdrivers::CIMUXSens::searchPortAndConnect().
|
private |
intentionally NOT implemented due to ambiguous nature
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.
|
private |
Sorts the list in an ascending order, using the T::< operator.
Definition at line 382 of file xsens_list.hpp.
|
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.
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().
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.
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.
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.
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.
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.
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().
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.
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.
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.
|
protected |
The number of items currently in the list.
Definition at line 72 of file xsens_list.h.
Referenced by xsens::List< uint32_t >::length(), xsens::IntList::operator==(), and xsens::List< uint32_t >::twinSortAscending().
|
protected |
The array containing the items.
Definition at line 70 of file xsens_list.h.
Referenced by xsens::List< uint32_t >::getBuffer(), xsens::IntList::operator==(), and xsens::List< uint32_t >::twinSortAscending().
|
protected |
Used to clean up the list on exit.
Definition at line 73 of file xsens_list.h.
|
protected |
Definition at line 74 of file xsens_list.h.
|
protected |
The current size of the data array.
Definition at line 71 of file xsens_list.h.
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |