]> git.saurik.com Git - wxWidgets.git/blame - include/wx/arrimpl.cpp
Some make corrections for HP and related,
[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
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>
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
e90c1d2a 23// needed to resolve the conflict between global T and macro parameter T
8a729bb8 24#define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::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{ \
22692cf6 37 for ( size_t ui = 0; ui < src.Count(); 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 \
49name::name(const name& src) \
50{ \
51 DoCopy(src); \
52} \
53 \
54void name::Empty() \
55{ \
22692cf6
VZ
56 for ( size_t ui = 0; ui < Count(); ui++ ) \
57 delete (T*)wxBaseArray::Item(ui); \
0297f5c6 58 \
22692cf6 59 wxBaseArray::Clear(); \
0297f5c6
VZ
60} \
61 \
8a729bb8 62void name::RemoveAt(size_t uiIndex) \
0297f5c6 63{ \
e90c1d2a 64 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
0297f5c6 65 \
22692cf6 66 delete (T*)wxBaseArray::Item(uiIndex); \
0297f5c6 67 \
8a729bb8 68 wxBaseArray::RemoveAt(uiIndex); \
0297f5c6
VZ
69} \
70 \
71void name::Add(const T& item) \
72{ \
73 T* pItem = new T(item); \
74 if ( pItem != NULL ) \
75 Add(pItem); \
76} \
77 \
22692cf6 78void name::Insert(const T& item, size_t uiIndex) \
0297f5c6
VZ
79{ \
80 T* pItem = new T(item); \
81 if ( pItem != NULL ) \
82 Insert(pItem, uiIndex); \
83} \
84 \
22692cf6 85int name::Index(const T& Item, bool bFromEnd) const \
0297f5c6
VZ
86{ \
87 if ( bFromEnd ) { \
88 if ( Count() > 0 ) { \
22692cf6 89 size_t ui = Count() - 1; \
0297f5c6 90 do { \
22692cf6 91 if ( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
92 return ui; \
93 ui--; \
94 } \
95 while ( ui != 0 ); \
96 } \
97 } \
98 else { \
22692cf6
VZ
99 for( size_t ui = 0; ui < Count(); ui++ ) { \
100 if( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
101 return ui; \
102 } \
103 } \
104 \
e90c1d2a
VZ
105 return wxNOT_FOUND; \
106}
0297f5c6
VZ
107
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)