]> git.saurik.com Git - wxWidgets.git/blame - include/wx/arrimpl.cpp
Removed unused files.
[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
VZ
6// Created: 16.10.97
7// RCS-ID: $Id$
8// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
0a53b9b8 9// Licence: wxWindows license
0297f5c6
VZ
10///////////////////////////////////////////////////////////////////////////////
11
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) *
16 * *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_OBJARRAY *
19 * 3) #include arrimpl.cpp *
20 * 4) WX_DEFINE_OBJARRAY *
21 *****************************************************************************/
22
e90c1d2a 23// needed to resolve the conflict between global T and macro parameter T
fbdcff4a 24
eee3624b 25#define _WX_ERROR_REMOVE2(x) wxT("bad index in ") wxT(#x) wxT("::RemoveAt()")
e90c1d2a 26
0297f5c6
VZ
27// macro implements remaining (not inline) methods of template list
28// (it's private to this file)
22692cf6
VZ
29#undef _DEFINE_OBJARRAY
30#define _DEFINE_OBJARRAY(T, name) \
0297f5c6
VZ
31name::~name() \
32{ \
33 Empty(); \
34} \
35 \
36void name::DoCopy(const name& src) \
37{ \
df5168c4 38 for ( size_t ui = 0; ui < src.size(); ui++ ) \
0297f5c6
VZ
39 Add(src[ui]); \
40} \
41 \
42name& name::operator=(const name& src) \
43{ \
44 Empty(); \
45 DoCopy(src); \
46 \
47 return *this; \
48} \
49 \
d84afea9 50name::name(const name& src) : wxArrayPtrVoid() \
0297f5c6
VZ
51{ \
52 DoCopy(src); \
53} \
54 \
f6bcfd97 55void name::DoEmpty() \
0297f5c6 56{ \
df5168c4
MB
57 for ( size_t ui = 0; ui < size(); ui++ ) \
58 delete (T*)base_array::operator[](ui); \
0297f5c6
VZ
59} \
60 \
3b0b5f13 61void name::RemoveAt(size_t uiIndex, size_t nRemove) \
0297f5c6 62{ \
df5168c4 63 wxCHECK_RET( uiIndex < size(), _WX_ERROR_REMOVE2(name) ); \
0297f5c6 64 \
3b0b5f13 65 for (size_t i = 0; i < nRemove; i++ ) \
df5168c4 66 delete (T*)base_array::operator[](uiIndex + i); \
0297f5c6 67 \
df5168c4 68 base_array::erase(begin() + uiIndex, begin() + uiIndex + nRemove); \
0297f5c6
VZ
69} \
70 \
3b0b5f13 71void name::Add(const T& item, size_t nInsert) \
0297f5c6 72{ \
2b5f62a0
VZ
73 if (nInsert == 0) \
74 return; \
0297f5c6 75 T* pItem = new T(item); \
df5168c4 76 size_t nOldSize = size(); \
0297f5c6 77 if ( pItem != NULL ) \
df5168c4 78 base_array::insert(end(), nInsert, pItem); \
3b0b5f13 79 for (size_t i = 1; i < nInsert; i++) \
df5168c4 80 base_array::operator[](nOldSize + i) = new T(item); \
0297f5c6
VZ
81} \
82 \
3b0b5f13 83void name::Insert(const T& item, size_t uiIndex, size_t nInsert) \
0297f5c6 84{ \
2b5f62a0
VZ
85 if (nInsert == 0) \
86 return; \
0297f5c6
VZ
87 T* pItem = new T(item); \
88 if ( pItem != NULL ) \
df5168c4 89 base_array::insert(begin() + uiIndex, nInsert, pItem); \
3b0b5f13 90 for (size_t i = 1; i < nInsert; i++) \
df5168c4 91 base_array::operator[](uiIndex + i) = new T(item); \
0297f5c6
VZ
92} \
93 \
22692cf6 94int name::Index(const T& Item, bool bFromEnd) const \
0297f5c6
VZ
95{ \
96 if ( bFromEnd ) { \
df5168c4
MB
97 if ( size() > 0 ) { \
98 size_t ui = size() - 1; \
0297f5c6 99 do { \
df5168c4 100 if ( (T*)base_array::operator[](ui) == &Item ) \
106d80ad 101 return wx_static_cast(int, ui); \
0297f5c6
VZ
102 ui--; \
103 } \
104 while ( ui != 0 ); \
105 } \
106 } \
107 else { \
df5168c4
MB
108 for( size_t ui = 0; ui < size(); ui++ ) { \
109 if( (T*)base_array::operator[](ui) == &Item ) \
106d80ad 110 return wx_static_cast(int, ui); \
0297f5c6
VZ
111 } \
112 } \
113 \
e90c1d2a
VZ
114 return wxNOT_FOUND; \
115}
0297f5c6
VZ
116
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
1a931653 120#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_wxObjArray##name, name)