]> git.saurik.com Git - wxWidgets.git/blame - include/wx/arrimpl.cpp
wxDialogBase only has one ctor, so just do initialization in ctor instead of Init()
[wxWidgets.git] / include / wx / arrimpl.cpp
CommitLineData
0297f5c6 1///////////////////////////////////////////////////////////////////////////////
1a931653 2// Name: wx/arrimpl.cpp
0297f5c6
VZ
3// Purpose: helper file for implementation of dynamic lists
4// Author: Vadim Zeitlin
e90c1d2a 5// Modified by:
0297f5c6 6// Created: 16.10.97
0297f5c6 7// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
526954c5 8// Licence: wxWindows licence
0297f5c6
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11/*****************************************************************************
12 * Purpose: implements methods of "template" class declared in *
13 * DECLARE_OBJARRAY macro and which couldn't be implemented inline *
14 * (because they need the full definition of type T in scope) *
15 * *
16 * Usage: 1) #include dynarray.h *
17 * 2) WX_DECLARE_OBJARRAY *
18 * 3) #include arrimpl.cpp *
19 * 4) WX_DEFINE_OBJARRAY *
20 *****************************************************************************/
21
e90c1d2a 22// needed to resolve the conflict between global T and macro parameter T
fbdcff4a 23
eee3624b 24#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
e90c1d2a 25
0297f5c6
VZ
26// macro implements remaining (not inline) methods of template list
27// (it's private to this file)
22692cf6
VZ
28#undef _DEFINE_OBJARRAY
29#define _DEFINE_OBJARRAY(T, name) \
0297f5c6
VZ
30name::~name() \
31{ \
32 Empty(); \
33} \
34 \
35void name::DoCopy(const name& src) \
36{ \
df5168c4 37 for ( size_t ui = 0; ui < src.size(); ui++ ) \
0297f5c6
VZ
38 Add(src[ui]); \
39} \
40 \
41name& name::operator=(const name& src) \
42{ \
43 Empty(); \
44 DoCopy(src); \
45 \
46 return *this; \
47} \
48 \
d84afea9 49name::name(const name& src) : wxArrayPtrVoid() \
0297f5c6
VZ
50{ \
51 DoCopy(src); \
52} \
53 \
f6bcfd97 54void name::DoEmpty() \
0297f5c6 55{ \
df5168c4
MB
56 for ( size_t ui = 0; ui < size(); ui++ ) \
57 delete (T*)base_array::operator[](ui); \
0297f5c6
VZ
58} \
59 \
3b0b5f13 60void name::RemoveAt(size_t uiIndex, size_t nRemove) \
0297f5c6 61{ \
df5168c4 62 wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
0297f5c6 63 \
3b0b5f13 64 for (size_t i = 0; i < nRemove; i++ ) \
df5168c4 65 delete (T*)base_array::operator[](uiIndex + i); \
0297f5c6 66 \
df5168c4 67 base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
0297f5c6
VZ
68} \
69 \
3b0b5f13 70void name::Add(const T& item, size_t nInsert) \
0297f5c6 71{ \
2b5f62a0
VZ
72 if (nInsert == 0) \
73 return; \
0297f5c6 74 T* pItem = new T(item); \
df5168c4 75 size_t nOldSize = size(); \
0297f5c6 76 if ( pItem != NULL ) \
df5168c4 77 base_array::insert(end(), nInsert, pItem); \
3b0b5f13 78 for (size_t i = 1; i < nInsert; i++) \
df5168c4 79 base_array::operator[](nOldSize + i) = new T(item); \
0297f5c6
VZ
80} \
81 \
3b0b5f13 82void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
0297f5c6 83{ \
2b5f62a0
VZ
84 if (nInsert == 0) \
85 return; \
0297f5c6
VZ
86 T* pItem = new T(item); \
87 if ( pItem != NULL ) \
df5168c4 88 base_array::insert(begin() + uiIndex, nInsert, pItem); \
3b0b5f13 89 for (size_t i = 1; i < nInsert; i++) \
df5168c4 90 base_array::operator[](uiIndex + i) = new T(item); \
0297f5c6
VZ
91} \
92 \
7d1214cd 93int name::Index(const T& item, bool bFromEnd) const \
0297f5c6
VZ
94{ \
95 if ( bFromEnd ) { \
df5168c4
MB
96 if ( size() > 0 ) { \
97 size_t ui = size() - 1; \
0297f5c6 98 do { \
7d1214cd 99 if ( (T*)base_array::operator[](ui) == &item ) \
5c33522f 100 return static_cast<int>(ui); \
0297f5c6
VZ
101 ui--; \
102 } \
103 while ( ui != 0 ); \
104 } \
105 } \
106 else { \
df5168c4 107 for( size_t ui = 0; ui < size(); ui++ ) { \
7d1214cd 108 if( (T*)base_array::operator[](ui) == &item ) \
5c33522f 109 return static_cast<int>(ui); \
0297f5c6
VZ
110 } \
111 } \
112 \
e90c1d2a
VZ
113 return wxNOT_FOUND; \
114}
0297f5c6
VZ
115
116// redefine the macro so that now it will generate the class implementation
117// old value would provoke a compile-time error if this file is not included
118#undef WX_DEFINE_OBJARRAY
1a931653 119#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)