1 #ifndef XSENS_MONOLITHIC 34 #ifndef XSENS_MONOLITHIC 35 #ifndef PSTDINT_H_INCLUDED 40 #ifndef XSENS_EXCEPTION_H 44 #ifndef XSENS_JANITORS_H 49 #define XSENS_LIST_NOTFOUND 0xFFFFFFFF 51 #ifdef _XSENS_LIST_RANGE_CHECKS 53 # define XSENS_LIST_THROW throw(...) 55 # define XSENS_LIST_THROW 58 # define XSENS_LIST_THROW 67 #define XSENS_LIST_LINEAR_SEARCH_TRESHOLD 10 82 void operator = (
const List& list);
83 void qSort(uint32_t left, uint32_t right);
86 void qSortDeref(uint32_t left, uint32_t right);
96 List(
const uint32_t size, T* src,
bool manage);
100 typedef int32_t (*
cmpFunc) (
const T&,
const T&);
105 List(
const uint32_t size);
109 List(
const uint32_t size,
const T* src);
120 void resize(uint32_t newSize);
122 void append(
const T& item);
130 template <
typename TB>
133 template <
typename TR>
150 T&
get(
const uint32_t index)
const XSENS_LIST_THROW;
154 void insert(
const T& item,
const uint32_t index);
156 template <
typename TB>
157 void insertCopy(
const TB& item,
const uint32_t index);
163 template <
typename TB>
174 template <
typename T2>
177 template <
typename TB>
178 uint32_t
find(
const TB& item)
const;
180 template <
typename TB>
181 uint32_t
findDeref(
const TB& item)
const;
183 template <
typename TB>
186 template <
typename TB>
190 template <
typename TB>
193 template <
typename TB>
197 template <
typename TB>
200 template <
typename TB>
224 template <
typename TB>
232 template <
typename TB>
237 template <
typename T>
244 throw std::bad_alloc();
249 template <
typename T>
258 throw std::bad_alloc();
263 template <
typename T>
272 throw std::bad_alloc();
279 template <
typename T>
288 throw std::bad_alloc();
295 template <
typename T>
305 template <
typename T>
316 template <
typename T>
319 for (
unsigned i=0;i<
m_count;++i)
324 template <
typename T>
327 for (
unsigned i=0;i<
m_count;++i)
332 template <
typename T>
338 template <
typename T>
343 if (newSize ==
m_max)
356 template <
typename T>
364 template <
typename T>
369 for (
unsigned i = 0; i <
count; ++i)
373 template <
typename T>
379 for (uint32_t i = 0;i<source.
m_count;++i)
383 template <
typename T>
389 for (uint32_t i = 0;i<source.
m_count;++i)
393 template <
typename T>
394 template <
typename TB>
402 template <
typename T>
403 template <
typename TR>
411 template <
typename T>
414 #ifdef _XSENS_LIST_RANGE_CHECKS 416 throw Exception(
"List.last: empty list");
421 template <
typename T>
424 #ifdef _XSENS_LIST_RANGE_CHECKS 426 throw Exception(
"List.maxVal: empty list");
429 for (uint32_t i = 1; i <
m_count; ++i)
435 template <
typename T>
438 #ifdef _XSENS_LIST_RANGE_CHECKS 440 throw Exception(
"List.minVal: empty list");
443 for (uint32_t i = 1; i <
m_count; ++i)
449 template <
typename T>
452 #ifdef _XSENS_LIST_RANGE_CHECKS 454 throw Exception(
"List.get: index out of bounds");
461 template <
typename T>
466 for (
unsigned i=
m_count;i>index;--i)
475 template <
typename T>
476 template <
typename TB>
481 for (
unsigned i=
m_count;i>index;--i)
484 m_data[index] =
new TB(item);
490 template <
typename T>
493 #ifdef _XSENS_LIST_RANGE_CHECKS 495 throw Exception(
"List[]: index out of bounds");
501 template <
typename T>
504 uint32_t l_hold, r_hold;
512 while (!(
m_data[right] < pivot) && (left < right))
519 while (!(pivot <
m_data[left]) && (left < right))
521 if (!(left == right))
529 qSort(l_hold, left-1);
531 qSort(left+1, r_hold);
534 template <
typename T>
537 uint32_t l_hold, r_hold;
545 while (!(*
m_data[right] < *pivot) && (left < right))
552 while (!(*pivot < *
m_data[left]) && (left < right))
554 if (!(left == right))
562 qSortDeref(l_hold, left-1);
564 qSortDeref(left+1, r_hold);
567 template <
typename T>
579 Linker* list = (Linker*) malloc(
m_count*
sizeof(Linker));
581 throw std::bad_alloc();
590 for (uint32_t i = 1; i <
m_count; ++i)
596 while (curr->prev != NULL)
602 list[i].next = curr->next;
604 curr->next->prev = &list[i];
605 curr->next = &list[i];
610 if (curr != &list[i])
614 curr->prev = &list[i];
620 while (curr->next != NULL)
627 list[i].prev = curr->prev;
628 curr->prev->next = &list[i];
629 curr->prev = &list[i];
634 if (curr != &list[i])
638 curr->next = &list[i];
645 while (curr->prev != NULL) curr = curr->prev;
648 for (uint32_t i = 0; i <
m_count; ++i)
657 template <
typename T>
670 Linker* list = (Linker*) malloc(
m_count*
sizeof(Linker));
672 throw std::bad_alloc();
681 for (uint32_t i = 1; i <
m_count; ++i)
687 while (curr->prev != NULL)
693 list[i].next = curr->next;
695 curr->next->prev = &list[i];
696 curr->next = &list[i];
701 if (curr != &list[i])
705 curr->prev = &list[i];
711 while (curr->next != NULL)
718 list[i].prev = curr->prev;
719 curr->prev->next = &list[i];
720 curr->prev = &list[i];
725 if (curr != &list[i])
729 curr->next = &list[i];
736 while (curr->prev != NULL) curr = curr->prev;
739 for (uint32_t i = 0; i <
m_count; ++i)
748 template <
typename T>
749 template <
typename T2>
755 #ifdef _XSENS_LIST_RANGE_CHECKS 757 throw Exception(
"List.twinSortAscending: sizes do not match");
759 uint32_t iteration = 0;
767 for (uint32_t i=iteration+1;i<
m_count;++i)
772 if (mini != iteration)
780 twin.
m_data[iteration] = tmp2;
786 template <
typename T>
789 #ifdef _XSENS_LIST_RANGE_CHECKS 791 throw Exception(
"List.remove: index out of bounds");
799 for (
unsigned i = index;i <
m_count;++i)
803 template <
typename T>
806 #ifdef _XSENS_LIST_RANGE_CHECKS 808 throw Exception(
"List.removeTail: list size less than remove count");
818 template <
typename T>
821 #ifdef _XSENS_LIST_RANGE_CHECKS 823 throw Exception(
"List.deleteAndRemoveTail: list size less than remove count");
827 for (
unsigned i = 0;i <
count;++i)
834 template <
typename T>
837 #ifdef _XSENS_LIST_RANGE_CHECKS 839 throw Exception(
"List.freeAndRemoveTail: list size less than remove count");
843 for (
unsigned i = 0;i <
count;++i)
850 template <
typename T>
853 uint32_t removed = 0;
854 for (uint32_t i=0;i <
m_count; ++i)
856 for (uint32_t j=i+1;j <
m_count; ++j)
869 template <
typename T>
872 uint32_t removed = 0;
873 for (uint32_t i=0;i <
m_count; ++i)
875 for (uint32_t j=i+1;j <
m_count; ++j)
888 template <
typename T>
891 #ifdef _XSENS_LIST_RANGE_CHECKS 893 throw Exception(
"List.deleteAndRemove: index out of bounds");
902 for (
unsigned i = index;i <
m_count;++i)
906 template <
typename T>
909 #ifdef _XSENS_LIST_RANGE_CHECKS 911 throw Exception(
"List.freeAndRemove: index out of bounds");
920 for (
unsigned i = index;i <
m_count;++i)
924 template <
typename T>
925 template <
typename TB>
928 for (uint32_t i=0;i<
m_count;++i)
929 if (((
const T*)
m_data)[i] == item)
934 template <
typename T>
937 for (uint32_t i=0;i<
m_count;++i)
943 template <
typename T>
944 template <
typename TB>
947 for (uint32_t i=0;i<
m_count;++i)
953 template <
typename T>
954 template <
typename TB>
959 if (((
const T*)
m_data)[i] == item)
964 template <
typename T>
965 template <
typename TB>
975 template <
typename T>
976 template <
typename TB>
1000 template <
typename T>
1001 template <
typename TB>
1015 if (*(
m_data[i-1]) < item)
1017 else if (*(
m_data[i-1]) == item)
1025 template <
typename T>
1026 template <
typename TB>
1048 else if (
m_data[i-1] == item)
1057 template <
typename T>
1058 template <
typename TB>
1078 if (*(
m_data[i-1]) < item)
1080 else if (*(
m_data[i-1]) == item)
1089 template <
typename T>
1095 else if (item ==
m_data[i])
1102 template <
typename T>
1108 else if (*item == *
m_data[i])
1115 template <
typename T>
1116 template <
typename TB>
1121 appendCopy<TB>(item);
1122 else if (item ==
m_data[i])
1125 insertCopy<TB>(item,i);
1129 template <
typename T>
1140 template <
typename T>
1151 template <
typename T>
1152 template <
typename TB>
1159 for (uint32_t i = 0;i<
m_count;++i)
1163 template <
typename T>
1170 for (uint32_t i = 0;i<
m_count;++i)
1174 template <
typename T>
1177 #ifdef _XSENS_LIST_RANGE_CHECKS 1179 throw Exception(
"List.swap: index out of bounds");
1186 template <
typename T>
1190 for (uint32_t i = 0, end=
m_count-1; i < half; ++i,--end)
1198 template <
typename T>
1199 template <
typename TB>
1204 for (uint32_t i = 0; i <
m_count; ++i)
1212 #endif // XSENS_LIST_H int32_t(__cdecl * InequalityFunction)(const T &, const T &)
Type for an equality compare function, should return true when NOT equal.
Definition: xsens_list.h:211
void remove(const uint32_t index) XSENS_LIST_THROW
Removes an item at the given index in the list.
Definition: xsens_list.h:787
void deleteItemsOnDestroy(void)
Definition: xsens_list.h:1130
void swap(const uint32_t i, const uint32_t j) XSENS_LIST_THROW
Swaps two items in the list.
Definition: xsens_list.h:1175
void freeAndRemoveTail(const uint32_t count) XSENS_LIST_THROW
Definition: xsens_list.h:835
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.
Definition: xsens_list.h:450
void freeAndClear(void)
Calls free for all items in the list and then clears the list.
Definition: xsens_list.h:325
Definition: xsens_exception.h:9
int32_t(* cmpFunc)(const T &, const T &)
A comparison function type, should return -1, 0 or 1 for <, == and >
Definition: xsens_list.h:100
Contains the Janitor class-interfaces and implementations.
bool operator==(const List< TB > &lst)
Compare each item of the lists using the T == TB operator. If they're all identical, returns true.
Definition: xsens_list.h:1200
void deleteAndClear(void)
Calls delete for all items in the list and then clears the list.
Definition: xsens_list.h:317
#define __cdecl
Definition: cmtdef.h:51
void deleteAndRemove(const uint32_t index) XSENS_LIST_THROW
Removes an item at the given index in the list.
Definition: xsens_list.h:889
Dynamic list class.
Definition: xsens_list.h:79
uint32_t length(void) const
Returns the number of items currently in the list.
Definition: xsens_list.h:166
void reverse(void)
Reverse the order of the list, useful for sorted lists that are read/created in the reverse order...
Definition: xsens_list.h:1187
List()
Standard constructor, creates an empty list with some room for items.
Definition: xsens_list.h:238
T & maxVal(void) const XSENS_LIST_THROW
Retrieves the largest item, using the T::< operator.
Definition: xsens_list.h:422
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...
Definition: xsens_list.h:966
JanitorClassFunc< List< T > > * m_jcf
Used to clean up the list on exit.
Definition: xsens_list.h:92
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...
Definition: xsens_list.h:945
void sortAscendingDeref(void)
Sorts the list in an ascending order, using the T::< operator on dereferenced list items...
Definition: xsens_list.h:658
const T * getBuffer(void) const
Returns the start of the linear data buffer.
Definition: xsens_list.h:230
uint32_t find(const TB &item) const
Finds an item in an unsorted list (walk over all items) using the T::== operator. ...
Definition: xsens_list.h:926
Class function calling janitor class.
Definition: xsens_janitors.h:45
uint32_t findSortedDeref(const TB &item) const
Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced lis...
Definition: xsens_list.h:1002
void clear(void)
Clears the list without explicitly deleting anything.
Definition: xsens_list.h:333
void insert(const T &item, const uint32_t index)
Inserts an item at the given index, shifting any items below it down one spot.
Definition: xsens_list.h:462
T & minVal(void) const XSENS_LIST_THROW
Retrieves the smallest item, using the T::< operator.
Definition: xsens_list.h:436
uint32_t insertSorted(const T &item)
Assumes the list is sorted and inserts the item at the appropriate spot.
Definition: xsens_list.h:1090
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...
Definition: xsens_list.h:955
~List()
Destroy the list. This does NOT automatically delete items IN the list.
Definition: xsens_list.h:306
void appendDeepCopy(const List< T > &source)
Adds the contents of the source list to the end of the list.
Definition: xsens_list.h:374
bool m_manage
Definition: xsens_list.h:93
#define XSENS_LIST_THROW
Definition: xsens_list.h:58
void appendCopy(const TB &item)
Adds a copy of a referenced item to the end of the list using newItem = new TB(item).
Definition: xsens_list.h:395
#define XSENS_LIST_NOTFOUND
Definition: xsens_list.h:49
uint32_t m_count
The number of items currently in the list.
Definition: xsens_list.h:91
void deleteAndRemoveTail(const uint32_t count) XSENS_LIST_THROW
Definition: xsens_list.h:819
uint32_t removeDuplicateEntriesDeref(void)
Removes any duplicate entries and returns the number of items removed. Items are compared after deref...
Definition: xsens_list.h:870
void appendList(uint32_t count, const T *lst)
Adds a number of items to the end of the list.
Definition: xsens_list.h:365
uint32_t insertSortedCopy(const TB &item)
Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot...
Definition: xsens_list.h:1117
void freeAndRemove(const uint32_t index) XSENS_LIST_THROW
Removes an item at the given index in the list.
Definition: xsens_list.h:907
void resize(uint32_t newSize)
Resizes the list to at least the given size.
Definition: xsens_list.h:339
T & last(void) const XSENS_LIST_THROW
Retrieves the last item.
Definition: xsens_list.h:412
void appendShallowCopy(const List< T > &source)
Adds the contents of the source list to the end of the list.
Definition: xsens_list.h:384
T * m_data
The array containing the items.
Definition: xsens_list.h:89
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:62
void isShallowCopyOf(const List< T > &source)
Overwrites the current list with a direct copy (a=b) of another list.
Definition: xsens_list.h:1164
uint32_t removeDuplicateEntries(void)
Removes any duplicate entries and returns the number of items removed. Items are compared directly...
Definition: xsens_list.h:851
#define XSENS_LIST_LINEAR_SEARCH_TRESHOLD
Definition: xsens_list.h:67
uint32_t findSortedDerefForInsert(const TB &item) const
Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced lis...
Definition: xsens_list.h:1059
void sortAscending(void)
Sorts the list in an ascending order, using the T::< operator.
Definition: xsens_list.h:568
void removeTail(const uint32_t count) XSENS_LIST_THROW
Removes items from the end of the list.
Definition: xsens_list.h:804
uint32_t count(void) const
Returns the number of items currently in the list.
Definition: xsens_list.h:168
uint32_t insertSortedDeref(const T &item)
Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot...
Definition: xsens_list.h:1103
void freeItemsOnDestroy(void)
Definition: xsens_list.h:1141
void append(const T &item)
Adds an item to the end of the list.
Definition: xsens_list.h:357
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...
Definition: xsens_list.h:491
uint32_t findSorted(const TB &item) const
Finds an item in a sorted list (binary search) using the T::== and T::< operators.
Definition: xsens_list.h:977
uint32_t m_max
The current size of the data array.
Definition: xsens_list.h:90
void twinSortAscending(List< T2 > &twin)
Sorts the first list in an ascending order, using the T::< operator, the second list will be updated ...
Definition: xsens_list.h:750
void appendRelated(const TR &item)
Adds a related item to the end of the list, using the T = TR operator.
Definition: xsens_list.h:404
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...
Definition: xsens_list.h:477
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.
Definition: xsens_list.h:1027
void isDeepCopyOf(const List< T > &source)
Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i]) ...
Definition: xsens_list.h:1153