]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/arrimpl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
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
24 #define _WX_ERROR_REMOVE2(x) T("bad index in " #x "::Remove()")
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) \
35 void name::DoCopy(const name& src) \
37 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
41 name& name::operator=(const name& src) \
49 name::name(const name& src) \
56 for ( size_t ui = 0; ui < Count(); ui++ ) \
57 delete (T*)wxBaseArray::Item(ui); \
59 wxBaseArray::Clear(); \
62 void name::Remove(size_t uiIndex) \
64 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
66 delete (T*)wxBaseArray::Item(uiIndex); \
68 wxBaseArray::Remove(uiIndex); \
71 void name::Add(const T& item) \
73 T* pItem = new T(item); \
74 if ( pItem != NULL ) \
78 void name::Insert(const T& item, size_t uiIndex) \
80 T* pItem = new T(item); \
81 if ( pItem != NULL ) \
82 Insert(pItem, uiIndex); \
85 int name::Index(const T& Item, bool bFromEnd) const \
88 if ( Count() > 0 ) { \
89 size_t ui = Count() - 1; \
91 if ( (T*)wxBaseArray::Item(ui) == &Item ) \
99 for( size_t ui = 0; ui < Count(); ui++ ) { \
100 if( (T*)wxBaseArray::Item(ui) == &Item ) \
105 return wxNOT_FOUND; \
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)