]> git.saurik.com Git - wxWidgets.git/blob - include/wx/arrimpl.cpp
some fixes after global _T() => T() change
[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 // needed to resolve the conflict between global T and macro parameter T
24 #define _WX_ERROR_REMOVE2(x) T("bad index in " #x "::Remove()")
25
26 // macro implements remaining (not inline) methods of template list
27 // (it's private to this file)
28 #undef _DEFINE_OBJARRAY
29 #define _DEFINE_OBJARRAY(T, name) \
30 name::~name() \
31 { \
32 Empty(); \
33 } \
34 \
35 void name::DoCopy(const name& src) \
36 { \
37 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
38 Add(src[ui]); \
39 } \
40 \
41 name& name::operator=(const name& src) \
42 { \
43 Empty(); \
44 DoCopy(src); \
45 \
46 return *this; \
47 } \
48 \
49 name::name(const name& src) \
50 { \
51 DoCopy(src); \
52 } \
53 \
54 void name::Empty() \
55 { \
56 for ( size_t ui = 0; ui < Count(); ui++ ) \
57 delete (T*)wxBaseArray::Item(ui); \
58 \
59 wxBaseArray::Clear(); \
60 } \
61 \
62 void name::Remove(size_t uiIndex) \
63 { \
64 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
65 \
66 delete (T*)wxBaseArray::Item(uiIndex); \
67 \
68 wxBaseArray::Remove(uiIndex); \
69 } \
70 \
71 void name::Add(const T& item) \
72 { \
73 T* pItem = new T(item); \
74 if ( pItem != NULL ) \
75 Add(pItem); \
76 } \
77 \
78 void name::Insert(const T& item, size_t uiIndex) \
79 { \
80 T* pItem = new T(item); \
81 if ( pItem != NULL ) \
82 Insert(pItem, uiIndex); \
83 } \
84 \
85 int name::Index(const T& Item, bool bFromEnd) const \
86 { \
87 if ( bFromEnd ) { \
88 if ( Count() > 0 ) { \
89 size_t ui = Count() - 1; \
90 do { \
91 if ( (T*)wxBaseArray::Item(ui) == &Item ) \
92 return ui; \
93 ui--; \
94 } \
95 while ( ui != 0 ); \
96 } \
97 } \
98 else { \
99 for( size_t ui = 0; ui < Count(); ui++ ) { \
100 if( (T*)wxBaseArray::Item(ui) == &Item ) \
101 return ui; \
102 } \
103 } \
104 \
105 return wxNOT_FOUND; \
106 }
107
108 // redefine the macro so that now it will generate the class implementation
109 // old value would provoke a compile-time error if this file is not included
110 #undef WX_DEFINE_OBJARRAY
111 #define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_L##name, name)