Main MRPT website > C++ reference for MRPT 1.5.6
xsens_list.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef _XSENS_LIST_H_2006_06_08
11 #define _XSENS_LIST_H_2006_06_08
12 
13 #include <mrpt/utils/mrpt_stdint.h>
14 
15 #ifndef _JANITORS_H_2006_05_01
16 # include "xsens_janitors.h"
17 #endif
18 
19 #ifdef _XSENS_COMPILE
20 # ifndef _XSENS_LIST_WITH_MATH
21 # define _XSENS_LIST_WITH_MATH
22 # endif
23 # ifndef _XSENS_LIST_IO
24 # define _XSENS_LIST_IO
25 # endif
26 #endif
27 
28 #ifdef _DEBUG
29 # define _XSENS_LIST_RANGE_CHECKS
30 #endif
31 
32 #ifdef _XSENS_LIST_WITH_MATH
33 # include <math.h>
34 # ifndef _XSENS_MATH_H_2006_05_31
35 # include "xsens_math.h"
36 # endif
37 #endif
38 
39 #define XSENS_LIST_NOTFOUND 0xFFFFFFFF
40 
41 #ifdef _XSENS_LIST_RANGE_CHECKS
42 //# define XSENS_LIST_THROW throw(...) // JLBC: Changed for MRPT in Linux in Debug
43 # define XSENS_LIST_THROW
44 #else
45 # define XSENS_LIST_THROW
46 #endif
47 
48 namespace xsens {
49 
50  /*! \brief Dynamic list class
51 
52  This class can store items of the given type. If the type supports the < operator
53  it can also be sorted.
54  Items in the list can be accessed through the [] operator or the get() function.
55 
56  Do NOT use any item type that requires a constructor to work correctly. Pointers to these
57  objects can work though.
58  */
59  template <typename T>
60  class List
61  {
62  private:
63  void operator = (const List& list); //!< intentionally NOT implemented due to ambiguous nature
64  //! Sorts the list in an ascending order, using the T::< operator.
65  void qSort(uint32_t left, uint32_t right);
66  //! Sorts the list in an ascending order, using the T::< operator on dereferenced list items.
67  void qSortDeref(uint32_t left, uint32_t right);
68 
69  protected:
70  T* m_data; //!< The array containing the items
71  uint32_t m_max; //!< The current size of the data array
72  uint32_t m_count; //!< The number of items currently in the list
73  JanitorClassFunc<List<T> >* m_jcf; //!< Used to clean up the list on exit
74  bool m_manage;
75 
76  //! Construct a list as a reference to a raw list
77  List(const uint32_t size, T* src, bool manage);
78  public:
79 
80  //! A comparison function type, should return -1, 0 or 1 for <, == and >
81  typedef int32_t (*cmpFunc) (const T&,const T&);
82 
83  //! Standard constructor, creates an empty list with some room for items.
84  List();
85  //! Construct a list with a capacity of at least the given size.
86  List(const uint32_t size);
87  //! Construct a list as a direct copy of another list
88  List(const List<T>& src);
89  //! Construct a list as a copy of a raw list
90  List(const uint32_t size, const T* src);
91  //! Destroy the list. This does NOT automatically delete items IN the list.
92  ~List();
93 
94  //! Calls delete for all items in the list and then clears the list.
95  void deleteAndClear(void);
96  //! Calls free for all items in the list and then clears the list.
97  void freeAndClear(void);
98  //! Clears the list without explicitly deleting anything.
99  void clear(void);
100  //! Resizes the list to at least the given size.
101  void resize(uint32_t newSize);
102  //! Adds an item to the end of the list.
103  void append(const T& item);
104  //! Adds a number of items to the end of the list.
105  void appendList(uint32_t count, const T* lst);
106  //! Adds the contents of the source list to the end of the list.
107  void appendDeepCopy(const List<T>& source);
108  //! Adds the contents of the source list to the end of the list.
109  void appendShallowCopy(const List<T>& source);
110  //! Adds a copy of a referenced item to the end of the list.
111  template <typename TB>
112  void appendCopy(const TB& item);
113  //! Adds a related item to the end of the list, using the T = TR operator.
114  template <typename TR>
115  void appendRelated(const TR& item);
116  //! Removes an item at the given index in the list.
117  void remove(const uint32_t index) XSENS_LIST_THROW;
118  //! Swaps two items in the list.
119  void swap(const uint32_t i, const uint32_t j) XSENS_LIST_THROW;
120  //! Removes an item at the given index in the list.
122  //! Removes an item at the given index in the list.
124  //! Retrieves the last item.
125  T& last(void) const XSENS_LIST_THROW;
126  //! Retrieves the item at the given index. An index beyond the end returns the first item.
127  T& get(const uint32_t index) const XSENS_LIST_THROW;
128  //! Retrieves the item at the given index. An index beyond the end probably causes an exception.
130  //! Inserts an item at the given index, shifting any items below it down one spot.
131  void insert(const T& item, const uint32_t index);
132  //! Inserts a copy of the referenced item at the given index, shifting any items below it down one spot.
133  template <typename TB>
134  void insertCopy(const TB& item, const uint32_t index);
135  //! Assumes the list is sorted and inserts the item at the appropriate spot.
136  uint32_t insertSorted(const T& item);
137  //! Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot.
138  uint32_t insertSortedDeref(const T& item);
139  //! Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot.
140  template <typename TB>
141  uint32_t insertSortedCopy(const TB& item);
142  //! Returns the number of items currently in the list.
143  uint32_t length(void) const { return m_count; }
144  //! Sorts the list in an ascending order, using the T::< operator.
145  void sortAscending(void);
146  //! Sorts the list in an ascending order, using the T::< operator on dereferenced list items.
147  void sortAscendingDeref(void);
148  //! Sorts the first list in an ascending order, using the T::< operator, the second list will be updated the same way.
149  template <typename T2>
150  void twinSortAscending(List<T2>& twin);
151  //! Finds an item in an unsorted list (walk over all items) using the T::== operator
152  template <typename TB>
153  uint32_t find(const TB& item) const;
154  //! Finds an item in an unsorted list (walk over all items) using the T::== operator on dereferenced list items
155  template <typename TB>
156  uint32_t findDeref(const TB& item) const;
157  //! Finds an item in a sorted list (binary search) using the T::== and T::< operators
158  template <typename TB>
159  uint32_t findSorted(const TB& item) const;
160  //! Finds an item in a sorted list (binary search) using the T::== and T::< operators on dereferenced list items
161  template <typename TB>
162  uint32_t findSortedDeref(const TB& item) const;
163  //! Reverse the order of the list, useful for sorted lists that are read/created in the reverse order
164  void reverse(void);
165  //! Removes items from the end of the list.
169 
170  //! Type for an equality compare function, should return true when NOT equal
171  typedef int32_t (__cdecl * InequalityFunction)(const T&, const T&);
172  //! Finds an item in an unsorted list (walk over all items) using the given inequality function
173  uint32_t find(const T item, InequalityFunction fnc) const;
174 
175  void deleteItemsOnDestroy(void);
176  void freeItemsOnDestroy(void);
177 
178  //! Removes any duplicate entries and returns the number of items removed. Items are compared directly.
180  //! Removes any duplicate entries and returns the number of items removed. Items are compared after dereferencing.
182 
183  //! Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i])
184  template <typename TB>
185  void isDeepCopyOf(const List<T>& source);
186  //! Overwrites the current list with a shallow (memcopy) copy of another list.
187  void isShallowCopyOf(const List<T>& source);
188 
189  //! Returns the start of the linear data buffer
190  const T* getBuffer(void) const { return m_data; }
191  #ifdef _XSENS_LIST_IO
192  #ifdef _XSENS_LIST_WITH_MATH
193  //! Saves the list as a matrix in a .mat file. This assumes that T is a Vector<T,E>
194  void saveAsMatlab(const char* filename, const char *varname) const;
195  #endif
196  #endif
197  };
198 
199  class IntList : public List<uint32_t>
200  {
201  private:
202  void operator = (const IntList& list); //!< intentionally NOT implemented due to ambiguous nature
203  public:
204  //! Standard constructor, creates an empty list with some room for items.
206  //! Construct a list with a capacity of at least the given size.
208  //! Construct a list as a direct copy of another list
210  //! Construct a list as a reference to a raw list
212 
213  bool operator == (const IntList& lst);
214 
215  void addValue(int32_t value);
216  int32_t deserialize(const char* str);
217  int32_t readFromString(const char* str);
218  int32_t serialize(char* buffer) const;
219  void setIncremental(const uint32_t start, const uint32_t end, const int32_t step);
220  int32_t writeToString(char* buffer) const;
221  int32_t writeToStringHex(char* buffer) const;
222  };
223 } // end of xsens namespace
224 
225 #endif // _XSENS_LIST_H_2006_06_08
void addValue(int32_t value)
Definition: xsens_list.cpp:157
GLuint GLuint GLsizei count
Definition: glext.h:3512
void freeItemsOnDestroy(void)
uint32_t m_count
The number of items currently in the list.
Definition: xsens_list.h:72
void clear(void)
Clears the list without explicitly deleting anything.
Definition: xsens_list.hpp:126
void append(const T &item)
Adds an item to the end of the list.
Definition: xsens_list.hpp:150
int32_t(* cmpFunc)(const T &, const T &)
A comparison function type, should return -1, 0 or 1 for <, == and >
Definition: xsens_list.h:81
void setIncremental(const uint32_t start, const uint32_t end, const int32_t step)
Definition: xsens_list.cpp:76
void appendDeepCopy(const List< T > &source)
Adds the contents of the source list to the end of the list.
Definition: xsens_list.hpp:167
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.hpp:242
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.hpp:738
int32_t readFromString(const char *str)
Definition: xsens_list.cpp:96
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.hpp:914
IntList()
Standard constructor, creates an empty list with some room for items.
Definition: xsens_list.h:205
GLuint buffer
Definition: glext.h:3775
void deleteAndRemoveTail(const uint32_t count) XSENS_LIST_THROW
Definition: xsens_list.hpp:807
void appendShallowCopy(const List< T > &source)
Adds the contents of the source list to the end of the list.
Definition: xsens_list.hpp:177
void appendRelated(const TR &item)
Adds a related item to the end of the list, using the T = TR operator.
Definition: xsens_list.hpp:197
bool operator==(const IntList &lst)
Definition: xsens_list.cpp:164
void freeAndRemoveTail(const uint32_t count) XSENS_LIST_THROW
Definition: xsens_list.hpp:823
void deleteAndClear(void)
Calls delete for all items in the list and then clears the list.
Definition: xsens_list.hpp:110
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.hpp:933
void reverse(void)
Reverse the order of the list, useful for sorted lists that are read/created in the reverse order...
bool m_manage
Definition: xsens_list.h:74
void appendCopy(const TB &item)
Adds a copy of a referenced item to the end of the list.
Definition: xsens_list.hpp:188
GLuint src
Definition: glext.h:6303
int32_t serialize(char *buffer) const
Definition: xsens_list.cpp:66
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.hpp:943
T * m_data
The array containing the items.
Definition: xsens_list.h:70
void resize(uint32_t newSize)
Resizes the list to at least the given size.
Definition: xsens_list.hpp:132
IntList(const IntList &src)
Construct a list as a direct copy of another list.
Definition: xsens_list.h:209
uint32_t insertSortedCopy(const TB &item)
Assumes the list is sorted and inserts a copy of the referenced item at the appropriate spot...
void operator=(const IntList &list)
intentionally NOT implemented due to ambiguous nature
void appendList(uint32_t count, const T *lst)
Adds a number of items to the end of the list.
Definition: xsens_list.hpp:158
void deleteAndRemove(const uint32_t index) XSENS_LIST_THROW
Removes an item at the given index in the list.
Definition: xsens_list.hpp:877
List()
Standard constructor, creates an empty list with some room for items.
Definition: xsens_list.hpp:38
void freeAndRemove(const uint32_t index) XSENS_LIST_THROW
Removes an item at the given index in the list.
Definition: xsens_list.hpp:895
T & last(void) const XSENS_LIST_THROW
Retrieves the last item.
Definition: xsens_list.hpp:205
GLuint index
Definition: glext.h:3891
void swap(const uint32_t i, const uint32_t j) XSENS_LIST_THROW
Swaps two items in the list.
GLuint GLuint end
Definition: glext.h:3512
IntList(const uint32_t size)
Construct a list with a capacity of at least the given size.
Definition: xsens_list.h:207
void removeTail(const uint32_t count) XSENS_LIST_THROW
Removes items from the end of the list.
Definition: xsens_list.hpp:792
Class function calling janitor class.
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.hpp:227
uint32_t insertSortedDeref(const T &item)
Assumes the list is sorted by dereferenced values and inserts the item at the appropriate spot...
JanitorClassFunc< List< T > > * m_jcf
Used to clean up the list on exit.
Definition: xsens_list.h:73
uint32_t insertSorted(const T &item)
Assumes the list is sorted and inserts the item at the appropriate spot.
Definition: xsens_list.hpp:992
int32_t(__cdecl * InequalityFunction)(const T &, const T &)
Type for an equality compare function, should return true when NOT equal.
Definition: xsens_list.h:171
void isShallowCopyOf(const List< T > &source)
Overwrites the current list with a shallow (memcopy) copy of another list.
void isDeepCopyOf(const List< T > &source)
Make a copy of the list, duplicating list items i with: copy[i] = new TB(*source[i]) ...
void operator=(const List &list)
intentionally NOT implemented due to ambiguous nature
void sortAscending(void)
Sorts the list in an ascending order, using the T::< operator.
Definition: xsens_list.hpp:453
int32_t writeToString(char *buffer) const
Definition: xsens_list.cpp:119
void qSort(uint32_t left, uint32_t right)
Sorts the list in an ascending order, using the T::< operator.
Definition: xsens_list.hpp:382
uint32_t removeDuplicateEntriesDeref(void)
Removes any duplicate entries and returns the number of items removed. Items are compared after deref...
Definition: xsens_list.hpp:858
Dynamic list class.
Definition: xsens_list.h:60
__int32 int32_t
Definition: rptypes.h:48
#define XSENS_LIST_THROW
Definition: xsens_list.h:45
void qSortDeref(uint32_t left, uint32_t right)
Sorts the list in an ascending order, using the T::< operator on dereferenced list items...
Definition: xsens_list.hpp:415
const T * getBuffer(void) const
Returns the start of the linear data buffer.
Definition: xsens_list.h:190
int32_t deserialize(const char *str)
Definition: xsens_list.cpp:56
uint32_t length(void) const
Returns the number of items currently in the list.
Definition: xsens_list.h:143
uint32_t m_max
The current size of the data array.
Definition: xsens_list.h:71
uint32_t removeDuplicateEntries(void)
Removes any duplicate entries and returns the number of items removed. Items are compared directly...
Definition: xsens_list.hpp:839
GLsizei GLsizei GLchar * source
Definition: glext.h:3908
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.hpp:968
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:92
void freeAndClear(void)
Calls free for all items in the list and then clears the list.
Definition: xsens_list.hpp:118
GLsizei const GLfloat * value
Definition: glext.h:3929
IntList(const uint32_t size, uint32_t *src)
Construct a list as a reference to a raw list.
Definition: xsens_list.h:211
GLsizeiptr size
Definition: glext.h:3779
int32_t writeToStringHex(char *buffer) const
Definition: xsens_list.cpp:138
GLuint start
Definition: glext.h:3512
unsigned __int32 uint32_t
Definition: rptypes.h:49
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.hpp:256
void sortAscendingDeref(void)
Sorts the list in an ascending order, using the T::< operator on dereferenced list items...
Definition: xsens_list.hpp:595
void deleteItemsOnDestroy(void)
~List()
Destroy the list. This does NOT automatically delete items IN the list.
Definition: xsens_list.hpp:99



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019