00001
00002
00011 #ifndef ATHCONTAINERS_TOOLS_DVLITERATOR_H
00012 #define ATHCONTAINERS_TOOLS_DVLITERATOR_H
00013
00014
00015 #include "AthContainers/OwnershipPolicy.h"
00016 #include "AthContainers/tools/DVLCast.h"
00017 #include "AthContainers/tools/ElementProxy.h"
00018 #include <boost/iterator/iterator_adaptor.hpp>
00019 #include <boost/version.hpp>
00020 #include <iterator>
00021 #include <cstdlib>
00022
00023
00024 #if BOOST_VERSION < 105000
00025 namespace boost { namespace detail {
00026
00027
00039 template <class T, class U>
00040 struct operator_arrow_result<T*,
00041 DataModel_detail::ElementProxy<U>,
00042 T**>
00043 {
00044 public:
00045 typedef T* ValueType;
00046 typedef DataModel_detail::ElementProxy<U> Reference;
00047 typedef T** Pointer;
00048 typedef Pointer type;
00049 static type make (Reference ) { std::abort(); return 0; }
00050 };
00051
00052
00053 }}
00054 #endif
00055
00056
00057 namespace DataModel_detail {
00058
00059
00076 template <class DVL>
00077 class const_iterator
00078 {
00079 public:
00081 typedef typename DVL::const_value_type value_type;
00082 typedef value_type reference;
00083 typedef value_type* pointer;
00084 typedef typename DVL::BaseContainer::const_iterator::difference_type difference_type;
00085 typedef typename DVL::BaseContainer::const_iterator::iterator_category iterator_category;
00086
00087 typedef DVL Container;
00088 typedef typename DVL::BaseContainer BaseContainer;
00089
00090
00094 const_iterator() {}
00095
00096
00101 const_iterator (typename BaseContainer::const_iterator it)
00102 : m_it (it)
00103 {}
00104
00105
00107 reference operator*() const { return dereference(); }
00108 reference operator[] (difference_type n) const
00109 { const_iterator tmp = *this + n; return *tmp; }
00110
00111
00113 const_iterator& operator++() { ++m_it; return *this; }
00114 const_iterator operator++(int)
00115 { const_iterator tmp = *this; ++m_it; return tmp; }
00116 const_iterator& operator--() { --m_it; return *this; }
00117 const_iterator operator--(int)
00118 { const_iterator tmp = *this; --m_it; return tmp; }
00119
00120
00122 const_iterator& operator+= (difference_type n) { m_it += n; return *this; }
00123 const_iterator& operator-= (difference_type n) { m_it -= n; return *this; }
00124 const_iterator operator+ (difference_type n) const { const_iterator tmp = *this; tmp += n; return tmp; }
00125 const_iterator operator- (difference_type n) const { const_iterator tmp = *this; tmp -= n; return tmp; }
00126 difference_type operator- (const_iterator other) const { return m_it - other.m_it; }
00127
00128
00130 bool operator== (const const_iterator& other) const { return m_it == other.m_it; }
00131 bool operator!= (const const_iterator& other) const { return m_it != other.m_it; }
00132 bool operator< (const const_iterator& other) const { return m_it < other.m_it; }
00133 bool operator> (const const_iterator& other) const { return m_it > other.m_it; }
00134 bool operator<= (const const_iterator& other) const { return m_it <= other.m_it; }
00135 bool operator>= (const const_iterator& other) const { return m_it >= other.m_it; }
00136
00137
00138 private:
00140 typename BaseContainer::const_iterator m_it;
00141
00146 const typename DVL::value_type dereference() const
00147 {
00148 return DataModel_detail::DVLCast<DVL>::cast (*m_it);
00149 }
00150 };
00151
00152
00166 template <class DVL>
00167 class iterator
00168 : public boost::iterator_adaptor<iterator<DVL>,
00169 typename DVL::BaseContainer::iterator,
00170 typename DVL::value_type,
00171
00172
00173
00174
00175
00176
00177 typename DVL::BaseContainer::
00178 const_iterator::iterator_category,
00179 typename DVL::ElementProxy>
00180 {
00181 private:
00182
00183 typedef boost::iterator_adaptor<iterator,
00184 typename DVL::BaseContainer::iterator,
00185 typename DVL::value_type,
00186
00187 typename DVL::BaseContainer::
00188 const_iterator::iterator_category,
00189 typename DVL::ElementProxy> iterator_adaptor_;
00190
00191
00192 typedef typename DVL::ElementProxy ElementProxy;
00193 typedef typename DVL::const_iterator const_iterator;
00194
00195
00196 public:
00197 typedef DVL Container;
00198 typedef typename DVL::BaseContainer BaseContainer;
00199
00200
00204 iterator() :
00205 m_container(0)
00206 {}
00207
00208
00214 iterator (typename BaseContainer::iterator it,
00215 DVL* container)
00216 : iterator_adaptor_ (it),
00217 m_container (container)
00218 {}
00219
00220
00228 ElementProxy operator[] (int n) const
00229 {
00230 return ElementProxy (this->base()+n, m_container);
00231 }
00232
00233
00239 operator const_iterator() const
00240 {
00241 return const_iterator (this->base());
00242 }
00243
00244
00248 DVL* container() const
00249 {
00250 return m_container;
00251 }
00252
00253
00258 SG::OwnershipPolicy ownPolicy() const
00259 {
00260 return m_container->ownPolicy();
00261 }
00262
00263
00268 void testInsert (const char* op)
00269 {
00270 m_container->testInsert (op);
00271 }
00272
00273
00274
00275 bool operator== (const iterator& i) const { return this->base() == i.base();}
00276 bool operator!= (const iterator& i) const { return this->base() != i.base();}
00277 bool operator< (const iterator& i) const { return this->base() < i.base();}
00278 bool operator> (const iterator& i) const { return this->base() > i.base();}
00279 bool operator<= (const iterator& i) const { return this->base() <= i.base();}
00280 bool operator>= (const iterator& i) const { return this->base() >= i.base();}
00281
00282
00283 bool operator== (const const_iterator& i) const
00284 { return static_cast<const_iterator>(*this)==i; }
00285 bool operator!= (const const_iterator& i) const
00286 { return static_cast<const_iterator>(*this)!=i; }
00287 bool operator< (const const_iterator& i) const
00288 { return static_cast<const_iterator>(*this)<i; }
00289 bool operator> (const const_iterator& i) const
00290 { return static_cast<const_iterator>(*this)>i; }
00291 bool operator<= (const const_iterator& i) const
00292 { return static_cast<const_iterator>(*this)<=i; }
00293 bool operator>= (const const_iterator& i) const
00294 { return static_cast<const_iterator>(*this)>=i; }
00295
00296
00297 typename iterator_adaptor_::difference_type
00298 operator- (const iterator& i) const
00299 { return this->base() - i.base(); }
00300 iterator operator- (typename iterator_adaptor_::difference_type i) const
00301 { return iterator (this->base() - i, m_container); }
00302 typename iterator_adaptor_::difference_type
00303 operator- (const const_iterator& i) const
00304 { return static_cast<const_iterator>(*this) - i; }
00305
00306
00307 private:
00308 typename DVL::pointer operator-> ();
00309
00310
00311 friend class boost::iterator_core_access;
00312
00313
00318 ElementProxy dereference() const
00319 {
00320 return ElementProxy (this->base(), m_container);
00321 }
00322
00323
00325 DVL* m_container;
00326 };
00327
00328
00329 }
00330
00331
00332
00333
00334 template <class DVL>
00335 inline
00336 bool operator== (const typename DVL::const_iterator& i1,
00337 const DataModel_detail::iterator<DVL>& i2)
00338 {
00339 return i1 == typename DVL::const_iterator (i2);
00340 }
00341 template <class DVL>
00342 inline
00343 bool operator!= (typename DVL::const_iterator i1,
00344 DataModel_detail::iterator<DVL> i2)
00345 {
00346 return i1 != typename DVL::const_iterator (i2);
00347 }
00348 template <class DVL>
00349 inline
00350 bool operator< (typename DVL::const_iterator i1,
00351 DataModel_detail::iterator<DVL> i2)
00352 {
00353 return i1 < typename DVL::const_iterator (i2);
00354 }
00355 template <class DVL>
00356 inline
00357 bool operator> (typename DVL::const_iterator i1,
00358 DataModel_detail::iterator<DVL> i2)
00359 {
00360 return i1 > typename DVL::const_iterator (i2);
00361 }
00362 template <class DVL>
00363 inline
00364 bool operator<= (typename DVL::const_iterator i1,
00365 DataModel_detail::iterator<DVL> i2)
00366 {
00367 return i1 <= typename DVL::const_iterator (i2);
00368 }
00369 template <class DVL>
00370 inline
00371 bool operator>= (typename DVL::const_iterator i1,
00372 DataModel_detail::iterator<DVL> i2)
00373 {
00374 return i1 >= typename DVL::const_iterator (i2);
00375 }
00376
00377
00378 template <class DVL>
00379 inline
00380 typename DVL::const_iterator::difference_type
00381 operator- (typename DVL::const_iterator i1,
00382 DataModel_detail::iterator<DVL> i2)
00383 {
00384 return i1 - typename DVL::const_iterator (i2);
00385 }
00386
00387
00388 #endif // not ATHCONTAINERS_TOOLS_DVLITERATOR_H