]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/dynarray.h
Don't uninstall common files if there is more than one wxPython installed
[wxWidgets.git] / include / wx / dynarray.h
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: dynarray.h
3// Purpose: auto-resizable (i.e. dynamic) array support
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 12.09.97
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _DYNARRAY_H
13#define _DYNARRAY_H
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && \
16 !(defined(__MINGW32__) && __GNUC__ == 3 && __GNUC_MINOR__ == 2)
17#pragma interface "dynarray.h"
18#endif
19
20#include "wx/defs.h"
21
22#if wxUSE_STL
23 #include "wx/beforestd.h"
24 #include <vector>
25 #include <algorithm>
26 #include "wx/afterstd.h"
27#endif
28
29/*
30 This header defines the dynamic arrays and object arrays (i.e. arrays which
31 own their elements). Dynamic means that the arrays grow automatically as
32 needed.
33
34 These macros are ugly (especially if you look in the sources ;-), but they
35 allow us to define "template" classes without actually using templates and so
36 this works with all compilers (and may be also much faster to compile even
37 with a compiler which does support templates). The arrays defined with these
38 macros are type-safe.
39
40 Range checking is performed in debug build for both arrays and objarrays but
41 not in release build - so using an invalid index will just lead to a crash
42 then.
43
44 Note about memory usage: arrays never shrink automatically (although you may
45 use Shrink() function explicitly), they only grow, so loading 10 millions in
46 an array only to delete them 2 lines below might be a bad idea if the array
47 object is not going to be destroyed soon. However, as it does free memory
48 when destroyed, it is ok if the array is a local variable.
49 */
50
51// ----------------------------------------------------------------------------
52// constants
53// ----------------------------------------------------------------------------
54
55/*
56 The initial size by which an array grows when an element is added default
57 value avoids allocate one or two bytes when the array is created which is
58 rather inefficient
59*/
60#define WX_ARRAY_DEFAULT_INITIAL_SIZE (16)
61
62// ----------------------------------------------------------------------------
63// types
64// ----------------------------------------------------------------------------
65
66/*
67 Callback compare function for quick sort.
68
69 It must return negative value, 0 or positive value if the first item is
70 less than, equal to or greater than the second one.
71 */
72extern "C"
73{
74typedef int (wxCMPFUNC_CONV *CMPFUNC)(const void* pItem1, const void* pItem2);
75}
76
77// ----------------------------------------------------------------------------
78// Base class managing data having size of type 'long' (not used directly)
79//
80// NB: for efficiency this often used class has no virtual functions (hence no
81// virtual table), even dtor is *not* virtual. If used as expected it
82// won't create any problems because ARRAYs from DEFINE_ARRAY have no dtor
83// at all, so it's not too important if it's not called (this happens when
84// you cast "SomeArray *" as "BaseArray *" and then delete it)
85// ----------------------------------------------------------------------------
86
87#if wxUSE_STL
88
89template<class T>
90class WXDLLIMPEXP_BASE wxArray_SortFunction
91{
92public:
93 typedef int (wxCMPFUNC_CONV *CMPFUNC)(T* pItem1, T* pItem2);
94
95 wxArray_SortFunction(CMPFUNC f) : m_f(f) { }
96 bool operator()(const T& i1, const T& i2)
97 { return m_f((T*)&i1, (T*)&i2) < 0; }
98private:
99 CMPFUNC m_f;
100};
101
102template<class T, typename F>
103class WXDLLIMPEXP_BASE wxSortedArray_SortFunction
104{
105public:
106 typedef F CMPFUNC;
107
108 wxSortedArray_SortFunction(CMPFUNC f) : m_f(f) { }
109 bool operator()(const T& i1, const T& i2)
110 { return m_f(i1, i2) < 0; }
111private:
112 CMPFUNC m_f;
113};
114
115#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
116 typedef int (wxCMPFUNC_CONV *CMPFUN##name)(T pItem1, T pItem2); \
117 typedef wxSortedArray_SortFunction<T, CMPFUN##name> name##_Predicate; \
118 _WX_DECLARE_BASEARRAY_2(T, name, name##_Predicate, classexp)
119
120#define _WX_DECLARE_BASEARRAY_2(T, name, predicate, classexp) \
121classexp name : public std::vector<T> \
122{ \
123 typedef predicate Predicate; \
124 typedef predicate::CMPFUNC SCMPFUNC; \
125public: \
126 typedef wxArray_SortFunction<T>::CMPFUNC CMPFUNC; \
127public: \
128 void Empty() { clear(); } \
129 void Clear() { clear(); } \
130 void Alloc(size_t uiSize) { reserve(uiSize); } \
131 void Shrink(); \
132 \
133 size_t GetCount() const { return size(); } \
134 void SetCount(size_t n, T v = T()) { resize(n, v); } \
135 bool IsEmpty() const { return empty(); } \
136 size_t Count() const { return size(); } \
137 \
138 typedef T base_type; \
139 \
140protected: \
141 T& Item(size_t uiIndex) const \
142 { wxASSERT( uiIndex < size() ); return (T&)operator[](uiIndex); } \
143 \
144 int Index(T e, bool bFromEnd = false) const; \
145 int Index(T lItem, CMPFUNC fnCompare) const; \
146 size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const; \
147 void Add(T lItem, size_t nInsert = 1) \
148 { insert(end(), nInsert, lItem); } \
149 size_t Add(T lItem, CMPFUNC fnCompare); \
150 void Insert(T lItem, size_t uiIndex, size_t nInsert = 1) \
151 { insert(begin() + uiIndex, nInsert, lItem); } \
152 void Remove(T lItem); \
153 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
154 { erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \
155 \
156 void Sort(CMPFUNC fCmp) \
157 { \
158 wxArray_SortFunction<T> p(fCmp); \
159 std::sort(begin(), end(), p); \
160 } \
161}
162
163#else // if !wxUSE_STL
164
165#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
166classexp name \
167{ \
168 typedef CMPFUNC SCMPFUNC; /* for compatibility wuth wxUSE_STL */ \
169public: \
170 name(); \
171 name(const name& array); \
172 name& operator=(const name& src); \
173 ~name(); \
174 \
175 void Empty() { m_nCount = 0; } \
176 void Clear(); \
177 void Alloc(size_t uiSize); \
178 void Shrink(); \
179 \
180 size_t GetCount() const { return m_nCount; } \
181 void SetCount(size_t n, T defval = T()); \
182 bool IsEmpty() const { return m_nCount == 0; } \
183 size_t Count() const { return m_nCount; } \
184 \
185 typedef T base_type; \
186 \
187protected: \
188 T& Item(size_t uiIndex) const \
189 { wxASSERT( uiIndex < m_nCount ); return m_pItems[uiIndex]; } \
190 T& operator[](size_t uiIndex) const { return Item(uiIndex); } \
191 \
192 int Index(T lItem, bool bFromEnd = false) const; \
193 int Index(T lItem, CMPFUNC fnCompare) const; \
194 size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const; \
195 void Add(T lItem, size_t nInsert = 1); \
196 size_t Add(T lItem, CMPFUNC fnCompare); \
197 void Insert(T lItem, size_t uiIndex, size_t nInsert = 1); \
198 void Remove(T lItem); \
199 void RemoveAt(size_t uiIndex, size_t nRemove = 1); \
200 \
201 void Sort(CMPFUNC fnCompare); \
202 \
203 /* *minimal* STL-ish interface, for derived classes */ \
204 typedef T value_type; \
205 typedef value_type* iterator; \
206 typedef const value_type* const_iterator; \
207 typedef value_type& reference; \
208 typedef const value_type& const_reference; \
209 typedef int difference_type; \
210 typedef size_t size_type; \
211 \
212 void assign(const_iterator first, const_iterator last); \
213 void assign(size_type n, const_reference v); \
214 size_type capacity() const { return m_nSize; } \
215 iterator erase(iterator first, iterator last) \
216 { \
217 size_type idx = first - begin(); \
218 RemoveAt(idx, last - first); \
219 return begin() + idx; \
220 } \
221 iterator erase(iterator it) { return erase(it, it + 1); } \
222 void insert(iterator it, size_type n, const value_type& v) \
223 { Insert(v, it - begin(), n); } \
224 iterator insert(iterator it, const value_type& v = value_type()) \
225 { \
226 size_type idx = it - begin(); \
227 Insert(v, idx); \
228 return begin() + idx; \
229 } \
230 void insert(iterator it, const_iterator first, const_iterator last);\
231 void pop_back() { RemoveAt(size() - 1); } \
232 void push_back(const value_type& v) { Add(v); } \
233 void reserve(size_type n) { if(n > m_nSize) Realloc(n); } \
234 void resize(size_type n, value_type v = value_type()); \
235 \
236 iterator begin() { return m_pItems; } \
237 iterator end() { return m_pItems + m_nCount; } \
238 const_iterator begin() const { return m_pItems; } \
239 const_iterator end() const { return m_pItems + m_nCount; } \
240 \
241 /* the following functions may be made directly public because */ \
242 /* they don't use the type of the elements at all */ \
243public: \
244 void clear() { Clear(); } \
245 bool empty() const { return IsEmpty(); } \
246 size_type max_size() const { return INT_MAX; } \
247 size_type size() const { return GetCount(); } \
248 \
249private: \
250 void Grow(size_t nIncrement = 0); \
251 bool Realloc(size_t nSize); \
252 \
253 size_t m_nSize, \
254 m_nCount; \
255 \
256 T *m_pItems; \
257}
258
259#endif // !wxUSE_STL
260
261// ============================================================================
262// The private helper macros containing the core of the array classes
263// ============================================================================
264
265// Implementation notes:
266//
267// JACS: Salford C++ doesn't like 'var->operator=' syntax, as in:
268// { ((wxBaseArray *)this)->operator=((const wxBaseArray&)src);
269// so using a temporary variable instead.
270//
271// The classes need a (even trivial) ~name() to link under Mac X
272//
273// _WX_ERROR_REMOVE is needed to resolve the name conflict between the wxT()
274// macro and T typedef: we can't use wxT() inside WX_DEFINE_ARRAY!
275
276#define _WX_ERROR_REMOVE wxT("removing inexisting element in wxArray::Remove")
277
278// ----------------------------------------------------------------------------
279// _WX_DEFINE_TYPEARRAY: array for simple types
280// ----------------------------------------------------------------------------
281
282#if wxUSE_STL
283
284#define _WX_DEFINE_TYPEARRAY(T, name, base, classexp) \
285typedef int (CMPFUNC_CONV *CMPFUNC##T)(T *pItem1, T *pItem2); \
286classexp name : public base \
287{ \
288public: \
289 T& operator[](size_t uiIndex) const \
290 { return (T&)(base::operator[](uiIndex)); } \
291 T& Item(size_t uiIndex) const \
292 { return (T&)/*const cast*/base::operator[](uiIndex); } \
293 T& Last() const \
294 { return Item(Count() - 1); } \
295 \
296 int Index(T e, bool bFromEnd = false) const \
297 { return base::Index(e, bFromEnd); } \
298 \
299 void Add(T Item, size_t nInsert = 1) \
300 { insert(end(), nInsert, Item); } \
301 void Insert(T Item, size_t uiIndex, size_t nInsert = 1) \
302 { insert(begin() + uiIndex, nInsert, Item); } \
303 \
304 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
305 { base::RemoveAt(uiIndex, nRemove); } \
306 void Remove(T Item) \
307 { int iIndex = Index(Item); \
308 wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \
309 _WX_ERROR_REMOVE); \
310 RemoveAt((size_t)iIndex); } \
311 \
312 void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC)fCmp); } \
313}
314
315#define _WX_DEFINE_TYPEARRAY_PTR(T, name, base, classexp) \
316 _WX_DEFINE_TYPEARRAY(T, name, base, classexp)
317
318#else // if !wxUSE_STL
319
320// common declaration used by both _WX_DEFINE_TYPEARRAY and
321// _WX_DEFINE_TYPEARRAY_PTR
322#define _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, ptrop) \
323wxCOMPILE_TIME_ASSERT(sizeof(T) <= sizeof(base::base_type), \
324 TypeTooBigToBeStoredIn##base); \
325typedef int (CMPFUNC_CONV *CMPFUNC##T)(T *pItem1, T *pItem2); \
326classexp name : public base \
327{ \
328public: \
329 name() { } \
330 ~name() { } \
331 \
332 name& operator=(const name& src) \
333 { base* temp = (base*) this; \
334 (*temp) = ((const base&)src); \
335 return *this; } \
336 \
337 T& operator[](size_t uiIndex) const \
338 { return (T&)(base::operator[](uiIndex)); } \
339 T& Item(size_t uiIndex) const \
340 { return (T&)(base::operator[](uiIndex)); } \
341 T& Last() const \
342 { return (T&)(base::operator[](Count() - 1)); } \
343 \
344 int Index(T Item, bool bFromEnd = false) const \
345 { return base::Index((base_type)Item, bFromEnd); } \
346 \
347 void Add(T Item, size_t nInsert = 1) \
348 { base::Add((base_type)Item, nInsert); } \
349 void Insert(T Item, size_t uiIndex, size_t nInsert = 1) \
350 { base::Insert((base_type)Item, uiIndex, nInsert) ; } \
351 \
352 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
353 { base::RemoveAt(uiIndex, nRemove); } \
354 void Remove(T Item) \
355 { int iIndex = Index(Item); \
356 wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \
357 _WX_ERROR_REMOVE); \
358 base::RemoveAt((size_t)iIndex); } \
359 \
360 void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC)fCmp); } \
361 \
362 /* STL-like interface */ \
363private: \
364 typedef base::iterator biterator; \
365 typedef base::const_iterator bconst_iterator; \
366 typedef base::value_type bvalue_type; \
367 typedef base::const_reference bconst_reference; \
368public: \
369 typedef T value_type; \
370 typedef value_type* pointer; \
371 typedef const value_type* const_pointer; \
372 typedef value_type* iterator; \
373 typedef const value_type* const_iterator; \
374 typedef value_type& reference; \
375 typedef const value_type& const_reference; \
376 typedef base::difference_type difference_type; \
377 typedef base::size_type size_type; \
378 \
379 class reverse_iterator \
380 { \
381 typedef T value_type; \
382 typedef value_type& reference; \
383 typedef value_type* pointer; \
384 typedef reverse_iterator itor; \
385 friend inline itor operator+(int o, const itor& it) \
386 { return it.m_ptr - o; } \
387 friend inline itor operator+(const itor& it, int o) \
388 { return it.m_ptr - o; } \
389 friend inline itor operator-(const itor& it, int o) \
390 { return it.m_ptr + o; } \
391 friend inline difference_type operator-(const itor& i1, \
392 const itor& i2) \
393 { return i1.m_ptr - i2.m_ptr; } \
394 \
395 public: \
396 pointer m_ptr; \
397 reverse_iterator() : m_ptr(NULL) { } \
398 reverse_iterator(pointer ptr) : m_ptr(ptr) { } \
399 reverse_iterator(const itor& it) : m_ptr(it.m_ptr) { } \
400 reference operator*() const { return *m_ptr; } \
401 ptrop \
402 itor operator++() { --m_ptr; return *this; } \
403 itor operator++(int) \
404 { reverse_iterator tmp = *this; --m_ptr; return tmp; } \
405 itor operator--() { ++m_ptr; return *this; } \
406 itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; } \
407 bool operator ==(const itor& it) { return m_ptr == it.m_ptr; } \
408 bool operator !=(const itor& it) { return m_ptr != it.m_ptr; } \
409 }; \
410 \
411 class const_reverse_iterator \
412 { \
413 typedef T value_type; \
414 typedef const value_type& reference; \
415 typedef const value_type* pointer; \
416 typedef const_reverse_iterator itor; \
417 friend inline itor operator+(int o, const itor& it) \
418 { return it.m_ptr - o; } \
419 friend inline itor operator+(const itor& it, int o) \
420 { return it.m_ptr - o; } \
421 friend inline itor operator-(const itor& it, int o) \
422 { return it.m_ptr + o; } \
423 friend inline difference_type operator-(const itor& i1, \
424 const itor& i2) \
425 { return i1.m_ptr - i2.m_ptr; } \
426 \
427 public: \
428 pointer m_ptr; \
429 const_reverse_iterator() : m_ptr(NULL) { } \
430 const_reverse_iterator(pointer ptr) : m_ptr(ptr) { } \
431 const_reverse_iterator(const itor& it) : m_ptr(it.m_ptr) { } \
432 const_reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }\
433 reference operator*() const { return *m_ptr; } \
434 ptrop \
435 itor operator++() { --m_ptr; return *this; } \
436 itor operator++(int) \
437 { itor tmp = *this; --m_ptr; return tmp; } \
438 itor operator--() { ++m_ptr; return *this; } \
439 itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; } \
440 bool operator ==(const itor& it) { return m_ptr == it.m_ptr; } \
441 bool operator !=(const itor& it) { return m_ptr != it.m_ptr; } \
442 }; \
443 \
444 name(size_type n, const_reference v) { assign(n, v); } \
445 name(const_iterator first, const_iterator last) \
446 { assign(first, last); } \
447 void assign(const_iterator first, const_iterator last) \
448 { base::assign((bconst_iterator)first, (bconst_iterator)last); } \
449 void assign(size_type n, const_reference v) \
450 { base::assign(n, (bconst_reference)v); } \
451 reference back() { return *(end() - 1); } \
452 const_reference back() const { return *(end() - 1); } \
453 iterator begin() { return (iterator)base::begin(); } \
454 const_iterator begin() const { return (const_iterator)base::begin(); }\
455 size_type capacity() const { return base::capacity(); } \
456 iterator end() { return (iterator)base::end(); } \
457 const_iterator end() const { return (const_iterator)base::end(); } \
458 iterator erase(iterator first, iterator last) \
459 { return (iterator)base::erase((biterator)first, (biterator)last); }\
460 iterator erase(iterator it) \
461 { return (iterator)base::erase((biterator)it); } \
462 reference front() { return *begin(); } \
463 const_reference front() const { return *begin(); } \
464 void insert(iterator it, size_type n, const_reference v) \
465 { base::insert((biterator)it, n, (bconst_reference)v); } \
466 iterator insert(iterator it, const_reference v = value_type()) \
467 { return (iterator)base::insert((biterator)it, (bconst_reference)v); }\
468 void insert(iterator it, const_iterator first, const_iterator last) \
469 { base::insert((biterator)it, (bconst_iterator)first, \
470 (bconst_iterator)last); } \
471 void pop_back() { base::pop_back(); } \
472 void push_back(const_reference v) \
473 { base::push_back((bconst_reference)v); } \
474 reverse_iterator rbegin() { return reverse_iterator(end() - 1); } \
475 const_reverse_iterator rbegin() const; \
476 reverse_iterator rend() { return reverse_iterator(begin() - 1); } \
477 const_reverse_iterator rend() const; \
478 void reserve(size_type n) { base::reserve(n); }; \
479 void resize(size_type n, value_type v = value_type()); \
480}
481
482#define _WX_PTROP pointer operator->() const { return m_ptr; }
483#define _WX_PTROP_NONE
484
485#define _WX_DEFINE_TYPEARRAY(T, name, base, classexp) \
486 _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, _WX_PTROP)
487#define _WX_DEFINE_TYPEARRAY_PTR(T, name, base, classexp) \
488 _WX_DEFINE_TYPEARRAY_HELPER(T, name, base, classexp, _WX_PTROP_NONE)
489
490#endif // !wxUSE_STL
491
492// ----------------------------------------------------------------------------
493// _WX_DEFINE_SORTED_TYPEARRAY: sorted array for simple data types
494// cannot handle types with size greater than pointer because of sorting
495// ----------------------------------------------------------------------------
496
497#define _WX_DEFINE_SORTED_TYPEARRAY_2(T, name, base, defcomp, classexp, comptype)\
498wxCOMPILE_TIME_ASSERT(sizeof(T) <= sizeof(base::base_type), \
499 TypeTooBigToBeStoredInSorted##base); \
500classexp name : public base \
501{ \
502 typedef comptype SCMPFUNC; \
503public: \
504 name(comptype fn defcomp) { m_fnCompare = fn; } \
505 \
506 name& operator=(const name& src) \
507 { base* temp = (base*) this; \
508 (*temp) = ((const base&)src); \
509 m_fnCompare = src.m_fnCompare; \
510 return *this; } \
511 \
512 T& operator[](size_t uiIndex) const \
513 { return (T&)(base::operator[](uiIndex)); } \
514 T& Item(size_t uiIndex) const \
515 { return (T&)(base::operator[](uiIndex)); } \
516 T& Last() const \
517 { return (T&)(base::operator[](size() - 1)); } \
518 \
519 int Index(T Item) const \
520 { return base::Index(Item, (CMPFUNC)m_fnCompare); } \
521 \
522 size_t IndexForInsert(T Item) const \
523 { return base::IndexForInsert(Item, (CMPFUNC)m_fnCompare); } \
524 \
525 void AddAt(T item, size_t index) \
526 { base::insert(begin() + index, item); } \
527 \
528 size_t Add(T Item) \
529 { return base::Add(Item, (CMPFUNC)m_fnCompare); } \
530 \
531 void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
532 { base::erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \
533 void Remove(T Item) \
534 { int iIndex = Index(Item); \
535 wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \
536 _WX_ERROR_REMOVE ); \
537 base::erase(begin() + iIndex); } \
538 \
539private: \
540 comptype m_fnCompare; \
541}
542
543
544// ----------------------------------------------------------------------------
545// _WX_DECLARE_OBJARRAY: an array for pointers to type T with owning semantics
546// ----------------------------------------------------------------------------
547
548#define _WX_DECLARE_OBJARRAY(T, name, base, classexp) \
549typedef int (CMPFUNC_CONV *CMPFUNC##T)(T **pItem1, T **pItem2); \
550classexp name : protected base \
551{ \
552typedef int (CMPFUNC_CONV *CMPFUNC##base)(void **pItem1, void **pItem2); \
553typedef base base_array; \
554public: \
555 name() { } \
556 name(const name& src); \
557 name& operator=(const name& src); \
558 \
559 ~name(); \
560 \
561 void Alloc(size_t count) { reserve(count); } \
562 size_t GetCount() const { return base_array::size(); } \
563 size_t size() const { return base_array::size(); } \
564 bool IsEmpty() const { return base_array::empty(); } \
565 bool empty() const { return base_array::empty(); } \
566 size_t Count() const { return base_array::size(); } \
567 void Shrink() { base::Shrink(); } \
568 \
569 T& operator[](size_t uiIndex) const \
570 { return *(T*)base::operator[](uiIndex); } \
571 T& Item(size_t uiIndex) const \
572 { return *(T*)base::operator[](uiIndex); } \
573 T& Last() const \
574 { return *(T*)(base::operator[](size() - 1)); } \
575 \
576 int Index(const T& Item, bool bFromEnd = false) const; \
577 \
578 void Add(const T& Item, size_t nInsert = 1); \
579 void Add(const T* pItem) \
580 { base::push_back((T*)pItem); } \
581 void push_back(const T* pItem) \
582 { base::push_back((T*)pItem); } \
583 void push_back(const T& Item) \
584 { Add(Item); } \
585 \
586 void Insert(const T& Item, size_t uiIndex, size_t nInsert = 1); \
587 void Insert(const T* pItem, size_t uiIndex) \
588 { base::insert(begin() + uiIndex, (T*)pItem); } \
589 \
590 void Empty() { DoEmpty(); base::clear(); } \
591 void Clear() { DoEmpty(); base::clear(); } \
592 \
593 T* Detach(size_t uiIndex) \
594 { T* p = (T*)base::operator[](uiIndex); \
595 base::erase(begin() + uiIndex); return p; } \
596 void RemoveAt(size_t uiIndex, size_t nRemove = 1); \
597 \
598 void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC##base)fCmp); } \
599 \
600private: \
601 void DoEmpty(); \
602 void DoCopy(const name& src); \
603}
604
605// ============================================================================
606// The public macros for declaration and definition of the dynamic arrays
607// ============================================================================
608
609// Please note that for each macro WX_FOO_ARRAY we also have
610// WX_FOO_EXPORTED_ARRAY and WX_FOO_USER_EXPORTED_ARRAY which are exactly the
611// same except that they use an additional __declspec(dllexport) or equivalent
612// under Windows if needed.
613//
614// The first (just EXPORTED) macros do it if wxWidgets was compiled as a DLL
615// and so must be used used inside the library. The second kind (USER_EXPORTED)
616// allow the user code to do it when it wants. This is needed if you have a dll
617// that wants to export a wxArray daubed with your own import/export goo.
618//
619// Finally, you can define the macro below as something special to modify the
620// arrays defined by a simple WX_FOO_ARRAY as well. By default is is empty.
621#define wxARRAY_DEFAULT_EXPORT
622
623// ----------------------------------------------------------------------------
624// WX_DECLARE_BASEARRAY(T, name) declare an array class named "name" containing
625// the elements of type T
626// ----------------------------------------------------------------------------
627
628#define WX_DECLARE_BASEARRAY(T, name) \
629 WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
630
631#define WX_DECLARE_EXPORTED_BASEARRAY(T, name) \
632 WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, WXDLLEXPORT)
633
634#define WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, expmode) \
635 typedef T _wxArray##name; \
636 _WX_DECLARE_BASEARRAY(_wxArray##name, name, class expmode)
637
638// ----------------------------------------------------------------------------
639// WX_DEFINE_TYPEARRAY(T, name, base) define an array class named "name" deriving
640// from class "base" containing the elements of type T
641//
642// Note that the class defined has only inline function and doesn't take any
643// space at all so there is no size penalty for defining multiple array classes
644// ----------------------------------------------------------------------------
645
646#define WX_DEFINE_TYPEARRAY(T, name, base) \
647 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class wxARRAY_DEFAULT_EXPORT)
648
649#define WX_DEFINE_TYPEARRAY_PTR(T, name, base) \
650 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class wxARRAY_DEFAULT_EXPORT)
651
652#define WX_DEFINE_EXPORTED_TYPEARRAY(T, name, base) \
653 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class WXDLLEXPORT)
654
655#define WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, base) \
656 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class WXDLLEXPORT)
657
658#define WX_DEFINE_USER_EXPORTED_TYPEARRAY(T, name, base, expdecl) \
659 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, class expdecl)
660
661#define WX_DEFINE_USER_EXPORTED_TYPEARRAY_PTR(T, name, base, expdecl) \
662 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, class expdecl)
663
664#define WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, base, classdecl) \
665 typedef T _wxArray##name; \
666 _WX_DEFINE_TYPEARRAY(_wxArray##name, name, base, classdecl)
667
668#define WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, base, classdecl) \
669 typedef T _wxArray##name; \
670 _WX_DEFINE_TYPEARRAY_PTR(_wxArray##name, name, base, classdecl)
671
672// ----------------------------------------------------------------------------
673// WX_DEFINE_SORTED_TYPEARRAY: this is the same as the previous macro, but it
674// defines a sorted array.
675//
676// Differences:
677// 1) it must be given a COMPARE function in ctor which takes 2 items of type
678// T* and should return -1, 0 or +1 if the first one is less/greater
679// than/equal to the second one.
680// 2) the Add() method inserts the item in such was that the array is always
681// sorted (it uses the COMPARE function)
682// 3) it has no Sort() method because it's always sorted
683// 4) Index() method is much faster (the sorted arrays use binary search
684// instead of linear one), but Add() is slower.
685// 5) there is no Insert() method because you can't insert an item into the
686// given position in a sorted array but there is IndexForInsert()/AddAt()
687// pair which may be used to optimize a common operation of "insert only if
688// not found"
689//
690// Note that you have to specify the comparison function when creating the
691// objects of this array type. If, as in 99% of cases, the comparison function
692// is the same for all objects of a class, WX_DEFINE_SORTED_TYPEARRAY_CMP below
693// is more convenient.
694//
695// Summary: use this class when the speed of Index() function is important, use
696// the normal arrays otherwise.
697// ----------------------------------------------------------------------------
698
699#define wxARRAY_EMPTY_CMP
700
701#define WX_DEFINE_SORTED_TYPEARRAY(T, name, base) \
702 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, \
703 wxARRAY_DEFAULT_EXPORT)
704
705#define WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, base) \
706 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, WXDLLEXPORT)
707
708#define WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, base, expmode) \
709 typedef T _wxArray##name; \
710 typedef int (CMPFUNC_CONV *SCMPFUNC##name)(T pItem1, T pItem2); \
711 _WX_DEFINE_SORTED_TYPEARRAY_2(_wxArray##name, name, base, \
712 wxARRAY_EMPTY_CMP, class expmode, SCMPFUNC##name)
713
714// ----------------------------------------------------------------------------
715// WX_DEFINE_SORTED_TYPEARRAY_CMP: exactly the same as above but the comparison
716// function is provided by this macro and the objects of this class have a
717// default constructor which just uses it.
718//
719// The arguments are: the element type, the comparison function and the array
720// name
721//
722// NB: this is, of course, how WX_DEFINE_SORTED_TYPEARRAY() should have worked
723// from the very beginning - unfortunately I didn't think about this earlier
724// ----------------------------------------------------------------------------
725
726#define WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, base) \
727 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
728 wxARRAY_DEFAULT_EXPORT)
729
730#define WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base) \
731 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
732 WXDLLEXPORT)
733
734#define WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, base, \
735 expmode) \
736 typedef T _wxArray##name; \
737 typedef int (CMPFUNC_CONV *SCMPFUNC##name)(T pItem1, T pItem2); \
738 _WX_DEFINE_SORTED_TYPEARRAY_2(_wxArray##name, name, base, = cmpfunc, \
739 class expmode, SCMPFUNC##name)
740
741// ----------------------------------------------------------------------------
742// WX_DECLARE_OBJARRAY(T, name): this macro generates a new array class
743// named "name" which owns the objects of type T it contains, i.e. it will
744// delete them when it is destroyed.
745//
746// An element is of type T*, but arguments of type T& are taken (see below!)
747// and T& is returned.
748//
749// Don't use this for simple types such as "int" or "long"!
750//
751// Note on Add/Insert functions:
752// 1) function(T*) gives the object to the array, i.e. it will delete the
753// object when it's removed or in the array's dtor
754// 2) function(T&) will create a copy of the object and work with it
755//
756// Also:
757// 1) Remove() will delete the object after removing it from the array
758// 2) Detach() just removes the object from the array (returning pointer to it)
759//
760// NB1: Base type T should have an accessible copy ctor if Add(T&) is used
761// NB2: Never ever cast a array to it's base type: as dtor is not virtual
762// and so you risk having at least the memory leaks and probably worse
763//
764// Some functions of this class are not inline, so it takes some space to
765// define new class from this template even if you don't use it - which is not
766// the case for the simple (non-object) array classes
767//
768// To use an objarray class you must
769// #include "dynarray.h"
770// WX_DECLARE_OBJARRAY(element_type, list_class_name)
771// #include "arrimpl.cpp"
772// WX_DEFINE_OBJARRAY(list_class_name) // name must be the same as above!
773//
774// This is necessary because at the moment of DEFINE_OBJARRAY class parsing the
775// element_type must be fully defined (i.e. forward declaration is not
776// enough), while WX_DECLARE_OBJARRAY may be done anywhere. The separation of
777// two allows to break cicrcular dependencies with classes which have member
778// variables of objarray type.
779// ----------------------------------------------------------------------------
780
781#define WX_DECLARE_OBJARRAY(T, name) \
782 WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
783
784#define WX_DECLARE_EXPORTED_OBJARRAY(T, name) \
785 WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, WXDLLEXPORT)
786
787#define WX_DECLARE_OBJARRAY_WITH_DECL(T, name, decl) \
788 typedef T _wxObjArray##name; \
789 _WX_DECLARE_OBJARRAY(_wxObjArray##name, name, wxArrayPtrVoid, decl)
790
791#define WX_DECLARE_USER_EXPORTED_OBJARRAY(T, name, expmode) \
792 WX_DECLARE_OBJARRAY_WITH_DECL(T, name, class expmode)
793
794// WX_DEFINE_OBJARRAY is going to be redefined when arrimpl.cpp is included,
795// try to provoke a human-understandable error if it used incorrectly.
796//
797// there is no real need for 3 different macros in the DEFINE case but do it
798// anyhow for consistency
799#define WX_DEFINE_OBJARRAY(name) DidYouIncludeArrimplCpp
800#define WX_DEFINE_EXPORTED_OBJARRAY(name) WX_DEFINE_OBJARRAY(name)
801#define WX_DEFINE_USER_EXPORTED_OBJARRAY(name) WX_DEFINE_OBJARRAY(name)
802
803// ----------------------------------------------------------------------------
804// Some commonly used predefined base arrays
805// ----------------------------------------------------------------------------
806
807WX_DECLARE_USER_EXPORTED_BASEARRAY(const void *, wxBaseArrayPtrVoid,
808 WXDLLIMPEXP_BASE);
809WX_DECLARE_USER_EXPORTED_BASEARRAY(short, wxBaseArrayShort, WXDLLIMPEXP_BASE);
810WX_DECLARE_USER_EXPORTED_BASEARRAY(int, wxBaseArrayInt, WXDLLIMPEXP_BASE);
811WX_DECLARE_USER_EXPORTED_BASEARRAY(long, wxBaseArrayLong, WXDLLIMPEXP_BASE);
812WX_DECLARE_USER_EXPORTED_BASEARRAY(size_t, wxBaseArraySizeT, WXDLLIMPEXP_BASE);
813WX_DECLARE_USER_EXPORTED_BASEARRAY(double, wxBaseArrayDouble, WXDLLIMPEXP_BASE);
814
815// ----------------------------------------------------------------------------
816// Convenience macros to define arrays from base arrays
817// ----------------------------------------------------------------------------
818
819#define WX_DEFINE_ARRAY(T, name) \
820 WX_DEFINE_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
821#define WX_DEFINE_ARRAY_PTR(T, name) \
822 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
823#define WX_DEFINE_EXPORTED_ARRAY(T, name) \
824 WX_DEFINE_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
825#define WX_DEFINE_EXPORTED_ARRAY_PTR(T, name) \
826 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
827#define WX_DEFINE_ARRAY_WITH_DECL_PTR(T, name, decl) \
828 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, decl)
829#define WX_DEFINE_USER_EXPORTED_ARRAY(T, name, expmode) \
830 WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, wxBaseArrayPtrVoid, expmode)
831#define WX_DEFINE_USER_EXPORTED_ARRAY_PTR(T, name, expmode) \
832 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, expmode)
833
834#define WX_DEFINE_ARRAY_SHORT(T, name) \
835 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
836#define WX_DEFINE_EXPORTED_ARRAY_SHORT(T, name) \
837 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
838#define WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
839 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayShort, expmode)
840
841#define WX_DEFINE_ARRAY_INT(T, name) \
842 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
843#define WX_DEFINE_EXPORTED_ARRAY_INT(T, name) \
844 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
845#define WX_DEFINE_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
846 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayInt, expmode)
847
848#define WX_DEFINE_ARRAY_LONG(T, name) \
849 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
850#define WX_DEFINE_EXPORTED_ARRAY_LONG(T, name) \
851 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
852#define WX_DEFINE_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
853 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayLong, expmode)
854
855#define WX_DEFINE_ARRAY_SIZE_T(T, name) \
856 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
857#define WX_DEFINE_EXPORTED_ARRAY_SIZE_T(T, name) \
858 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
859#define WX_DEFINE_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
860 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArraySizeT, expmode)
861
862#define WX_DEFINE_ARRAY_DOUBLE(T, name) \
863 WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
864#define WX_DEFINE_EXPORTED_ARRAY_DOUBLE(T, name) \
865 WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
866#define WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(T, name, expmode) \
867 WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayDouble, expmode)
868
869// ----------------------------------------------------------------------------
870// Convenience macros to define sorted arrays from base arrays
871// ----------------------------------------------------------------------------
872
873#define WX_DEFINE_SORTED_ARRAY(T, name) \
874 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
875#define WX_DEFINE_SORTED_EXPORTED_ARRAY(T, name) \
876 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
877#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, expmode) \
878 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid, expmode)
879
880#define WX_DEFINE_SORTED_ARRAY_SHORT(T, name) \
881 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayShort)
882#define WX_DEFINE_SORTED_EXPORTED_ARRAY_SHORT(T, name) \
883 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort)
884#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
885 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort, expmode)
886
887#define WX_DEFINE_SORTED_ARRAY_INT(T, name) \
888 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayInt)
889#define WX_DEFINE_SORTED_EXPORTED_ARRAY_INT(T, name) \
890 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt)
891#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
892 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt, expmode)
893
894#define WX_DEFINE_SORTED_ARRAY_LONG(T, name) \
895 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayLong)
896#define WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(T, name) \
897 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong)
898#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
899 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong, expmode)
900
901#define WX_DEFINE_SORTED_ARRAY_SIZE_T(T, name) \
902 WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
903#define WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(T, name) \
904 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
905#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
906 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT, expmode)
907
908// ----------------------------------------------------------------------------
909// Convenience macros to define sorted arrays from base arrays
910// ----------------------------------------------------------------------------
911
912#define WX_DEFINE_SORTED_ARRAY_CMP(T, cmpfunc, name) \
913 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
914#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP(T, cmpfunc, name) \
915 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
916#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP(T, cmpfunc, \
917 name, expmode) \
918 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
919 wxBaseArrayPtrVoid, expmode)
920
921#define WX_DEFINE_SORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
922 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
923#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
924 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
925#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, \
926 name, expmode) \
927 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
928 wxBaseArrayShort, expmode)
929
930#define WX_DEFINE_SORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
931 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
932#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
933 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
934#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, \
935 name, expmode) \
936 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
937 wxBaseArrayInt, expmode)
938
939#define WX_DEFINE_SORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
940 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
941#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
942 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
943#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, \
944 name, expmode) \
945 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
946 wxBaseArrayLong, expmode)
947
948#define WX_DEFINE_SORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
949 WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
950#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
951 WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
952#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, \
953 name, expmode) \
954 WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
955 wxBaseArraySizeT, expmode)
956
957// ----------------------------------------------------------------------------
958// Some commonly used predefined arrays
959// ----------------------------------------------------------------------------
960
961WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(short, wxArrayShort, class WXDLLIMPEXP_BASE);
962WX_DEFINE_USER_EXPORTED_ARRAY_INT(int, wxArrayInt, class WXDLLIMPEXP_BASE);
963WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, wxArrayLong, class WXDLLIMPEXP_BASE);
964WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE);
965
966// -----------------------------------------------------------------------------
967// convenience macros
968// -----------------------------------------------------------------------------
969
970// append all element of one array to another one
971#define WX_APPEND_ARRAY(array, other) \
972 { \
973 size_t count = (other).size(); \
974 for ( size_t n = 0; n < count; n++ ) \
975 { \
976 (array).push_back((other)[n]); \
977 } \
978 }
979
980// delete all array elements
981//
982// NB: the class declaration of the array elements must be visible from the
983// place where you use this macro, otherwise the proper destructor may not
984// be called (a decent compiler should give a warning about it, but don't
985// count on it)!
986#define WX_CLEAR_ARRAY(array) \
987 { \
988 size_t count = (array).size(); \
989 for ( size_t n = 0; n < count; n++ ) \
990 { \
991 delete (array)[n]; \
992 } \
993 \
994 (array).clear(); \
995 }
996
997#endif // _DYNARRAY_H
998