]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/listimpl.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 DECLARE_LIST *
14 * macro and which couldn't be implemented inline (because they *
15 * need the full definition of type T in scope) *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_LIST *
19 * 3) #include listimpl.cpp *
21 *****************************************************************************/
23 // macro implements remaining (not inline) methods of template list
24 // (it's private to this file)
25 #define _DEFINE_LIST(T, name) \
31 void name::DoCopy(const name& src) \
33 for ( uint ui = 0; ui < src.Count(); ui++ ) \
37 name& name::operator=(const name& src) \
45 name::name(const name& src) \
52 for ( uint ui = 0; ui < Count(); ui++ ) \
53 delete (T*)BaseArray::Item(ui); \
58 void name::Remove(uint uiIndex) \
60 wxCHECK( uiIndex < Count() ); \
62 delete (T*)BaseArray::Item(uiIndex); \
64 BaseArray::Remove(uiIndex); \
67 void name::Add(const T& item) \
69 T* pItem = new T(item); \
70 if ( pItem != NULL ) \
74 void name::Insert(const T& item, uint uiIndex) \
76 T* pItem = new T(item); \
77 if ( pItem != NULL ) \
78 Insert(pItem, uiIndex); \
81 int name::Index(const T& Item, Bool bFromEnd) const \
84 if ( Count() > 0 ) { \
85 uint ui = Count() - 1; \
87 if ( (T*)BaseArray::Item(ui) == &Item ) \
95 for( uint ui = 0; ui < Count(); ui++ ) { \
96 if( (T*)BaseArray::Item(ui) == &Item ) \
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_LIST
107 #define WX_DEFINE_LIST(name) _DEFINE_LIST(_L##name, name)
109 // don't pollute preprocessor's name space