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