]> git.saurik.com Git - wxWidgets.git/blame - include/wx/arrimpl.cpp
added wxTLW for MSW
[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
fbdcff4a
JS
24
25// VC++ can't cope with string concatenation in Unicode mode
26#if defined(wxUSE_UNICODE) && wxUSE_UNICODE
27#define _WX_ERROR_REMOVE2(x) wxT("bad index in ::RemoveAt()")
28#else
8a729bb8 29#define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::RemoveAt()")
fbdcff4a 30#endif
e90c1d2a 31
0297f5c6
VZ
32// macro implements remaining (not inline) methods of template list
33// (it's private to this file)
22692cf6
VZ
34#undef _DEFINE_OBJARRAY
35#define _DEFINE_OBJARRAY(T, name) \
0297f5c6
VZ
36name::~name() \
37{ \
38 Empty(); \
39} \
40 \
41void name::DoCopy(const name& src) \
42{ \
22692cf6 43 for ( size_t ui = 0; ui < src.Count(); ui++ ) \
0297f5c6
VZ
44 Add(src[ui]); \
45} \
46 \
47name& name::operator=(const name& src) \
48{ \
49 Empty(); \
50 DoCopy(src); \
51 \
52 return *this; \
53} \
54 \
55name::name(const name& src) \
56{ \
57 DoCopy(src); \
58} \
59 \
f6bcfd97 60void name::DoEmpty() \
0297f5c6 61{ \
22692cf6
VZ
62 for ( size_t ui = 0; ui < Count(); ui++ ) \
63 delete (T*)wxBaseArray::Item(ui); \
0297f5c6
VZ
64} \
65 \
f6bcfd97 66void name::RemoveAt(size_t uiIndex) \
0297f5c6 67{ \
e90c1d2a 68 wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \
0297f5c6 69 \
22692cf6 70 delete (T*)wxBaseArray::Item(uiIndex); \
0297f5c6 71 \
f6bcfd97 72 wxBaseArray::RemoveAt(uiIndex); \
0297f5c6
VZ
73} \
74 \
75void name::Add(const T& item) \
76{ \
77 T* pItem = new T(item); \
78 if ( pItem != NULL ) \
79 Add(pItem); \
80} \
81 \
22692cf6 82void name::Insert(const T& item, size_t uiIndex) \
0297f5c6
VZ
83{ \
84 T* pItem = new T(item); \
85 if ( pItem != NULL ) \
86 Insert(pItem, uiIndex); \
87} \
88 \
22692cf6 89int name::Index(const T& Item, bool bFromEnd) const \
0297f5c6
VZ
90{ \
91 if ( bFromEnd ) { \
92 if ( Count() > 0 ) { \
22692cf6 93 size_t ui = Count() - 1; \
0297f5c6 94 do { \
22692cf6 95 if ( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
96 return ui; \
97 ui--; \
98 } \
99 while ( ui != 0 ); \
100 } \
101 } \
102 else { \
22692cf6
VZ
103 for( size_t ui = 0; ui < Count(); ui++ ) { \
104 if( (T*)wxBaseArray::Item(ui) == &Item ) \
0297f5c6
VZ
105 return ui; \
106 } \
107 } \
108 \
e90c1d2a
VZ
109 return wxNOT_FOUND; \
110}
0297f5c6
VZ
111
112// redefine the macro so that now it will generate the class implementation
113// old value would provoke a compile-time error if this file is not included
114#undef WX_DEFINE_OBJARRAY
115#define WX_DEFINE_OBJARRAY(name) _DEFINE_OBJARRAY(_L##name, name)