wxArt2D
a2dlist.h
Go to the documentation of this file.
1 /*! \file wx/general/a2dlist.h
2  \brief basic list class based on STL containers.
3  \author Klaas Holwerda
4  \author Kevin J Bluck
5  \date 1/11/2005
6 
7  Copyright: 2005 (c) Kevin J Bluck
8 
9  License: wxWidgets License
10 
11  RCS-ID: $Id: a2dlist.h,v 1.22 2008/08/05 15:52:43 titato Exp $
12 */
13 
14 #ifndef __A2DLIST_H__
15 #define __A2DLIST_H__
16 
17 // shared builds stuff
18 #include "wx/general/generaldef.h"
19 
20 template<class Clss> class a2dSmrtPtr;
21 
22 //#include <memory>
23 //#include <list>
24 
25 #include <memory>
26 #include <list>
27 
28 //! std list compatible list
29 /*!
30  Template list used all over wxDocview. It is a standard template list, with some extra features.
31  The (STL) list, stores the object by value.
32  Therefore often smartpointers are used to store the object,
33  in order to properly delete the object when a node is deleted.
34 
35  - See a2dSmrtPtrList< T >
36  - See a2dSmrtPtr< T >
37 
38  \ingroup general
39 
40 */
41 template<class T>
42 class a2dlist: public std::list< T, std::allocator<T> >
43 {
44 public:
45 
46  //! Default constructor
48  {
49  }
50 
51  //! Copy constructor
52  a2dlist( const a2dlist& other );
53 
54  //! Destructor
55  ~a2dlist();
56 
57  typename a2dlist<T>::const_iterator item( size_t index ) const
58  {
59  typename a2dlist<T>::const_iterator iter = this->begin();
60  for( size_t i = 0; i < index; ++i )
61  iter++;
62  return iter;
63  }
64 
65  typename a2dlist<T>::iterator item( size_t index )
66  {
67  typename a2dlist<T>::iterator iter = this->begin();
68  for( size_t i = 0; i < index; ++i )
69  iter++;
70  return iter;
71  }
72 
73  typename a2dlist<T>::reverse_iterator rerase( typename std::list< T, std::allocator< T > >::reverse_iterator iterr )
74  {
75  typename std::list< T, std::allocator< T > >::iterator it( iterr.base() ) ;
76  iterr++;
77  -- it ;
78  this->erase( it ) ;
79  return iterr;
80  }
81 
82  //! get the previous node ( --end() if no previous )
83  typename std::list< T, std::allocator< T > >::iterator GetPreviousAround( typename std::list< T, std::allocator< T > >::iterator iter )
84  {
85  if ( this->size() )
86  {
87  if ( iter == this->begin() )
88  return --( this->end() );
89  return --iter;
90  }
91  return this->begin();
92  }
93 
94  //! get the next node ( begin() if no next )
95  typename std::list< T, std::allocator< T > >::iterator GetNextAround( typename std::list< T, std::allocator< T > >::iterator iter )
96  {
97  if ( this->size() )
98  {
99  if ( iter == --( this->end() ) )
100  return this->begin();
101  return ++iter;
102  }
103  return this->begin();
104  }
105 };
106 
107 //! easy iteration for a2dlist
108 /*!
109  \ingroup general
110 */
111 #define forEachIn( listtype, list ) \
112  for( listtype::iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
113 
114 //! easy const iteration for a2dlist
115 /*!
116  \ingroup general
117 */
118 #define const_forEachIn( listtype, list ) \
119  for( listtype::const_iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
120 
121 #include "a2dlist.inl"
122 
123 /*
124 // minimal wrap to be able to use wxWidget or Stl hash implementation.
125 #if 0
126  #ifdef _MSC_VER
127  #include <hash_map>
128  // In case of compiler problems, please add more checks.
129  #if _MSC_VER > 1300
130  #define a2dHashMap stdext::hash_map
131  #else
132  #define a2dHashMap std::hash_map
133  #endif
134  #endif // _MSC_VER
135  #ifdef __GNUG__
136  #include <ext/hash_map>
137  #define a2dHashMap __gnu_cxx::hash_map
138  #endif // __GNUG__
139 #else
140  template <class Key, class Type> class a2dHashMap
141  {
142  public:
143  class KeyHash
144  {
145  public:
146  unsigned long operator()( const Key& k ) const { return (unsigned long) &k; }
147  KeyHash& operator=(const KeyHash&) { return *this; }
148  };
149  class KeyEqual
150  {
151  public:
152  bool operator()( const Key& a, const Key& b ) const { return ( &a == &b ); }
153  KeyEqual& operator=(const KeyEqual&) { return *this; }
154  };
155  WX_DECLARE_HASH_MAP( Key, Type, KeyHash, KeyEqual, wxhash );
156  public:
157  Type& operator[](const Key& key) { return m_hash[ key ]; }
158  void erase( Key& key ) { m_hash.erase( key ); }
159  void clear() { m_hash.clear(); }
160  protected:
161  wxhash m_hash;
162  };
163 #endif
164 */
165 
166 
167 
168 
169 
170 #endif // __A2DLIST_H__
a2dlist()
Default constructor.
Definition: a2dlist.h:47
basic list class based on STL containers.
std list compatible list
Definition: a2dlist.h:42
std::list< T, std::allocator< T > >::iterator GetPreviousAround(typename std::list< T, std::allocator< T > >::iterator iter)
get the previous node ( –end() if no previous )
Definition: a2dlist.h:83
the settings used by all other include files are stored here.
std::list< T, std::allocator< T > >::iterator GetNextAround(typename std::list< T, std::allocator< T > >::iterator iter)
get the next node ( begin() if no next )
Definition: a2dlist.h:95
~a2dlist()
Destructor.
Definition: a2dlist.inl:28
A pointer class, that automatically calls SmrtPtrOwn/SmrtPtrRelease.
Definition: a2dlist.h:20
a2dlist.h Source File -- Sun Oct 12 2014 17:04:12 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation