]>
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 #define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
27 // macro implements remaining (not inline) methods of template list
28 // (it's private to this file)
29 #undef _DEFINE_OBJARRAY
30 #define _DEFINE_OBJARRAY(T, name) \
36 void name::DoCopy(const name& src) \
38 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
42 name& name::operator=(const name& src) \
50 name::name(const name& src) : wxArrayPtrVoid() \
55 void name::DoEmpty() \
57 for ( size_t ui = 0; ui < Count(); ui++ ) \
58 delete (T*)wxBaseArrayPtrVoid::Item(ui); \
61 void name::RemoveAt(size_t uiIndex, size_t nRemove) \
63 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
65 for (size_t i = 0; i < nRemove; i++ ) \
66 delete (T*)wxBaseArrayPtrVoid::Item(uiIndex + i); \
68 wxBaseArrayPtrVoid::RemoveAt(uiIndex, nRemove); \
71 void name::Add(const T& item, size_t nInsert) \
75 T* pItem = new T(item); \
76 size_t nOldSize = GetCount(); \
77 if ( pItem != NULL ) \
78 wxBaseArrayPtrVoid::Add(pItem, nInsert); \
79 for (size_t i = 1; i < nInsert; i++) \
80 wxBaseArrayPtrVoid::Item(nOldSize + i) = new T(item); \
83 void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
87 T* pItem = new T(item); \
88 if ( pItem != NULL ) \
89 wxBaseArrayPtrVoid::Insert(pItem, uiIndex, nInsert); \
90 for (size_t i = 1; i < nInsert; i++) \
91 wxBaseArrayPtrVoid::Item(uiIndex + i) = new T(item); \
94 int name::Index(const T& Item, bool bFromEnd) const \
97 if ( Count() > 0 ) { \
98 size_t ui = Count() - 1; \
100 if ( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
108 for( size_t ui = 0; ui < Count(); ui++ ) { \
109 if( (T*)wxBaseArrayPtrVoid::Item(ui) == &Item ) \
114 return wxNOT_FOUND; \
117 // redefine the macro so that now it will generate the class implementation
118 // old value would provoke a compile-time error if this file is not included
119 #undef WX_DEFINE_OBJARRAY
120 #define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)