xsarray.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSARRAY_H
66 #define XSARRAY_H
67 
68 #include "xstypesconfig.h"
69 
70 #define XSARRAY_DECL(T)\
71  T* const m_data; \
72  const XsSize m_size; \
73  const XsSize m_reserved; \
74  const XsSize m_flags; \
75  XsArrayDescriptor const* const m_descriptor;
77 #define XSARRAY_STRUCT(S,T) struct S { XSARRAY_DECL(T) }
78 #define XSARRAY_INITIALIZER(D) { 0, 0, 0, XSDF_Managed, D }
79 
81 typedef void (*XsArrayItemSwapFunc)(void*, void*);
82 typedef void (*XsArrayItemStructFunc)(void*);
83 typedef void (*XsArrayItemCopyFunc)(void*, void const*);
84 typedef int (*XsArrayItemCompareFunc)(void const*, void const*);
85 typedef void (*XsArrayRawCopy)(void*, void const*, XsSize, XsSize);
86 
87 #define XSEXPCASTITEMSWAP (XsArrayItemSwapFunc)
88 #define XSEXPCASTITEMMAKE (XsArrayItemStructFunc)
89 #define XSEXPCASTITEMCOPY (XsArrayItemCopyFunc)
90 #define XSEXPCASTITEMCOMP (XsArrayItemCompareFunc)
91 #define XSEXPCASTRAWCOPY (XsArrayRawCopy)
92 
98 struct XsArrayDescriptor
99 {
100 #ifndef __cplusplus
101  const
102 #else
103 protected:
104  template <typename T, XsArrayDescriptor const& D, typename I> friend struct XsArrayImpl;
105 #endif
106  XsSize itemSize;
107  void (*itemSwap)(void* a, void* b);
108  void (*itemConstruct)(void* e);
109  void (*itemCopyConstruct)(void* e, void const* s);
110  void (*itemDestruct)(void* e);
111  void (*itemCopy)(void* to, void const* from);
112  int (*itemCompare)(void const* a, void const* b);
113  void (*rawCopy)(void* to, void const* from, XsSize count, XsSize iSize);
114 };
116 
117 #ifdef __cplusplus
118 #include <iterator>
119 #include <stdexcept>
120 
121 #if __cplusplus >= 201103L && !defined(XSENS_HAVE_TYPE_TRAITS)
122 #include <type_traits>
123 #define XSENS_HAVE_TYPE_TRAITS
124 #endif
125 
126 extern "C" {
127 #endif
128 
129 XSTYPES_DLL_API void XsArray_construct(void* thisPtr, XsArrayDescriptor const* const descriptor, XsSize count, void const* src);
130 XSTYPES_DLL_API void XsArray_copyConstruct(void* thisPtr, void const* src);
131 XSTYPES_DLL_API void XsArray_destruct(void* thisPtr);
132 XSTYPES_DLL_API void XsArray_assign(void* thisPtr, XsSize count, void const* src);
133 XSTYPES_DLL_API void XsArray_resize(void* thisPtr, XsSize count);
134 XSTYPES_DLL_API void XsArray_reserve(void* thisPtr, XsSize count);
135 XSTYPES_DLL_API void XsArray_copy(void* thisPtr, void const* src);
136 XSTYPES_DLL_API void XsArray_append(void* thisPtr, void const* other);
137 XSTYPES_DLL_API void XsArray_insert(void* thisPtr, XsSize index, XsSize count, void const* src);
138 XSTYPES_DLL_API void XsArray_erase(void* thisPtr, XsSize index, XsSize count);
139 XSTYPES_DLL_API void XsArray_swap(void* a, void* b);
140 XSTYPES_DLL_API int XsArray_compare(void const* a, void const* b);
141 XSTYPES_DLL_API int XsArray_compareSet(void const* a, void const* b);
142 XSTYPES_DLL_API int XsArray_comparePredicate(void const* a, void const* b, XsArrayItemCompareFunc predicate);
143 XSTYPES_DLL_API ptrdiff_t XsArray_find(void const* thisPtr, void const* needle);
144 XSTYPES_DLL_API ptrdiff_t XsArray_findPredicate(void const* thisPtr, void const* needle, XsArrayItemCompareFunc predicate);
145 XSTYPES_DLL_API int XsArray_empty(void const* thisPtr);
146 XSTYPES_DLL_API void const* XsArray_at(void const* thisPtr, XsSize index);
147 XSTYPES_DLL_API void* XsArray_atIndex(void* thisPtr, XsSize index);
148 XSTYPES_DLL_API void XsArray_removeDuplicates(void* thisPtr);
149 XSTYPES_DLL_API void XsArray_removeDuplicatesPredicate(void* thisPtr, XsArrayItemCompareFunc predicate);
150 XSTYPES_DLL_API void XsArray_rawCopy(void* to, void const* from, XsSize count, XsSize iSize);
151 XSTYPES_DLL_API void XsArray_sort(void* thisPtr);
152 XSTYPES_DLL_API void XsArray_reverse(void* thisPtr);
153 
154 struct XsArray
155 {
156  XSARRAY_DECL(void)
157 #ifdef __cplusplus
158  inline XsArray(XsArrayDescriptor const* descriptor, XsSize count = 0, void const* src = 0)
160  : m_data(0)
161  , m_size(0)
162  , m_reserved(0)
163  , m_flags(0)
164  , m_descriptor(0)
165  {
166  XsArray_construct(this, descriptor, count, src);
167  }
168 
170  inline XsArray(const XsArray& src)
171  : m_data(0)
172  , m_size(0)
173  , m_reserved(0)
174  , m_flags(0)
175  , m_descriptor(0)
176  {
177  XsArray_copyConstruct(this, &src);
178  }
179 
181  inline explicit XsArray(XsArrayDescriptor const* descriptor, void* ref, XsSize count, XsDataFlags flags)
182  : m_data(ref)
183  , m_size(count)
184  , m_reserved(count)
185  , m_flags((XsSize)flags)
186  , m_descriptor(descriptor)
187  {
188  }
189 
190 #ifndef SWIG
191  inline XsArray(XsArray&& src)
193  : m_data(0)
194  , m_size(0)
195  , m_reserved(0)
196  , m_flags(0)
197  , m_descriptor(src.m_descriptor)
198  {
199  if (!(src.m_flags & XSDF_Managed))
200  XsArray_copy(this, &src);
201  else
202  XsArray_swap(this, &src);
203  }
204 #endif
205 
207  ~XsArray()
208  {
209  XsArray_destruct(this);
210  }
211 
217  inline XsArray const& operator=(const XsArray& src)
218  {
219  if (this != &src)
220  XsArray_copy(this, &src);
221  return *this;
222  }
223 #endif
224 };
225 
226 typedef struct XsArray XsArray;
227 
228 #ifdef __cplusplus
229 } // extern "C"
230 
236 template <typename T, XsArrayDescriptor const& D, typename I>
237 struct XsArrayImpl : private XsArray
238 {
240  typedef T value_type;
241 
243  typedef XsSize size_type;
244 
246  typedef XsArrayImpl<T, D, I> ArrayImpl;
247 
253  inline explicit XsArrayImpl<T, D, I>(XsSize count = 0, T const* src = 0)
254  : XsArray(&D, count, src)
255  {
256  }
257 
259  inline XsArrayImpl<T, D, I>(ArrayImpl const& other)
260  : XsArray(other)
261  {
262  }
263 
264 #ifndef XSENS_NOITERATOR
265  template <typename Iterator>
267  inline explicit XsArrayImpl<T, D, I>(Iterator const& beginIt, Iterator const& endIt)
268  : XsArray(&D, 0, 0)
269  {
270  ptrdiff_t diff = endIt - beginIt;
271  if (diff > 0)
272  {
273  reserve((XsSize) diff);
274  for (Iterator it = beginIt; it != endIt; ++it)
275  push_back(*it);
276  }
277  }
278 #endif
279  inline explicit XsArrayImpl<T, D, I>(T* ref, XsSize sz, XsDataFlags flags /* = XSDF_None */)
281  : XsArray(&D, ref, sz, flags)
282  {
283  }
284 
286  inline ~XsArrayImpl()
287  {
288  XsArray_destruct(this);
289  }
290 
292  inline void clear()
293  {
294  XsArray_destruct(this);
295  }
296 
297 #ifndef SWIG
298 
304  inline int comparePredicate(ArrayImpl const& other, XsArrayItemCompareFunc predicate) const
305  {
306  return XsArray_comparePredicate(this, &other, predicate);
307  }
308 
315  inline bool isEqualPredicate(ArrayImpl const& other, XsArrayItemCompareFunc predicate) const
316  {
317  return !XsArray_comparePredicate(this, &other, predicate);
318  }
319 #endif
320 
326  inline bool operator == (ArrayImpl const& other) const
327  {
328  return !XsArray_compare(this, &other);
329  }
330 
336  inline bool operator != (ArrayImpl const& other) const
337  {
338  return !!XsArray_compare(this, &other);
339  }
340 
342  inline void reserve(XsSize count)
343  {
344  XsArray_reserve(this, count);
345  }
346 
348  inline XsSize reserved() const
349  {
350  return m_reserved;
351  }
352 
354  inline XsArrayDescriptor const& descriptor() const
355  {
356  return *m_descriptor;
357  }
358 
359 protected:
360 #ifndef XSENS_NOITERATOR
361 
362  template <ptrdiff_t F, typename R, typename Derived>
363  struct IteratorImplBase
364  {
365  public:
367  typedef ptrdiff_t difference_type;
369  typedef T value_type;
371  typedef T* pointer;
373  typedef T& reference;
374 #ifndef XSENS_NO_STL
375  typedef std::random_access_iterator_tag iterator_category;
377 #endif
378  typedef Derived this_type;
381  static const ptrdiff_t direction = F;
382  protected:
384  inline explicit IteratorImplBase(void* p = 0) : m_ptr((T*) p) {}
386  inline explicit IteratorImplBase(T* p) : m_ptr(p) {}
388  inline IteratorImplBase(this_type const& i) : m_ptr(i.m_ptr) {}
389  public:
390 #ifndef SWIG
391 
392  template <typename J>
393  inline T const& operator[](J index) const
394  {
395 #ifdef XSENS_HAVE_TYPE_TRAITS
396  static_assert(std::is_integral<J>::value || std::is_enum<J>::value, "Integral index required.");
397 #endif
398  return *ptrAt(m_ptr, F * static_cast<ptrdiff_t>(index));
399  }
401  template <typename J>
402  inline T& operator[](J index)
403  {
404 #ifdef XSENS_HAVE_TYPE_TRAITS
405  static_assert(std::is_integral<J>::value || std::is_enum<J>::value, "Integral index required.");
406 #endif
407  return *ptrAt(m_ptr, F * static_cast<ptrdiff_t>(index));
408  }
409 #else
410 
411  inline T const& operator[](int index) const
412  {
413  return *ptrAt(m_ptr, F * static_cast<ptrdiff_t>(index));
414  }
416  inline T& operator[](int index)
417  {
418  return *ptrAt(m_ptr, F * static_cast<ptrdiff_t>(index));
419  }
420 #endif
421  inline this_type& operator =(void* p)
423  {
424  m_ptr = (T*) p;
425  return *(this_type*)this;
426  }
428  inline this_type& operator =(T* p)
429  {
430  m_ptr = p;
431  return *(this_type*)this;
432  }
434  inline this_type& operator =(this_type const& i)
435  {
436  m_ptr = i.m_ptr;
437  return *(this_type*)this;
438  }
440  inline this_type& operator ++()
441  {
442  m_ptr = (T*) ptrAt(m_ptr, F);
443  return *(this_type*)this;
444  }
446  inline this_type operator ++(int)
447  {
448  this_type p(m_ptr);
449  m_ptr = (T*) ptrAt(m_ptr, F);
450  return p;
451  }
453  inline this_type& operator --()
454  {
455  m_ptr = (T*) ptrAt(m_ptr, -F);
456  return *(this_type*)this;
457  }
459  inline this_type operator --(int)
460  {
461  this_type p(m_ptr);
462  m_ptr = (T*) ptrAt(m_ptr, -F);
463  return p;
464  }
466  inline this_type const& operator +=(ptrdiff_t count)
467  {
468  m_ptr = ptrAt(m_ptr, F * count);
469  return *(this_type*)this;
470  }
472  inline this_type const& operator -=(ptrdiff_t count)
473  {
474  m_ptr = ptrAt(m_ptr, -F * count);
475  return *(this_type*)this;
476  }
478  inline this_type operator +(ptrdiff_t count) const
479  {
480  return this_type(ptrAt(m_ptr, F * count));
481  }
483  inline this_type operator -(ptrdiff_t count) const
484  {
485  return this_type(ptrAt(m_ptr, -F * count));
486  }
494  inline difference_type operator - (const this_type& other) const
495  {
496  return (F * (reinterpret_cast<char*>(m_ptr) - reinterpret_cast<char*>(other.m_ptr))) / D.itemSize;
497  }
499  inline bool operator == (this_type const& i) const
500  {
501  return m_ptr == i.m_ptr;
502  }
504  inline bool operator <= (this_type const& i) const
505  {
506  return (F == 1) ? (m_ptr <= i.m_ptr) : (m_ptr >= i.m_ptr);
507  }
509  inline bool operator < (this_type const& i) const
510  {
511  return (F == 1) ? (m_ptr < i.m_ptr) : (m_ptr > i.m_ptr);
512  }
514  inline bool operator != (this_type const& i) const
515  {
516  return m_ptr != i.m_ptr;
517  }
519  inline bool operator >= (this_type const& i) const
520  {
521  return (F == 1) ? (m_ptr >= i.m_ptr) : (m_ptr <= i.m_ptr);
522  }
524  inline bool operator > (this_type const& i) const
525  {
526  return (F == 1) ? (m_ptr > i.m_ptr) : (m_ptr < i.m_ptr);
527  }
529  inline R& operator *() const
530  {
531  return *(R*) ptr();
532  }
534  inline R* operator ->() const
535  {
536  return (R*) ptr();
537  }
539  inline T* ptr() const
540  {
541  return m_ptr;
542  }
543  private:
545  T* m_ptr;
546  };
547 #endif
548 
549 public:
550 #ifndef XSENS_NOITERATOR
551 
552  template <ptrdiff_t F>
553  struct IteratorImpl : public IteratorImplBase<F, T, IteratorImpl<F> >
554  {
555  private:
557  typedef IteratorImplBase<F, T, IteratorImpl<F> > ParentType;
558  public:
560  inline IteratorImpl(void* p = 0) : ParentType(p) {}
562  inline IteratorImpl(T* p) : ParentType(p) {}
564  inline IteratorImpl(const IteratorImpl& i) : ParentType(i) {}
565  };
566 
568  template <ptrdiff_t F>
569  struct IteratorImplConst : public IteratorImplBase<F, T const, IteratorImplConst<F> >
570  {
571  private:
573  typedef IteratorImplBase<F, T const, IteratorImplConst<F> > ParentType;
574  public:
576  inline IteratorImplConst(void* p = 0) : ParentType(p) {}
578  inline IteratorImplConst(T* p) : ParentType(p) {}
580  inline IteratorImplConst(IteratorImpl<F> const& i) : ParentType(i.ptr()) {}
582  inline IteratorImplConst(IteratorImplConst const& i) : ParentType(i) {}
583  };
584 
586  typedef IteratorImpl<1> iterator;
588  typedef IteratorImpl < -1 > reverse_iterator;
590  typedef IteratorImplConst<1> const_iterator;
592  typedef IteratorImplConst < -1 > const_reverse_iterator;
593 
595  inline const_iterator begin() const
596  {
597  return const_iterator(m_data);
598  }
600  inline const_iterator end() const
601  {
602  return begin() + (ptrdiff_t) size();
603  }
604 
606  inline const_reverse_iterator rbegin() const
607  {
608  return rend() - (ptrdiff_t) size();
609  }
611  inline const_reverse_iterator rend() const
612  {
613  return const_reverse_iterator(m_data) + (ptrdiff_t) 1;
614  }
615 
617  inline iterator begin()
618  {
619  return iterator(m_data);
620  }
622  inline iterator end()
623  {
624  return begin() + (ptrdiff_t) size();
625  }
626 
628  inline reverse_iterator rbegin()
629  {
630  return rend() - (ptrdiff_t) size();
631  }
633  inline reverse_iterator rend()
634  {
635  return reverse_iterator(m_data) + (ptrdiff_t) 1;
636  }
637 #endif
638 #ifndef SWIG
639 
640  template <typename J>
641  inline T const& operator[](J index) const
642  {
643 #ifdef XSENS_HAVE_TYPE_TRAITS
644  static_assert(std::is_integral<J>::value || std::is_enum<J>::value, "Integral index required.");
645 #endif
646  assert(static_cast<XsSize>(index) < m_size);
647  return *ptrAt(m_data, static_cast<ptrdiff_t>(index));
648  }
650  template <typename J>
651  inline T& operator[](J index)
652  {
653 #ifdef XSENS_HAVE_TYPE_TRAITS
654  static_assert(std::is_integral<J>::value || std::is_enum<J>::value, "Integral index required.");
655 #endif
656  assert(static_cast<XsSize>(index) < m_size);
657  return *ptrAt(m_data, static_cast<ptrdiff_t>(index));
658  }
659 #else
660 
661  inline T const& operator[](int index) const
662  {
663  assert(static_cast<XsSize>(index) < m_size);
664  return *ptrAt(m_data, static_cast<ptrdiff_t>(index));
665  }
667  inline T& operator[](int index)
668  {
669  assert(static_cast<XsSize>(index) < m_size);
670  return *ptrAt(m_data, static_cast<ptrdiff_t>(index));
671  }
672 #endif
673 
675  inline T value(XsSize index) const
676  {
677 #ifdef XSENS_NO_EXCEPTIONS
678  assert(index >= m_size);
679 #else
680  if (index >= m_size)
681  throw std::out_of_range("index out of range");
682 #endif
683  return *ptrAt(m_data, index);
684  }
686  inline T first() const
687  {
688 #ifdef XSENS_NO_EXCEPTIONS
689  assert(m_size);
690 #else
691  if (!m_size)
692  throw std::out_of_range("out of range");
693 #endif
694  return *ptrAt(m_data, 0);
695  }
697  inline T last() const
698  {
699 #ifdef XSENS_NO_EXCEPTIONS
700  assert(m_size);
701 #else
702  if (!m_size)
703  throw std::out_of_range("out of range");
704 #endif
705  return *ptrAt(m_data, m_size - 1);
706  }
708  inline T const& at(XsSize index) const
709  {
710 #ifdef XSENS_NO_EXCEPTIONS
711  assert(index >= m_size);
712 #else
713  if (index >= m_size)
714  throw std::out_of_range("index out of range");
715 #endif
716  return *ptrAt(m_data, (ptrdiff_t) index);
717  }
719  inline T& at(XsSize index)
720  {
721 #ifdef XSENS_NO_EXCEPTIONS
722  assert(index >= m_size);
723 #else
724  if (index >= m_size)
725  throw std::out_of_range("index out of range");
726 #endif
727  return *ptrAt(m_data, index);
728  }
734  inline void insert(T const& item, XsSize index)
735  {
736  insert(&item, index, 1);
737  }
744  inline void insert(T const* items, XsSize index, XsSize count)
745  {
746  XsArray_insert(this, index, count, items);
747  }
748 
749 #ifndef XSENS_NOITERATOR
750 
755  inline void insert(T const& item, const_iterator it)
756  {
757  insert(&item, indexOf(it), 1);
758  }
764  inline void insert(T const& item, const_reverse_iterator it)
765  {
766  insert(&item, indexOf(it), 1);
767  }
768 
775  inline void insert(T const* items, const_iterator it, XsSize count)
776  {
777  insert(items, indexOf(it), count);
778  }
785  inline void insert(T const* items, const_reverse_iterator it, XsSize count)
786  {
787  insert(items, indexOf(it), count);
788  }
789 #endif
790 
792  inline void push_back(T const& item)
793  {
794  insert(&item, (XsSize) - 1, 1);
795  }
797  inline void pop_back(XsSize count = 1)
798  {
799  if (count >= size())
800  erase(0, (XsSize) - 1);
801  else
802  erase(size() - count, count);
803  }
805  inline void push_front(T const& item)
806  {
807  insert(&item, 0, 1);
808  }
810  inline void pop_front(XsSize count = 1)
811  {
812  erase(0, count);
813  }
818  inline XsSize size() const noexcept
819  {
820  return m_size;
821  }
823  inline void erase(XsSize index, XsSize count = 1)
824  {
825  XsArray_erase(this, index, count);
826  }
827 #ifndef XSENS_NOITERATOR
828 
829  inline iterator erase(iterator it)
830  {
831  XsSize idx = indexOf(it);
832  erase(idx, 1);
833  return (idx < size()) ? ptrAt(m_data, idx) : end();
834  }
836  inline reverse_iterator erase(reverse_iterator it)
837  {
838  XsSize idx = indexOf(it);
839  erase(idx, 1);
840  return (idx < size()) ? ptrAt(m_data, idx) : rend();
841  }
842 #endif
843 
844  inline void assign(XsSize count, T const* src)
845  {
846  XsArray_assign(this, count, src);
847  }
849  inline void resize(XsSize count)
850  {
851  XsArray_resize(this, count);
852  }
858  inline void setSize(XsSize count)
859  {
860  if (count != m_size)
861  XsArray_assign(this, count, 0);
862  }
864  inline void append(ArrayImpl const& other)
865  {
866  XsArray_append(this, &other);
867  }
869  inline ArrayImpl& operator=(ArrayImpl const& other)
870  {
871  if (this != &other)
872  XsArray_copy(this, &other);
873  return *this;
874  }
876  inline bool empty() const noexcept
877  {
878  return (size() == 0) || (m_data == 0) || (m_flags & XSDF_Empty);
879  }
880 
881 #ifndef XSENS_NOITERATOR
882 
883  inline I const& inherited() const
884  {
885  return *static_cast<I const*>(this);
886  }
887 
889  inline I& inherited()
890  {
891  return *static_cast<I*>(this);
892  }
893 
894 #endif
895 
896  inline void swap(ArrayImpl& other)
897  {
898  XsArray_swap(this, &other);
899  }
900 
902  friend void swap(ArrayImpl& first, ArrayImpl& second)
903  {
904  first.swap(second);
905  }
906 
908  inline void swap(XsSize a, XsSize b)
909  {
910  using std::swap;
911  if (a >= size() || b >= size())
912  return;
913  swap(at(a), at(b));
914  }
915 
923 #ifndef XSENS_NOITERATOR
924  inline I& operator <<(T const& item)
925  {
926  push_back(item);
927  return inherited();
928  }
929 #endif
930 
932  inline ptrdiff_t find(T const& needle) const
933  {
934  return XsArray_find(this, &needle);
935  }
936 #ifndef SWIG
937 
938  inline ptrdiff_t findPredicate(T const& needle, XsArrayItemCompareFunc predicate) const
939  {
940  return XsArray_findPredicate(this, &needle, predicate);
941  }
942 #endif
943 #ifndef XSENS_NOITERATOR
944 
949  template <ptrdiff_t F, typename R, typename Derived>
950  XsSize indexOf(IteratorImplBase<F, R, Derived> const& it) const
951  {
952  ptrdiff_t d = ((char const*) it.ptr() - (char const*) m_data);
953  if (d >= 0)
954  {
955  XsSize r = d / D.itemSize;
956  if (r <= size())
957  return r;
958  return size();
959  }
960  return 0;
961  }
962 #endif
963 
965  inline void removeDuplicates()
966  {
968  }
969 
971  inline void removeDuplicatesPredicate(XsArrayItemCompareFunc predicate)
972  {
973  XsArray_removeDuplicatesPredicate(this, predicate);
974  }
975 
977  inline void sort()
978  {
979  XsArray_sort(this);
980  }
981 
983  inline void reverse()
984  {
985  XsArray_reverse(this);
986  }
987 
988 private:
998  inline static const T* ptrAt(void const* ptr, ptrdiff_t count)
999  {
1000  return (const T*)(void const*)(((char const*)ptr) + count * (ptrdiff_t)D.itemSize);
1001  }
1002 
1012  inline static T* ptrAt(void* ptr, ptrdiff_t count)
1013  {
1014  return (T*)(void*)(((char*)ptr) + count * (ptrdiff_t)D.itemSize);
1015  }
1016 };
1017 #endif
1018 
1019 #endif
XsArrayDescriptor
This object describes how to treat the data in an array.
Definition: xsarray.h:103
XSARRAY_DECL
#define XSARRAY_DECL(T)
Definition: xsarray.h:70
XsArray::XsArray_construct
void XsArray_construct(void *thisPtr, XsArrayDescriptor const *const descriptor, XsSize count, void const *src)
Initializes the XsArray with space for count items and copies them from src.
Definition: xsarray.c:102
XsArray::XsArray_comparePredicate
int XsArray_comparePredicate(void const *a, void const *b, XsArrayItemCompareFunc predicate)
Returns non-zero if the lists are different, 0 if they're equal.
Definition: xsarray.c:514
XsArray::XsArray_rawCopy
void XsArray_rawCopy(void *to, void const *from, XsSize count, XsSize iSize)
Copies items optimized in a direct way.
Definition: xsarray.c:707
XsArray::XsArray_removeDuplicates
void XsArray_removeDuplicates(void *thisPtr)
Removes duplicate entries from the array, keeping only the first instance of each value.
Definition: xsarray.c:649
XsArray::XsArray_compare
int XsArray_compare(void const *a, void const *b)
Returns non-zero if the lists are different, 0 if they're equal.
Definition: xsarray.c:479
XsArray::XsArray_compareSet
int XsArray_compareSet(void const *a, void const *b)
Returns -1 if a is smaller in some way than b, 1 if it is larger in some way and 0 if both lists are ...
Definition: xsarray.c:549
XsArray::XsArray_reverse
void XsArray_reverse(void *thisPtr)
Reverses the contents of the array by repeatedly using the itemSwap func in the XsArrayDescriptor.
Definition: xsarray.c:726
XsArrayDescriptor::rawCopy
void(* rawCopy)(void *to, void const *from, XsSize count, XsSize iSize)
The function to use for copying the data of an array of from to to.
Definition: xsarray.h:118
s
XmlRpcServer s
XsArray::XsArray_destruct
void XsArray_destruct(void *thisPtr)
Clears and frees memory allocated by the XsArray.
Definition: xsarray.c:157
XsArray::XsArray_append
void XsArray_append(void *thisPtr, void const *other)
Appends the other list to thisArray list.
Definition: xsarray.c:319
XsArray
Provides generic storage for data in an array and manipulation operations on that data.
Definition: xsarray.h:159
XsArray::XsArray_copy
void XsArray_copy(void *thisPtr, void const *src)
Copy the contents of src to thisArray.
Definition: xsarray.c:305
XsArray::XsArray_sort
void XsArray_sort(void *thisPtr)
Sorts the array using the itemCompare func in the XsArrayDescriptor.
Definition: xsarray.c:716
XsArrayDescriptor::itemConstruct
void(* itemConstruct)(void *e)
The function to use for constructing a new array item. May be 0 for simple types.
Definition: xsarray.h:113
XsArray::XsArray_erase
void XsArray_erase(void *thisPtr, XsSize index, XsSize count)
Removes a count items from the list starting at index.
Definition: xsarray.c:448
operator==
bool operator==(const XsFilterProfile &lhs, const XsFilterProfile &rhs)
Returns true if lhs has the same type as rhs.
Definition: scenariomatchpred.h:81
XsArray::XsArray_copyConstruct
void XsArray_copyConstruct(void *thisPtr, void const *src)
Initializes the XsArray with a copy of src.
Definition: xsarray.c:144
XsArray::XsArray_atIndex
void * XsArray_atIndex(void *thisPtr, XsSize index)
Returns a pointer to the item at the supplied index or a null pointer if it is out of bounds.
Definition: xsarray.c:638
XsArrayDescriptor::itemDestruct
void(* itemDestruct)(void *e)
The function to use for destructing a array item. May be 0 for simple types.
Definition: xsarray.h:115
XsArrayDescriptor::itemSwap
void(* itemSwap)(void *a, void *b)
The function to use for swapping the data of two array items.
Definition: xsarray.h:112
XsArray::XsArray_swap
void XsArray_swap(void *a, void *b)
Swap the contents of a with those of b.
Definition: xsarray.c:408
d
d
XsArray::XsArray_removeDuplicatesPredicate
void XsArray_removeDuplicatesPredicate(void *thisPtr, XsArrayItemCompareFunc predicate)
Removes duplicate entries from the array, keeping only the first instance of each value.
Definition: xsarray.c:670
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
XsArrayDescriptor::itemCopyConstruct
void(* itemCopyConstruct)(void *e, void const *s)
The function to use for constructing a new array item with a source initializer. This may not be 0.
Definition: xsarray.h:114
XsArray::XsArray_assign
void XsArray_assign(void *thisPtr, XsSize count, void const *src)
Reinitializes the XsArray with space for count items and copies them from src.
Definition: xsarray.c:186
XsArray::XsArray_resize
void XsArray_resize(void *thisPtr, XsSize count)
Resizes the existing list to count items.
Definition: xsarray.c:227
XsArray::XsArray_insert
void XsArray_insert(void *thisPtr, XsSize index, XsSize count, void const *src)
Insert count items from src at index in the array.
Definition: xsarray.c:372
XSDF_Empty
@ XSDF_Empty
The object contains undefined data / should be considered empty. Usually only relevant when XSDF_Fixe...
Definition: xstypedefs.h:112
XsArray::XsArray_reserve
void XsArray_reserve(void *thisPtr, XsSize count)
Reserves space for count items.
Definition: xsarray.c:256
xstypesconfig.h
append
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
XsArray
struct XsArray XsArray
Definition: xsarray.h:231
XsArrayDescriptor::itemSize
const XsSize itemSize
The size of an array item in bytes.
Definition: xsarray.h:111
XsArrayDescriptor::itemCopy
void(* itemCopy)(void *to, void const *from)
The function to use for copying the data of from to to.
Definition: xsarray.h:116
XSTYPES_DLL_API
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:65
XsArrayDescriptor::itemCompare
int(* itemCompare)(void const *a, void const *b)
The function to use for comparing two items.
Definition: xsarray.h:117
XsArray::XsArray_at
void const * XsArray_at(void const *thisPtr, XsSize index)
Returns a pointer to the item at the supplied index or a null pointer if it is out of bounds.
Definition: xsarray.c:625
operator<<
std::ostream & operator<<(std::ostream &os, JlHexLogger< char > const &hex)
Definition: journaller.cpp:388
XsDataFlags
XsDataFlags
These flags define the behaviour of data contained by Xsens data structures.
Definition: xstypedefs.h:107
XSDF_Managed
@ XSDF_Managed
The contained data should be managed (freed) by the object, when false, the object assumes the memory...
Definition: xstypedefs.h:110
XsArray::XsArray_empty
int XsArray_empty(void const *thisPtr)
Returns whether the array is empty.
Definition: xsarray.c:693
XsArray::XsArray_find
ptrdiff_t XsArray_find(void const *thisPtr, void const *needle)
Returns the index of needle in the list or -1 if it wasn't found.
Definition: xsarray.c:585
XsArray::XsArray_findPredicate
ptrdiff_t XsArray_findPredicate(void const *thisPtr, void const *needle, XsArrayItemCompareFunc predicate)
Returns the index of needle in the list or -1 if it wasn't found.
Definition: xsarray.c:607


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20