]> git.saurik.com Git - wxWidgets.git/blame - include/wx/arrimpl.cpp
Ignore erase failures
[wxWidgets.git] / include / wx / arrimpl.cpp
CommitLineData
0297f5c6
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: listimpl.cpp
3// Purpose: helper file for implementation of dynamic lists
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 16.10.97
7// RCS-ID: $Id$
8// Copyright: (c) 1997 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
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
23// macro implements remaining (not inline) methods of template list
24// (it's private to this file)
22692cf6
VZ
25#undef _DEFINE_OBJARRAY
26#define _DEFINE_OBJARRAY(T, name) \
0297f5c6
VZ
27name::~name() \
28{ \
29 Empty(); \
30} \
31 \
32void name::DoCopy(const name& src) \
33{ \
22692cf6 34 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
0297f5c6
VZ
35 Add(src[ui]); \
36} \
37 \
38name& name::operator=(const name& src) \
39{ \
40 Empty(); \
41 DoCopy(src); \
42 \
43 return *this; \
44} \
45 \
46name::name(const name& src) \
47{ \
48 DoCopy(src); \
49} \
50 \
51void name::Empty() \
52{ \
22692cf6
VZ
53 for ( size_t ui = 0; ui < Count(); ui++ ) \
54 delete (T*)wxBaseArray::Item(ui); \
0297f5c6 55 \
22692cf6 56 wxBaseArray::Clear(); \
0297f5c6
VZ
57} \
58 \
22692cf6 59void name::Remove(size_t uiIndex) \
0297f5c6 60{ \
a69f7aa8 61 wxCHECK_RET( uiIndex < Count(), _T("bad index in " #name "::Remove()") ); \
0297f5c6 62 \
22692cf6 63 delete (T*)wxBaseArray::Item(uiIndex); \
0297f5c6 64 \
22692cf6 65 wxBaseArray::Remove(uiIndex); \
0297f5c6
VZ
66} \
67 \
68void name::Add(const T& item) \
69{ \
70 T* pItem = new T(item); \
71 if ( pItem != NULL ) \
72 Add(pItem); \
73} \
74 \
22692cf6 75void name::Insert(const T& item, size_t uiIndex) \
0297f5c6
VZ
76{ \
77 T* pItem = new T(item); \
78 if ( pItem != NULL ) \
79 Insert(pItem, uiIndex); \
80} \
81 \
22692cf6 82int name::Index(const T& Item, bool bFromEnd) const \
0297f5c6
VZ
83{ \
84 if ( bFromEnd ) { \
85 if ( Count() > 0 ) { \
22692cf6 86 size_t ui = Count() - 1; \
0297f5c6 87 do { \
22692cf6 88 if ( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
89 return ui; \
90 ui--; \
91 } \
92 while ( ui != 0 ); \
93 } \
94 } \
95 else { \
22692cf6
VZ
96 for( size_t ui = 0; ui < Count(); ui++ ) { \
97 if( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
98 return ui; \
99 } \
100 } \
101 \
3c67202d 102 return wxNOT_FOUND; \
0297f5c6
VZ
103}
104
105// redefine the macro so that now it will generate the class implementation
106// old value would provoke a compile-time error if this file is not included
107#undef WX_DEFINE_OBJARRAY
108#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_L##name, name)