00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __A2DLIST_H__
00015 #define __A2DLIST_H__
00016
00017
00018 #include "wx/general/generaldef.h"
00019
00020 template<class Clss> class a2dSmrtPtr;
00021
00022
00023
00024
00025 #include <memory>
00026 #include <list>
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 template<class T>
00042 class a2dlist: public std::list< T, std::allocator<T> >
00043 {
00044 public:
00045
00046
00047 a2dlist()
00048 {
00049 }
00050
00051
00052 a2dlist( const a2dlist &other );
00053
00054
00055 ~a2dlist();
00056
00057 typename a2dlist<T>::const_iterator item(size_t index) const
00058 {
00059 typename a2dlist<T>::const_iterator iter = this->begin();
00060 for( size_t i = 0; i < index; ++i)
00061 iter++;
00062 return iter;
00063 }
00064
00065 typename a2dlist<T>::iterator item(size_t index)
00066 {
00067 typename a2dlist<T>::iterator iter = this->begin();
00068 for(size_t i = 0; i < index; ++i)
00069 iter++;
00070 return iter;
00071 }
00072
00073 typename a2dlist<T>::reverse_iterator rerase( typename std::list< T, std::allocator< T > >::reverse_iterator iterr )
00074 {
00075 typename std::list< T, std::allocator< T > >::iterator it( iterr.base() ) ;
00076 iterr++;
00077 -- it ;
00078 erase( it ) ;
00079 return iterr;
00080 }
00081
00082
00083 typename std::list< T, std::allocator< T > >::iterator GetPreviousAround( typename std::list< T, std::allocator< T > >::iterator iter )
00084 {
00085 if ( this->size() )
00086 {
00087 if ( iter == this->begin() )
00088 return --(this->end());
00089 return --iter;
00090 }
00091 return this->begin();
00092 }
00093
00094
00095 typename std::list< T, std::allocator< T > >::iterator GetNextAround( typename std::list< T, std::allocator< T > >::iterator iter )
00096 {
00097 if ( this->size() )
00098 {
00099 if ( iter == --(this->end()) )
00100 return this->begin();
00101 return ++iter;
00102 }
00103 return this->begin();
00104 }
00105 };
00106
00107
00108 template<class Clss>
00109 class a2dPtr
00110 {
00111 public:
00112 typedef Clss TType;
00113
00114 a2dPtr()
00115 {
00116 m_ptr = NULL;
00117 }
00118
00119 a2dPtr( Clss* objc )
00120 {
00121 m_ptr = objc;
00122 }
00123
00124 a2dPtr( const a2dPtr &objc )
00125 {
00126 m_ptr = &*objc;
00127 }
00128
00129 ~a2dPtr()
00130 {
00131 if( m_ptr )
00132 delete m_ptr;
00133 }
00134
00135 void operator=( const a2dPtr &objc )
00136 {
00137 m_ptr = &*objc;
00138 }
00139
00140 void operator=( Clss *objc )
00141 {
00142 m_ptr = objc;
00143 }
00144
00145 friend inline bool operator==(const a2dPtr &a, const a2dPtr &b)
00146 {
00147 return a.m_ptr == b.m_ptr;
00148 }
00149
00150 friend inline bool operator!=(const a2dPtr &a, const a2dPtr &b)
00151 {
00152 return a.m_ptr != b.m_ptr;
00153 }
00154
00155
00156
00157 friend inline bool operator==(const a2dPtr &a, const Clss *b)
00158 {
00159 return a.m_ptr == b;
00160 }
00161
00162 friend inline bool operator!=(const a2dPtr &a, const Clss *b)
00163 {
00164 return a.m_ptr != b;
00165 }
00166
00167 friend inline bool operator==(const Clss *a, const a2dPtr &b)
00168 {
00169 return a == b.m_ptr;
00170 }
00171
00172 friend inline bool operator!=(const Clss *a, const a2dPtr &b)
00173 {
00174 return a != b.m_ptr;
00175 }
00176
00177 friend inline bool operator==(const a2dPtr &a, Clss *b)
00178 {
00179 return a.m_ptr == b;
00180 }
00181
00182 friend inline bool operator!=(const a2dPtr &a, Clss *b)
00183 {
00184 return a.m_ptr != b;
00185 }
00186
00187 friend inline bool operator==( Clss *a, const a2dPtr &b)
00188 {
00189 return a == b.m_ptr;
00190 }
00191
00192 friend inline bool operator!=( Clss *a, const a2dPtr &b)
00193 {
00194 return a != b.m_ptr;
00195 }
00196
00197 inline operator Clss* () const { return m_ptr; }
00198
00199 inline Clss *Get() const
00200 {
00201 return m_ptr;
00202 }
00203
00204 inline Clss *operator->() const { return m_ptr; }
00205
00206 inline Clss &operator*() const { return *m_ptr; }
00207
00208 private:
00209 Clss* m_ptr;
00210 };
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 template<class T>
00222 class a2dPtrList: public a2dlist< T* >
00223 {
00224 typedef typename a2dlist< T* >::iterator itSmart;
00225 typedef typename a2dlist< T* >::const_iterator const_itSmart;
00226
00227 public:
00228
00229 itSmart Find( T *object );
00230
00231
00232 const_itSmart Find( T *object ) const;
00233
00234
00235 int IndexOf(T *object) const;
00236
00237
00238 bool ReleaseObject( T *object );
00239
00240
00241
00242 void DeleteObjects();
00243 };
00244
00245
00246
00247
00248
00249 #define forEachIn( listtype, list ) \
00250 for( listtype::iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
00251
00252
00253
00254
00255
00256 #define const_forEachIn( listtype, list ) \
00257 for( listtype::const_iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
00258
00259 #include "a2dlist.inl"
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 #endif // __A2DLIST_H__