1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: auto-resizable (i.e. dynamic) array support
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
17 #if wxUSE_STD_CONTAINERS
18 #include "wx/beforestd.h"
21 #include "wx/afterstd.h"
25 This header defines the dynamic arrays and object arrays (i.e. arrays which
26 own their elements). Dynamic means that the arrays grow automatically as
29 These macros are ugly (especially if you look in the sources ;-), but they
30 allow us to define "template" classes without actually using templates and so
31 this works with all compilers (and may be also much faster to compile even
32 with a compiler which does support templates). The arrays defined with these
35 Range checking is performed in debug build for both arrays and objarrays but
36 not in release build - so using an invalid index will just lead to a crash
39 Note about memory usage: arrays never shrink automatically (although you may
40 use Shrink() function explicitly), they only grow, so loading 10 millions in
41 an array only to delete them 2 lines below might be a bad idea if the array
42 object is not going to be destroyed soon. However, as it does free memory
43 when destroyed, it is ok if the array is a local variable.
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
51 The initial size by which an array grows when an element is added default
52 value avoids allocate one or two bytes when the array is created which is
55 #define WX_ARRAY_DEFAULT_INITIAL_SIZE (16)
57 #define _WX_ERROR_REMOVE "removing inexistent element in wxArray::Remove"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
64 Callback compare function for quick sort.
66 It must return negative value, 0 or positive value if the first item is
67 less than, equal to or greater than the second one.
71 typedef int (wxCMPFUNC_CONV
*CMPFUNC
)(const void* pItem1
, const void* pItem2
);
74 // ----------------------------------------------------------------------------
75 // Base class managing data having size of type 'long' (not used directly)
77 // NB: for efficiency this often used class has no virtual functions (hence no
78 // virtual table), even dtor is *not* virtual. If used as expected it
79 // won't create any problems because ARRAYs from DEFINE_ARRAY have no dtor
80 // at all, so it's not too important if it's not called (this happens when
81 // you cast "SomeArray *" as "BaseArray *" and then delete it)
82 // ----------------------------------------------------------------------------
84 #if wxUSE_STD_CONTAINERS
87 class wxArray_SortFunction
90 typedef int (wxCMPFUNC_CONV
*CMPFUNC
)(T
* pItem1
, T
* pItem2
);
92 wxArray_SortFunction(CMPFUNC f
) : m_f(f
) { }
93 bool operator()(const T
& i1
, const T
& i2
)
94 { return m_f((T
*)&i1
, (T
*)&i2
) < 0; }
99 template<class T
, typename F
>
100 class wxSortedArray_SortFunction
105 wxSortedArray_SortFunction(CMPFUNC f
) : m_f(f
) { }
106 bool operator()(const T
& i1
, const T
& i2
)
107 { return m_f(i1
, i2
) < 0; }
112 #define _WX_DECLARE_BASEARRAY(T, name, classexp) \
113 typedef int (wxCMPFUNC_CONV *CMPFUN##name)(T pItem1, T pItem2); \
114 typedef wxSortedArray_SortFunction<T, CMPFUN##name> name##_Predicate; \
115 _WX_DECLARE_BASEARRAY_2(T, name, name##_Predicate, classexp)
117 #define _WX_DECLARE_BASEARRAY_2(T, name, predicate, classexp) \
118 classexp name : public std::vector<T> \
120 typedef predicate Predicate; \
121 typedef predicate::CMPFUNC SCMPFUNC; \
123 typedef wxArray_SortFunction<T>::CMPFUNC CMPFUNC; \
126 typedef T base_type; \
128 name() : std::vector<T>() { } \
129 name(size_type n) : std::vector<T>(n) { } \
130 name(size_type n, const_reference v) : std::vector<T>(n, v) { } \
132 void Empty() { clear(); } \
133 void Clear() { clear(); } \
134 void Alloc(size_t uiSize) { reserve(uiSize); } \
135 void Shrink() { name tmp(*this); swap(tmp); } \
137 size_t GetCount() const { return size(); } \
138 void SetCount(size_t n, T v = T()) { resize(n, v); } \
139 bool IsEmpty() const { return empty(); } \
140 size_t Count() const { return size(); } \
142 T& Item(size_t uiIndex) const \
143 { wxASSERT( uiIndex < size() ); return (T&)operator[](uiIndex); } \
144 T& Last() const { return Item(size() - 1); } \
146 int Index(T item, bool bFromEnd = false) const \
150 const const_reverse_iterator b = rbegin(), \
152 for ( const_reverse_iterator i = b; i != e; ++i ) \
154 return (int)(e - i - 1); \
158 const const_iterator b = begin(), \
160 for ( const_iterator i = b; i != e; ++i ) \
162 return (int)(i - b); \
165 return wxNOT_FOUND; \
167 int Index(T lItem, CMPFUNC fnCompare) const \
169 Predicate p((SCMPFUNC)fnCompare); \
170 const_iterator i = std::lower_bound(begin(), end(), lItem, p);\
171 return i != end() && !p(lItem, *i) ? (int)(i - begin()) \
174 size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const \
176 Predicate p((SCMPFUNC)fnCompare); \
177 const_iterator i = std::lower_bound(begin(), end(), lItem, p);\
178 return i - begin(); \
180 void Add(T lItem, size_t nInsert = 1) \
181 { insert(end(), nInsert, lItem); } \
182 size_t Add(T lItem, CMPFUNC fnCompare) \
184 size_t n = IndexForInsert(lItem, fnCompare); \
188 void Insert(T lItem, size_t uiIndex, size_t nInsert = 1) \
189 { insert(begin() + uiIndex, nInsert, lItem); } \
190 void Remove(T lItem) \
192 int n = Index(lItem); \
193 wxCHECK_RET( n != wxNOT_FOUND, _WX_ERROR_REMOVE ); \
194 RemoveAt((size_t)n); \
196 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
197 { erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \
199 void Sort(CMPFUNC fCmp) \
201 wxArray_SortFunction<T> p(fCmp); \
202 std::sort(begin(), end(), p); \
206 #else // if !wxUSE_STD_CONTAINERS
208 #define _WX_DECLARE_BASEARRAY(T, name, classexp) \
211 typedef CMPFUNC SCMPFUNC; /* for compatibility wuth wxUSE_STD_CONTAINERS */ \
214 name(const name& array); \
215 name& operator=(const name& src); \
218 void Empty() { m_nCount = 0; } \
220 void Alloc(size_t n) { if ( n > m_nSize ) Realloc(n); } \
223 size_t GetCount() const { return m_nCount; } \
224 void SetCount(size_t n, T defval = T()); \
225 bool IsEmpty() const { return m_nCount == 0; } \
226 size_t Count() const { return m_nCount; } \
228 typedef T base_type; \
231 T& Item(size_t uiIndex) const \
232 { wxASSERT( uiIndex < m_nCount ); return m_pItems[uiIndex]; } \
233 T& operator[](size_t uiIndex) const { return Item(uiIndex); } \
235 int Index(T lItem, bool bFromEnd = false) const; \
236 int Index(T lItem, CMPFUNC fnCompare) const; \
237 size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const; \
238 void Add(T lItem, size_t nInsert = 1); \
239 size_t Add(T lItem, CMPFUNC fnCompare); \
240 void Insert(T lItem, size_t uiIndex, size_t nInsert = 1); \
241 void Remove(T lItem); \
242 void RemoveAt(size_t uiIndex, size_t nRemove = 1); \
244 void Sort(CMPFUNC fnCompare); \
246 /* *minimal* STL-ish interface, for derived classes */ \
247 typedef T value_type; \
248 typedef value_type* iterator; \
249 typedef const value_type* const_iterator; \
250 typedef value_type& reference; \
251 typedef const value_type& const_reference; \
252 typedef int difference_type; \
253 typedef size_t size_type; \
255 void assign(const_iterator first, const_iterator last); \
256 void assign(size_type n, const_reference v); \
257 size_type capacity() const { return m_nSize; } \
258 iterator erase(iterator first, iterator last) \
260 size_type idx = first - begin(); \
261 RemoveAt(idx, last - first); \
262 return begin() + idx; \
264 iterator erase(iterator it) { return erase(it, it + 1); } \
265 void insert(iterator it, size_type n, const value_type& v) \
266 { Insert(v, it - begin(), n); } \
267 iterator insert(iterator it, const value_type& v = value_type()) \
269 size_type idx = it - begin(); \
271 return begin() + idx; \
273 void insert(iterator it, const_iterator first, const_iterator last);\
274 void pop_back() { RemoveAt(size() - 1); } \
275 void push_back(const value_type& v) { Add(v); } \
276 void reserve(size_type n) { Alloc(n); } \
277 void resize(size_type count, value_type defval = value_type()) \
279 if ( count < m_nCount ) \
282 SetCount(count, defval); \
285 iterator begin() { return m_pItems; } \
286 iterator end() { return m_pItems + m_nCount; } \
287 const_iterator begin() const { return m_pItems; } \
288 const_iterator end() const { return m_pItems + m_nCount; } \
290 void swap(name& other) \
292 wxSwap(m_nSize, other.m_nSize); \
293 wxSwap(m_nCount, other.m_nCount); \
294 wxSwap(m_pItems, other.m_pItems); \
297 /* the following functions may be made directly public because */ \
298 /* they don't use the type of the elements at all */ \
300 void clear() { Clear(); } \
301 bool empty() const { return IsEmpty(); } \
302 size_type max_size() const { return INT_MAX; } \
303 size_type size() const { return GetCount(); } \
306 void Grow(size_t nIncrement = 0); \
307 bool Realloc(size_t nSize); \
315 #endif // !wxUSE_STD_CONTAINERS
317 // ============================================================================
318 // The private helper macros containing the core of the array classes
319 // ============================================================================
321 // Implementation notes:
323 // JACS: Salford C++ doesn't like 'var->operator=' syntax, as in:
324 // { ((wxBaseArray *)this)->operator=((const wxBaseArray&)src);
325 // so using a temporary variable instead.
327 // The classes need a (even trivial) ~name() to link under Mac X
329 // ----------------------------------------------------------------------------
330 // _WX_DEFINE_TYPEARRAY: array for simple types
331 // ----------------------------------------------------------------------------
333 #if wxUSE_STD_CONTAINERS
335 // in STL case we don't need the entire base arrays hack as standard container
336 // don't suffer from alignment/storage problems as our home-grown do
337 #define _WX_DEFINE_TYPEARRAY(T, name, base, classexp) \
338 _WX_DECLARE_BASEARRAY(T, name, classexp)
340 #define _WX_DEFINE_TYPEARRAY_PTR(T, name, base, classexp) \
341 _WX_DEFINE_TYPEARRAY(T, name, base, classexp)
343 #else // if !wxUSE_STD_CONTAINERS
345 // common declaration used by both _WX_DEFINE_TYPEARRAY and
346 // _WX_DEFINE_TYPEARRAY_PTR
347 #define _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, ptrop) \
348 wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(base::base_type), \
349 TypeTooBigToBeStoredIn##base, \
351 typedef int (CMPFUNC_CONV *CMPFUNC##T)(T *pItem1, T *pItem2); \
352 classexp name : public base \
358 T& operator[](size_t uiIndex) const \
359 { return (T&)(base::operator[](uiIndex)); } \
360 T& Item(size_t uiIndex) const \
361 { return (T&)(base::operator[](uiIndex)); } \
363 { return (T&)(base::operator[](GetCount() - 1)); } \
365 int Index(T lItem, bool bFromEnd = false) const \
366 { return base::Index((base_type)lItem, bFromEnd); } \
368 void Add(T lItem, size_t nInsert = 1) \
369 { base::Add((base_type)lItem, nInsert); } \
370 void Insert(T lItem, size_t uiIndex, size_t nInsert = 1) \
371 { base::Insert((base_type)lItem, uiIndex, nInsert) ; } \
373 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
374 { base::RemoveAt(uiIndex, nRemove); } \
375 void Remove(T lItem) \
376 { int iIndex = Index(lItem); \
377 wxCHECK_RET( iIndex != wxNOT_FOUND, _WX_ERROR_REMOVE); \
378 base::RemoveAt((size_t)iIndex); } \
380 void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC)fCmp); } \
382 /* STL-like interface */ \
384 typedef base::iterator biterator; \
385 typedef base::const_iterator bconst_iterator; \
386 typedef base::value_type bvalue_type; \
387 typedef base::const_reference bconst_reference; \
389 typedef T value_type; \
390 typedef value_type* pointer; \
391 typedef const value_type* const_pointer; \
392 typedef value_type* iterator; \
393 typedef const value_type* const_iterator; \
394 typedef value_type& reference; \
395 typedef const value_type& const_reference; \
396 typedef base::difference_type difference_type; \
397 typedef base::size_type size_type; \
399 class reverse_iterator \
401 typedef T value_type; \
402 typedef value_type& reference; \
403 typedef value_type* pointer; \
404 typedef reverse_iterator itor; \
405 friend inline itor operator+(int o, const itor& it) \
406 { return it.m_ptr - o; } \
407 friend inline itor operator+(const itor& it, int o) \
408 { return it.m_ptr - o; } \
409 friend inline itor operator-(const itor& it, int o) \
410 { return it.m_ptr + o; } \
411 friend inline difference_type operator-(const itor& i1, \
413 { return i1.m_ptr - i2.m_ptr; } \
417 reverse_iterator() : m_ptr(NULL) { } \
418 reverse_iterator(pointer ptr) : m_ptr(ptr) { } \
419 reverse_iterator(const itor& it) : m_ptr(it.m_ptr) { } \
420 reference operator*() const { return *m_ptr; } \
422 itor& operator++() { --m_ptr; return *this; } \
423 const itor operator++(int) \
424 { reverse_iterator tmp = *this; --m_ptr; return tmp; } \
425 itor& operator--() { ++m_ptr; return *this; } \
426 const itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; }\
427 bool operator ==(const itor& it) const { return m_ptr == it.m_ptr; }\
428 bool operator !=(const itor& it) const { return m_ptr != it.m_ptr; }\
431 class const_reverse_iterator \
433 typedef T value_type; \
434 typedef const value_type& reference; \
435 typedef const value_type* pointer; \
436 typedef const_reverse_iterator itor; \
437 friend inline itor operator+(int o, const itor& it) \
438 { return it.m_ptr - o; } \
439 friend inline itor operator+(const itor& it, int o) \
440 { return it.m_ptr - o; } \
441 friend inline itor operator-(const itor& it, int o) \
442 { return it.m_ptr + o; } \
443 friend inline difference_type operator-(const itor& i1, \
445 { return i1.m_ptr - i2.m_ptr; } \
449 const_reverse_iterator() : m_ptr(NULL) { } \
450 const_reverse_iterator(pointer ptr) : m_ptr(ptr) { } \
451 const_reverse_iterator(const itor& it) : m_ptr(it.m_ptr) { } \
452 const_reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }\
453 reference operator*() const { return *m_ptr; } \
455 itor& operator++() { --m_ptr; return *this; } \
456 const itor operator++(int) \
457 { itor tmp = *this; --m_ptr; return tmp; } \
458 itor& operator--() { ++m_ptr; return *this; } \
459 const itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; }\
460 bool operator ==(const itor& it) const { return m_ptr == it.m_ptr; }\
461 bool operator !=(const itor& it) const { return m_ptr != it.m_ptr; }\
464 name(size_type n) { assign(n, value_type()); } \
465 name(size_type n, const_reference v) { assign(n, v); } \
466 name(const_iterator first, const_iterator last) \
467 { assign(first, last); } \
468 void assign(const_iterator first, const_iterator last) \
469 { base::assign((bconst_iterator)first, (bconst_iterator)last); } \
470 void assign(size_type n, const_reference v) \
471 { base::assign(n, (bconst_reference)v); } \
472 reference back() { return *(end() - 1); } \
473 const_reference back() const { return *(end() - 1); } \
474 iterator begin() { return (iterator)base::begin(); } \
475 const_iterator begin() const { return (const_iterator)base::begin(); }\
476 size_type capacity() const { return base::capacity(); } \
477 iterator end() { return (iterator)base::end(); } \
478 const_iterator end() const { return (const_iterator)base::end(); } \
479 iterator erase(iterator first, iterator last) \
480 { return (iterator)base::erase((biterator)first, (biterator)last); }\
481 iterator erase(iterator it) \
482 { return (iterator)base::erase((biterator)it); } \
483 reference front() { return *begin(); } \
484 const_reference front() const { return *begin(); } \
485 void insert(iterator it, size_type n, const_reference v) \
486 { base::insert((biterator)it, n, (bconst_reference)v); } \
487 iterator insert(iterator it, const_reference v = value_type()) \
488 { return (iterator)base::insert((biterator)it, (bconst_reference)v); }\
489 void insert(iterator it, const_iterator first, const_iterator last) \
490 { base::insert((biterator)it, (bconst_iterator)first, \
491 (bconst_iterator)last); } \
492 void pop_back() { base::pop_back(); } \
493 void push_back(const_reference v) \
494 { base::push_back((bconst_reference)v); } \
495 reverse_iterator rbegin() { return reverse_iterator(end() - 1); } \
496 const_reverse_iterator rbegin() const; \
497 reverse_iterator rend() { return reverse_iterator(begin() - 1); } \
498 const_reverse_iterator rend() const; \
499 void reserve(size_type n) { base::reserve(n); } \
500 void resize(size_type n, value_type v = value_type()) \
501 { base::resize(n, v); } \
502 void swap(name& other) { base::swap(other); } \
505 #define _WX_PTROP pointer operator->() const { return m_ptr; }
506 #define _WX_PTROP_NONE
508 #define _WX_DEFINE_TYPEARRAY(T, name, base, classexp) \
509 _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, _WX_PTROP)
510 #define _WX_DEFINE_TYPEARRAY_PTR(T, name, base, classexp) \
511 _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, _WX_PTROP_NONE)
513 #endif // !wxUSE_STD_CONTAINERS
515 // ----------------------------------------------------------------------------
516 // _WX_DEFINE_SORTED_TYPEARRAY: sorted array for simple data types
517 // cannot handle types with size greater than pointer because of sorting
518 // ----------------------------------------------------------------------------
520 #define _WX_DEFINE_SORTED_TYPEARRAY_2(T, name, base, defcomp, classexp, comptype)\
521 wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(base::base_type), \
522 TypeTooBigToBeStoredInSorted##base, \
524 classexp name : public base \
526 typedef comptype SCMPFUNC; \
528 name(comptype fn defcomp) { m_fnCompare = fn; } \
530 name& operator=(const name& src) \
531 { base* temp = (base*) this; \
532 (*temp) = ((const base&)src); \
533 m_fnCompare = src.m_fnCompare; \
536 T& operator[](size_t uiIndex) const \
537 { return (T&)(base::operator[](uiIndex)); } \
538 T& Item(size_t uiIndex) const \
539 { return (T&)(base::operator[](uiIndex)); } \
541 { return (T&)(base::operator[](size() - 1)); } \
543 int Index(T lItem) const \
544 { return base::Index(lItem, (CMPFUNC)m_fnCompare); } \
546 size_t IndexForInsert(T lItem) const \
547 { return base::IndexForInsert(lItem, (CMPFUNC)m_fnCompare); } \
549 void AddAt(T item, size_t index) \
550 { base::insert(begin() + index, item); } \
552 size_t Add(T lItem) \
553 { return base::Add(lItem, (CMPFUNC)m_fnCompare); } \
554 void push_back(T lItem) \
557 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
558 { base::erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \
559 void Remove(T lItem) \
560 { int iIndex = Index(lItem); \
561 wxCHECK_RET( iIndex != wxNOT_FOUND, _WX_ERROR_REMOVE ); \
562 base::erase(begin() + iIndex); } \
565 comptype m_fnCompare; \
569 // ----------------------------------------------------------------------------
570 // _WX_DECLARE_OBJARRAY: an array for pointers to type T with owning semantics
571 // ----------------------------------------------------------------------------
573 #define _WX_DECLARE_OBJARRAY(T, name, base, classexp) \
574 typedef int (CMPFUNC_CONV *CMPFUNC##T)(T **pItem1, T **pItem2); \
575 classexp name : protected base \
577 typedef int (CMPFUNC_CONV *CMPFUNC##base)(void **pItem1, void **pItem2); \
578 typedef base base_array; \
581 name(const name& src); \
582 name& operator=(const name& src); \
586 void Alloc(size_t count) { base::reserve(count); } \
587 void reserve(size_t count) { base::reserve(count); } \
588 size_t GetCount() const { return base_array::size(); } \
589 size_t size() const { return base_array::size(); } \
590 bool IsEmpty() const { return base_array::empty(); } \
591 bool empty() const { return base_array::empty(); } \
592 size_t Count() const { return base_array::size(); } \
593 void Shrink() { base::Shrink(); } \
595 T& operator[](size_t uiIndex) const \
596 { return *(T*)base::operator[](uiIndex); } \
597 T& Item(size_t uiIndex) const \
598 { return *(T*)base::operator[](uiIndex); } \
600 { return *(T*)(base::operator[](size() - 1)); } \
602 int Index(const T& lItem, bool bFromEnd = false) const; \
604 void Add(const T& lItem, size_t nInsert = 1); \
605 void Add(const T* pItem) \
606 { base::push_back((T*)pItem); } \
607 void push_back(const T* pItem) \
608 { base::push_back((T*)pItem); } \
609 void push_back(const T& lItem) \
612 void Insert(const T& lItem, size_t uiIndex, size_t nInsert = 1); \
613 void Insert(const T* pItem, size_t uiIndex) \
614 { base::insert(begin() + uiIndex, (T*)pItem); } \
616 void Empty() { DoEmpty(); base::clear(); } \
617 void Clear() { DoEmpty(); base::clear(); } \
619 T* Detach(size_t uiIndex) \
620 { T* p = (T*)base::operator[](uiIndex); \
621 base::erase(begin() + uiIndex); return p; } \
622 void RemoveAt(size_t uiIndex, size_t nRemove = 1); \
624 void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC##base)fCmp); } \
628 void DoCopy(const name& src); \
631 // ============================================================================
632 // The public macros for declaration and definition of the dynamic arrays
633 // ============================================================================
635 // Please note that for each macro WX_FOO_ARRAY we also have
636 // WX_FOO_EXPORTED_ARRAY and WX_FOO_USER_EXPORTED_ARRAY which are exactly the
637 // same except that they use an additional __declspec(dllexport) or equivalent
638 // under Windows if needed.
640 // The first (just EXPORTED) macros do it if wxWidgets was compiled as a DLL
641 // and so must be used used inside the library. The second kind (USER_EXPORTED)
642 // allow the user code to do it when it wants. This is needed if you have a dll
643 // that wants to export a wxArray daubed with your own import/export goo.
645 // Finally, you can define the macro below as something special to modify the
646 // arrays defined by a simple WX_FOO_ARRAY as well. By default is empty.
647 #define wxARRAY_DEFAULT_EXPORT
649 // ----------------------------------------------------------------------------
650 // WX_DECLARE_BASEARRAY(T, name) declare an array class named "name" containing
651 // the elements of type T
652 // ----------------------------------------------------------------------------
654 #define WX_DECLARE_BASEARRAY(T, name) \
655 WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
657 #define WX_DECLARE_EXPORTED_BASEARRAY(T, name) \
658 WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, WXDLLIMPEXP_CORE)
660 #define WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, expmode) \
661 typedef T _wxArray##name; \
662 _WX_DECLARE_BASEARRAY(_wxArray##name, name, class expmode)
664 // ----------------------------------------------------------------------------
665 // WX_DEFINE_TYPEARRAY(T, name, base) define an array class named "name" deriving
666 // from class "base" containing the elements of type T
668 // Note that the class defined has only inline function and doesn't take any
669 // space at all so there is no size penalty for defining multiple array classes
670 // ----------------------------------------------------------------------------
672 #define WX_DEFINE_TYPEARRAY(T, name, base) \
673 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class wxARRAY_DEFAULT_EXPORT)
675 #define WX_DEFINE_TYPEARRAY_PTR(T, name, base) \
676 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class wxARRAY_DEFAULT_EXPORT)
678 #define WX_DEFINE_EXPORTED_TYPEARRAY(T, name, base) \
679 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class WXDLLIMPEXP_CORE)
681 #define WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, base) \
682 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class WXDLLIMPEXP_CORE)
684 #define WX_DEFINE_USER_EXPORTED_TYPEARRAY(T, name, base, expdecl) \
685 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class expdecl)
687 #define WX_DEFINE_USER_EXPORTED_TYPEARRAY_PTR(T, name, base, expdecl) \
688 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class expdecl)
690 #define WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, classdecl) \
691 typedef T _wxArray##name; \
692 _WX_DEFINE_TYPEARRAY(_wxArray##name, name, base, classdecl)
694 #define WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, classdecl) \
695 typedef T _wxArray##name; \
696 _WX_DEFINE_TYPEARRAY_PTR(_wxArray##name, name, base, classdecl)
698 // ----------------------------------------------------------------------------
699 // WX_DEFINE_SORTED_TYPEARRAY: this is the same as the previous macro, but it
700 // defines a sorted array.
703 // 1) it must be given a COMPARE function in ctor which takes 2 items of type
704 // T* and should return -1, 0 or +1 if the first one is less/greater
705 // than/equal to the second one.
706 // 2) the Add() method inserts the item in such was that the array is always
707 // sorted (it uses the COMPARE function)
708 // 3) it has no Sort() method because it's always sorted
709 // 4) Index() method is much faster (the sorted arrays use binary search
710 // instead of linear one), but Add() is slower.
711 // 5) there is no Insert() method because you can't insert an item into the
712 // given position in a sorted array but there is IndexForInsert()/AddAt()
713 // pair which may be used to optimize a common operation of "insert only if
716 // Note that you have to specify the comparison function when creating the
717 // objects of this array type. If, as in 99% of cases, the comparison function
718 // is the same for all objects of a class, WX_DEFINE_SORTED_TYPEARRAY_CMP below
719 // is more convenient.
721 // Summary: use this class when the speed of Index() function is important, use
722 // the normal arrays otherwise.
723 // ----------------------------------------------------------------------------
725 // we need a macro which expands to nothing to pass correct number of
726 // parameters to a nested macro invocation even when we don't have anything to
728 #define wxARRAY_EMPTY
730 #define WX_DEFINE_SORTED_TYPEARRAY(T, name, base) \
731 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, \
732 wxARRAY_DEFAULT_EXPORT)
734 #define WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, base) \
735 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, WXDLLIMPEXP_CORE)
737 #define WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, expmode) \
738 typedef T _wxArray##name; \
739 typedef int (CMPFUNC_CONV *SCMPFUNC##name)(T pItem1, T pItem2); \
740 _WX_DEFINE_SORTED_TYPEARRAY_2(_wxArray##name, name, base, \
741 wxARRAY_EMPTY, class expmode, SCMPFUNC##name)
743 // ----------------------------------------------------------------------------
744 // WX_DEFINE_SORTED_TYPEARRAY_CMP: exactly the same as above but the comparison
745 // function is provided by this macro and the objects of this class have a
746 // default constructor which just uses it.
748 // The arguments are: the element type, the comparison function and the array
751 // NB: this is, of course, how WX_DEFINE_SORTED_TYPEARRAY() should have worked
752 // from the very beginning - unfortunately I didn't think about this earlier
753 // ----------------------------------------------------------------------------
755 #define WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, base) \
756 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
757 wxARRAY_DEFAULT_EXPORT)
759 #define WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base) \
760 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
763 #define WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
765 typedef T _wxArray##name; \
766 typedef int (CMPFUNC_CONV *SCMPFUNC##name)(T pItem1, T pItem2); \
767 _WX_DEFINE_SORTED_TYPEARRAY_2(_wxArray##name, name, base, = cmpfunc, \
768 class expmode, SCMPFUNC##name)
770 // ----------------------------------------------------------------------------
771 // WX_DECLARE_OBJARRAY(T, name): this macro generates a new array class
772 // named "name" which owns the objects of type T it contains, i.e. it will
773 // delete them when it is destroyed.
775 // An element is of type T*, but arguments of type T& are taken (see below!)
776 // and T& is returned.
778 // Don't use this for simple types such as "int" or "long"!
780 // Note on Add/Insert functions:
781 // 1) function(T*) gives the object to the array, i.e. it will delete the
782 // object when it's removed or in the array's dtor
783 // 2) function(T&) will create a copy of the object and work with it
786 // 1) Remove() will delete the object after removing it from the array
787 // 2) Detach() just removes the object from the array (returning pointer to it)
789 // NB1: Base type T should have an accessible copy ctor if Add(T&) is used
790 // NB2: Never ever cast a array to it's base type: as dtor is not virtual
791 // and so you risk having at least the memory leaks and probably worse
793 // Some functions of this class are not inline, so it takes some space to
794 // define new class from this template even if you don't use it - which is not
795 // the case for the simple (non-object) array classes
797 // To use an objarray class you must
798 // #include "dynarray.h"
799 // WX_DECLARE_OBJARRAY(element_type, list_class_name)
800 // #include "arrimpl.cpp"
801 // WX_DEFINE_OBJARRAY(list_class_name) // name must be the same as above!
803 // This is necessary because at the moment of DEFINE_OBJARRAY class parsing the
804 // element_type must be fully defined (i.e. forward declaration is not
805 // enough), while WX_DECLARE_OBJARRAY may be done anywhere. The separation of
806 // two allows to break cicrcular dependencies with classes which have member
807 // variables of objarray type.
808 // ----------------------------------------------------------------------------
810 #define WX_DECLARE_OBJARRAY(T, name) \
811 WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
813 #define WX_DECLARE_EXPORTED_OBJARRAY(T, name) \
814 WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, WXDLLIMPEXP_CORE)
816 #define WX_DECLARE_OBJARRAY_WITH_DECL(T, name, decl) \
817 typedef T _wxObjArray##name; \
818 _WX_DECLARE_OBJARRAY(_wxObjArray##name, name, wxArrayPtrVoid, decl)
820 #define WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, expmode) \
821 WX_DECLARE_OBJARRAY_WITH_DECL(T, name, class expmode)
823 // WX_DEFINE_OBJARRAY is going to be redefined when arrimpl.cpp is included,
824 // try to provoke a human-understandable error if it used incorrectly.
826 // there is no real need for 3 different macros in the DEFINE case but do it
827 // anyhow for consistency
828 #define WX_DEFINE_OBJARRAY(name) DidYouIncludeArrimplCpp
829 #define WX_DEFINE_EXPORTED_OBJARRAY(name) WX_DEFINE_OBJARRAY(name)
830 #define WX_DEFINE_USER_EXPORTED_OBJARRAY(name) WX_DEFINE_OBJARRAY(name)
832 // ----------------------------------------------------------------------------
833 // Some commonly used predefined base arrays
834 // ----------------------------------------------------------------------------
836 WX_DECLARE_USER_EXPORTED_BASEARRAY(const void *, wxBaseArrayPtrVoid
,
838 WX_DECLARE_USER_EXPORTED_BASEARRAY(char, wxBaseArrayChar
, WXDLLIMPEXP_BASE
);
839 WX_DECLARE_USER_EXPORTED_BASEARRAY(short, wxBaseArrayShort
, WXDLLIMPEXP_BASE
);
840 WX_DECLARE_USER_EXPORTED_BASEARRAY(int, wxBaseArrayInt
, WXDLLIMPEXP_BASE
);
841 WX_DECLARE_USER_EXPORTED_BASEARRAY(long, wxBaseArrayLong
, WXDLLIMPEXP_BASE
);
842 WX_DECLARE_USER_EXPORTED_BASEARRAY(size_t, wxBaseArraySizeT
, WXDLLIMPEXP_BASE
);
843 WX_DECLARE_USER_EXPORTED_BASEARRAY(double, wxBaseArrayDouble
, WXDLLIMPEXP_BASE
);
845 // ----------------------------------------------------------------------------
846 // Convenience macros to define arrays from base arrays
847 // ----------------------------------------------------------------------------
849 #define WX_DEFINE_ARRAY(T, name) \
850 WX_DEFINE_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
851 #define WX_DEFINE_ARRAY_PTR(T, name) \
852 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
853 #define WX_DEFINE_EXPORTED_ARRAY(T, name) \
854 WX_DEFINE_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
855 #define WX_DEFINE_EXPORTED_ARRAY_PTR(T, name) \
856 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
857 #define WX_DEFINE_ARRAY_WITH_DECL_PTR(T, name, decl) \
858 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, decl)
859 #define WX_DEFINE_USER_EXPORTED_ARRAY(T, name, expmode) \
860 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, wxBaseArrayPtrVoid, wxARRAY_EMPTY expmode)
861 #define WX_DEFINE_USER_EXPORTED_ARRAY_PTR(T, name, expmode) \
862 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, wxARRAY_EMPTY expmode)
864 #define WX_DEFINE_ARRAY_CHAR(T, name) \
865 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayChar)
866 #define WX_DEFINE_EXPORTED_ARRAY_CHAR(T, name) \
867 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayChar)
868 #define WX_DEFINE_USER_EXPORTED_ARRAY_CHAR(T, name, expmode) \
869 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayChar, wxARRAY_EMPTY expmode)
871 #define WX_DEFINE_ARRAY_SHORT(T, name) \
872 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
873 #define WX_DEFINE_EXPORTED_ARRAY_SHORT(T, name) \
874 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
875 #define WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
876 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayShort, wxARRAY_EMPTY expmode)
878 #define WX_DEFINE_ARRAY_INT(T, name) \
879 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
880 #define WX_DEFINE_EXPORTED_ARRAY_INT(T, name) \
881 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
882 #define WX_DEFINE_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
883 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayInt, wxARRAY_EMPTY expmode)
885 #define WX_DEFINE_ARRAY_LONG(T, name) \
886 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
887 #define WX_DEFINE_EXPORTED_ARRAY_LONG(T, name) \
888 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
889 #define WX_DEFINE_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
890 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayLong, wxARRAY_EMPTY expmode)
892 #define WX_DEFINE_ARRAY_SIZE_T(T, name) \
893 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
894 #define WX_DEFINE_EXPORTED_ARRAY_SIZE_T(T, name) \
895 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
896 #define WX_DEFINE_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
897 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArraySizeT, wxARRAY_EMPTY expmode)
899 #define WX_DEFINE_ARRAY_DOUBLE(T, name) \
900 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
901 #define WX_DEFINE_EXPORTED_ARRAY_DOUBLE(T, name) \
902 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
903 #define WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(T, name, expmode) \
904 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayDouble, wxARRAY_EMPTY expmode)
906 // ----------------------------------------------------------------------------
907 // Convenience macros to define sorted arrays from base arrays
908 // ----------------------------------------------------------------------------
910 #define WX_DEFINE_SORTED_ARRAY(T, name) \
911 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
912 #define WX_DEFINE_SORTED_EXPORTED_ARRAY(T, name) \
913 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
914 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, expmode) \
915 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid, wxARRAY_EMPTY expmode)
917 #define WX_DEFINE_SORTED_ARRAY_CHAR(T, name) \
918 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayChar)
919 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CHAR(T, name) \
920 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayChar)
921 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CHAR(T, name, expmode) \
922 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayChar, wxARRAY_EMPTY expmode)
924 #define WX_DEFINE_SORTED_ARRAY_SHORT(T, name) \
925 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayShort)
926 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_SHORT(T, name) \
927 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort)
928 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
929 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort, wxARRAY_EMPTY expmode)
931 #define WX_DEFINE_SORTED_ARRAY_INT(T, name) \
932 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayInt)
933 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_INT(T, name) \
934 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt)
935 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
936 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt, expmode)
938 #define WX_DEFINE_SORTED_ARRAY_LONG(T, name) \
939 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayLong)
940 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(T, name) \
941 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong)
942 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
943 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong, expmode)
945 #define WX_DEFINE_SORTED_ARRAY_SIZE_T(T, name) \
946 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
947 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(T, name) \
948 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
949 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
950 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT, wxARRAY_EMPTY expmode)
952 // ----------------------------------------------------------------------------
953 // Convenience macros to define sorted arrays from base arrays
954 // ----------------------------------------------------------------------------
956 #define WX_DEFINE_SORTED_ARRAY_CMP(T, cmpfunc, name) \
957 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
958 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP(T, cmpfunc, name) \
959 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
960 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP(T, cmpfunc, \
962 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
963 wxBaseArrayPtrVoid, \
964 wxARRAY_EMPTY expmode)
966 #define WX_DEFINE_SORTED_ARRAY_CMP_CHAR(T, cmpfunc, name) \
967 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayChar)
968 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_CHAR(T, cmpfunc, name) \
969 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayChar)
970 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_CHAR(T, cmpfunc, \
972 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
974 wxARRAY_EMPTY expmode)
976 #define WX_DEFINE_SORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
977 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
978 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
979 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
980 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, \
982 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
984 wxARRAY_EMPTY expmode)
986 #define WX_DEFINE_SORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
987 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
988 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
989 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
990 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, \
992 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
994 wxARRAY_EMPTY expmode)
996 #define WX_DEFINE_SORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
997 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
998 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
999 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
1000 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, \
1002 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
1004 wxARRAY_EMPTY expmode)
1006 #define WX_DEFINE_SORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
1007 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
1008 #define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
1009 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
1010 #define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, \
1012 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
1014 wxARRAY_EMPTY expmode)
1016 // ----------------------------------------------------------------------------
1017 // Some commonly used predefined arrays
1018 // ----------------------------------------------------------------------------
1020 WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(short, wxArrayShort
, class WXDLLIMPEXP_BASE
);
1021 WX_DEFINE_USER_EXPORTED_ARRAY_INT(int, wxArrayInt
, class WXDLLIMPEXP_BASE
);
1022 WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(double, wxArrayDouble
, class WXDLLIMPEXP_BASE
);
1023 WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, wxArrayLong
, class WXDLLIMPEXP_BASE
);
1024 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid
, class WXDLLIMPEXP_BASE
);
1026 // -----------------------------------------------------------------------------
1027 // convenience macros
1028 // -----------------------------------------------------------------------------
1030 // prepend all element of one array to another one; e.g. if first array contains
1031 // elements X,Y,Z and the second contains A,B,C (in those orders), then the
1032 // first array will be result as A,B,C,X,Y,Z
1033 #define WX_PREPEND_ARRAY(array, other) \
1035 size_t wxAAcnt = (other).size(); \
1036 (array).reserve(wxAAcnt); \
1037 for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \
1039 (array).Insert((other)[wxAAn], wxAAn); \
1043 // append all element of one array to another one
1044 #define WX_APPEND_ARRAY(array, other) \
1046 size_t wxAAcnt = (other).size(); \
1047 (array).reserve(wxAAcnt); \
1048 for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \
1050 (array).push_back((other)[wxAAn]); \
1054 // delete all array elements
1056 // NB: the class declaration of the array elements must be visible from the
1057 // place where you use this macro, otherwise the proper destructor may not
1058 // be called (a decent compiler should give a warning about it, but don't
1060 #define WX_CLEAR_ARRAY(array) \
1062 size_t wxAAcnt = (array).size(); \
1063 for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \
1065 delete (array)[wxAAn]; \
1071 #endif // _DYNARRAY_H