]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listimpl.cpp
Added variant.h/cpp; changed variable names in object.h; added some
[wxWidgets.git] / include / wx / listimpl.cpp
CommitLineData
75c6c545
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 DECLARE_LIST *
14 * macro and which couldn't be implemented inline (because they *
15 * need the full definition of type T in scope) *
16 * *
17 * Usage: 1) #include dynarray.h *
18 * 2) WX_DECLARE_LIST *
19 * 3) #include listimpl.cpp *
20 * 4) WX_DEFINE_LIST *
21 *****************************************************************************/
22
23// macro implements remaining (not inline) methods of template list
24// (it's private to this file)
25#define _DEFINE_LIST(T, name) \
26name::~name() \
27{ \
28 Empty(); \
29} \
30 \
31void name::DoCopy(const name& src) \
32{ \
33 for ( uint ui = 0; ui < src.Count(); ui++ ) \
34 Add(src[ui]); \
35} \
36 \
37name& name::operator=(const name& src) \
38{ \
39 Empty(); \
40 DoCopy(src); \
41 \
42 return *this; \
43} \
44 \
45name::name(const name& src) \
46{ \
47 DoCopy(src); \
48} \
49 \
50void name::Empty() \
51{ \
52 for ( uint ui = 0; ui < Count(); ui++ ) \
53 delete (T*)BaseArray::Item(ui); \
54 \
55 BaseArray::Clear(); \
56} \
57 \
58void name::Remove(uint uiIndex) \
59{ \
60 wxCHECK( uiIndex < Count() ); \
61 \
62 delete (T*)BaseArray::Item(uiIndex); \
63 \
64 BaseArray::Remove(uiIndex); \
65} \
66 \
67void name::Add(const T& item) \
68{ \
69 T* pItem = new T(item); \
70 if ( pItem != NULL ) \
71 Add(pItem); \
72} \
73 \
74void name::Insert(const T& item, uint uiIndex) \
75{ \
76 T* pItem = new T(item); \
77 if ( pItem != NULL ) \
78 Insert(pItem, uiIndex); \
79} \
80 \
81int name::Index(const T& Item, Bool bFromEnd) const \
82{ \
83 if ( bFromEnd ) { \
84 if ( Count() > 0 ) { \
85 uint ui = Count() - 1; \
86 do { \
87 if ( (T*)BaseArray::Item(ui) == &Item ) \
88 return ui; \
89 ui--; \
90 } \
91 while ( ui != 0 ); \
92 } \
93 } \
94 else { \
95 for( uint ui = 0; ui < Count(); ui++ ) { \
96 if( (T*)BaseArray::Item(ui) == &Item ) \
97 return ui; \
98 } \
99 } \
100 \
101 return NOT_FOUND; \
102}
103
104// redefine the macro so that now it will generate the class implementation
105// old value would provoke a compile-time error if this file is not included
106#undef WX_DEFINE_LIST
107#define WX_DEFINE_LIST(name) _DEFINE_LIST(_L##name, name)
108
109// don't pollute preprocessor's name space
110#undef _DEFINE_LIST
111