]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/arrimpl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/arrimpl.cpp
3 // Purpose: helper file for implementation of dynamic lists
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
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) *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_OBJARRAY *
19 * 3) #include arrimpl.cpp *
20 * 4) WX_DEFINE_OBJARRAY *
21 *****************************************************************************/
23 // needed to resolve the conflict between global T and macro parameter T
25 // VC++ can't cope with string concatenation in Unicode mode
26 #if defined(wxUSE_UNICODE) && wxUSE_UNICODE
27 #define _WX_ERROR_REMOVE2(x) wxT("bad index in ::RemoveAt()")
29 #define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::RemoveAt()")
32 // macro implements remaining (not inline) methods of template list
33 // (it's private to this file)
34 #undef _DEFINE_OBJARRAY
35 #define _DEFINE_OBJARRAY(T, name) \
41 void name::DoCopy(const name& src) \
43 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
47 name& name::operator=(const name& src) \
55 name::name(const name& src) : wxArrayPtrVoid() \
60 void name::DoEmpty() \
62 for ( size_t ui = 0; ui < Count(); ui++ ) \
63 delete (T*)wxBaseArrayPtrVoid::Item(ui); \
66 void name::RemoveAt(size_t uiIndex, size_t nRemove) \
68 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
70 for (size_t i = 0; i < nRemove; i++ ) \
71 delete (T*)wxBaseArrayPtrVoid::Item(uiIndex + i); \
73 wxBaseArrayPtrVoid::RemoveAt(uiIndex, nRemove); \
76 void name::Add(const T& item, size_t nInsert) \
80 T* pItem = new T(item); \
81 size_t nOldSize = GetCount(); \
82 if ( pItem != NULL ) \
83 wxBaseArrayPtrVoid::Add(pItem, nInsert); \
84 for (size_t i = 1; i < nInsert; i++) \
85 wxBaseArrayPtrVoid::Item(nOldSize + i) = new T(item); \
88 void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
92 T* pItem = new T(item); \
93 if ( pItem != NULL ) \
94 wxBaseArrayPtrVoid::Insert(pItem, uiIndex, nInsert); \
95 for (size_t i = 1; i < nInsert; i++) \
96 wxBaseArrayPtrVoid::Item(uiIndex + i) = new T(item); \
99 int name::Index(const T& Item, bool bFromEnd) const \
102 if ( Count() > 0 ) { \
103 size_t ui = Count() - 1; \
105 if ( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
113 for( size_t ui = 0; ui < Count(); ui++ ) { \
114 if( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
119 return wxNOT_FOUND; \
122 // redefine the macro so that now it will generate the class implementation
123 // old value would provoke a compile-time error if this file is not included
124 #undef WX_DEFINE_OBJARRAY
125 #define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)