]> git.saurik.com Git - wxWidgets.git/blob - include/wx/arrimpl.cpp
Triued in vain to fix threads segvs with gcc
[wxWidgets.git] / include / wx / arrimpl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: listimpl.cpp
3 // Purpose: helper file for implementation of dynamic lists
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 16.10.97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*****************************************************************************
13 * Purpose: implements methods of "template" class declared in *
14 * DECLARE_OBJARRAY macro and which couldn't be implemented inline *
15 * (because they need the full definition of type T in scope) *
16 * *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_OBJARRAY *
19 * 3) #include arrimpl.cpp *
20 * 4) WX_DEFINE_OBJARRAY *
21 *****************************************************************************/
22
23 // macro implements remaining (not inline) methods of template list
24 // (it's private to this file)
25 #define _DEFINE_OBJARRAY(T, name) \
26 name::~name() \
27 { \
28 Empty(); \
29 } \
30 \
31 void name::DoCopy(const name& src) \
32 { \
33 for ( uint ui = 0; ui < src.Count(); ui++ ) \
34 Add(src[ui]); \
35 } \
36 \
37 name& name::operator=(const name& src) \
38 { \
39 Empty(); \
40 DoCopy(src); \
41 \
42 return *this; \
43 } \
44 \
45 name::name(const name& src) \
46 { \
47 DoCopy(src); \
48 } \
49 \
50 void name::Empty() \
51 { \
52 for ( uint ui = 0; ui < Count(); ui++ ) \
53 delete (T*)BaseArray::Item(ui); \
54 \
55 BaseArray::Clear(); \
56 } \
57 \
58 void name::Remove(uint uiIndex) \
59 { \
60 wxCHECK( uiIndex < Count() ); \
61 \
62 delete (T*)BaseArray::Item(uiIndex); \
63 \
64 BaseArray::Remove(uiIndex); \
65 } \
66 \
67 void name::Add(const T& item) \
68 { \
69 T* pItem = new T(item); \
70 if ( pItem != NULL ) \
71 Add(pItem); \
72 } \
73 \
74 void name::Insert(const T& item, uint uiIndex) \
75 { \
76 T* pItem = new T(item); \
77 if ( pItem != NULL ) \
78 Insert(pItem, uiIndex); \
79 } \
80 \
81 int name::Index(const T& Item, Bool bFromEnd) const \
82 { \
83 if ( bFromEnd ) { \
84 if ( Count() > 0 ) { \
85 uint ui = Count() - 1; \
86 do { \
87 if ( (T*)BaseArray::Item(ui) == &Item ) \
88 return ui; \
89 ui--; \
90 } \
91 while ( ui != 0 ); \
92 } \
93 } \
94 else { \
95 for( uint ui = 0; ui < Count(); ui++ ) { \
96 if( (T*)BaseArray::Item(ui) == &Item ) \
97 return ui; \
98 } \
99 } \
100 \
101 return NOT_FOUND; \
102 }
103
104 // redefine the macro so that now it will generate the class implementation
105 // old value would provoke a compile-time error if this file is not included
106 #undef WX_DEFINE_OBJARRAY
107 #define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_L##name, name)
108
109 // don't pollute preprocessor's name space
110 #undef _DEFINE_OBJARRAY
111