ATLAS Offline Software
DVLIterator.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
14 #ifndef ATHCONTAINERS_TOOLS_DVLITERATOR_H
15 #define ATHCONTAINERS_TOOLS_DVLITERATOR_H
16 
17 
22 #include <boost/iterator/iterator_adaptor.hpp>
23 #include <boost/version.hpp>
24 #include <iterator>
25 #include <cstdlib>
26 
27 
28 #if BOOST_VERSION < 105000
29 namespace boost { namespace detail {
30 
31 
43 template <class T, class U>
44 struct operator_arrow_result<T*,
46  T**>
47 {
48 public:
49  typedef T* ValueType;
51  typedef T** Pointer;
52  typedef Pointer type;
53  static type make (Reference /*x*/) { std::abort(); return 0; }
54 };
55 
56 
57 }}
58 #endif
59 
60 
61 namespace DataModel_detail {
62 
63 
80 template <class DVL>
82 {
83 public:
85  typedef typename DVL::const_value_type value_type;
87  typedef value_type* pointer;
88  typedef typename DVL::BaseContainer::const_iterator::difference_type difference_type;
89  typedef typename DVL::BaseContainer::const_iterator::iterator_category iterator_category;
90 
91  typedef DVL Container;
93 
94 
99 
100 
105  const_iterator (typename BaseContainer::const_iterator it)
106  : m_it (it)
107  {}
108 
109 
111  reference operator*() const { return dereference(); }
113  { const_iterator tmp = *this + n; return *tmp; }
114 
115 
117  const_iterator& operator++() { ++m_it; return *this; }
119  { const_iterator tmp = *this; ++m_it; return tmp; }
120  const_iterator& operator--() { --m_it; return *this; }
122  { const_iterator tmp = *this; --m_it; return tmp; }
123 
124 
131 
132 
134  bool operator== (const const_iterator& other) const { return m_it == other.m_it; }
135  bool operator!= (const const_iterator& other) const { return m_it != other.m_it; }
136  bool operator< (const const_iterator& other) const { return m_it < other.m_it; }
137  bool operator> (const const_iterator& other) const { return m_it > other.m_it; }
138  bool operator<= (const const_iterator& other) const { return m_it <= other.m_it; }
139  bool operator>= (const const_iterator& other) const { return m_it >= other.m_it; }
140 
141 
142 private:
144  typename BaseContainer::const_iterator m_it;
145 
150  const typename DVL::value_type dereference() const
151  {
153  }
154 };
155 
156 
170 template <class DVL>
171 class iterator
172  : public boost::iterator_adaptor<iterator<DVL>,
173  typename DVL::BaseContainer::iterator,
174  typename DVL::value_type, // Value
175  // Note: Can't use boost::use_default here.
176  // Otherwise, we get boost's new-fangled
177  // iterator categories, which won't work
178  // with libstdc++'s implementation
179  // of sort().
180  // CategoryOrTraversal
181  typename DVL::BaseContainer::
182  const_iterator::iterator_category,
183  typename DVL::ElementProxy> // Reference
184 {
185 private:
186  // Shorthand for the base class type.
187  typedef boost::iterator_adaptor<iterator,
189  typename DVL::value_type, // Value
190  // CategoryOrTraversal
191  typename DVL::BaseContainer::
192  const_iterator::iterator_category,
193  typename DVL::ElementProxy> iterator_adaptor_;
194 
195  // Copy some other names
196  typedef typename DVL::ElementProxy ElementProxy;
197  typedef typename DVL::const_iterator const_iterator;
198 
199 
200 public:
201  typedef DVL Container;
203 
204 
209  m_container(0)
210  {}
211 
212 
219  DVL* container)
220  : iterator_adaptor_ (it),
222  {}
223 
224 
233  {
235  return ElementProxy (this->base()+n, container);
236  }
237 
238 
244  operator const_iterator() const
245  {
246  return const_iterator (this->base());
247  }
248 
249 
253  DVL* container()
254  {
255  return m_container;
256  }
257 
258 
262  const DVL* container() const
263  {
264  return m_container;
265  }
266 
267 
273  {
274  return m_container->ownPolicy();
275  }
276 
277 
282  void testInsert (const char* op)
283  {
284  m_container->testInsert (op);
285  }
286 
287 
288  // These are needed for iterator/const_iterator comparisons to work.
289  bool operator== (const iterator& i) const { return this->base() == i.base();}
290  bool operator!= (const iterator& i) const { return this->base() != i.base();}
291  bool operator< (const iterator& i) const { return this->base() < i.base();}
292  bool operator> (const iterator& i) const { return this->base() > i.base();}
293  bool operator<= (const iterator& i) const { return this->base() <= i.base();}
294  bool operator>= (const iterator& i) const { return this->base() >= i.base();}
295 
296  // These are needed for iterator/const_iterator comparisons to work.
297  bool operator== (const const_iterator& i) const
298  { return static_cast<const_iterator>(*this)==i; }
299  bool operator!= (const const_iterator& i) const
300  { return static_cast<const_iterator>(*this)!=i; }
301  bool operator< (const const_iterator& i) const
302  { return static_cast<const_iterator>(*this)<i; }
303  bool operator> (const const_iterator& i) const
304  { return static_cast<const_iterator>(*this)>i; }
305  bool operator<= (const const_iterator& i) const
306  { return static_cast<const_iterator>(*this)<=i; }
307  bool operator>= (const const_iterator& i) const
308  { return static_cast<const_iterator>(*this)>=i; }
309 
310  // These overloads are needed for iterator-const_iterator to work.
311  typename iterator_adaptor_::difference_type
312  operator- (const iterator& i) const
313  { return this->base() - i.base(); }
314  iterator operator- (typename iterator_adaptor_::difference_type i) const
315  {
317  return iterator (this->base() - i, container);
318  }
319  typename iterator_adaptor_::difference_type
321  { return static_cast<const_iterator>(*this) - i; }
322 
323 
324 private:
325  typename DVL::pointer operator-> ();
326 
327  // Required for iterator_adaptor to work.
329 
330 
336  {
338  return ElementProxy (this->base(), container);
339  }
340 
341 
344 };
345 
346 
347 } // namespace DataModel_detail
348 
349 
350 // We need to define these to allow comparisons of
351 // iterator and const_iterator.
352 template <class DVL>
353 inline
354 bool operator== (const typename DVL::const_iterator& i1,
356 {
357  return i1 == typename DVL::const_iterator (i2);
358 }
359 template <class DVL>
360 inline
361 bool operator!= (typename DVL::const_iterator i1,
363 {
364  return i1 != typename DVL::const_iterator (i2);
365 }
366 template <class DVL>
367 inline
368 bool operator< (typename DVL::const_iterator i1,
370 {
371  return i1 < typename DVL::const_iterator (i2);
372 }
373 template <class DVL>
374 inline
375 bool operator> (typename DVL::const_iterator i1,
377 {
378  return i1 > typename DVL::const_iterator (i2);
379 }
380 template <class DVL>
381 inline
382 bool operator<= (typename DVL::const_iterator i1,
384 {
385  return i1 <= typename DVL::const_iterator (i2);
386 }
387 template <class DVL>
388 inline
389 bool operator>= (typename DVL::const_iterator i1,
391 {
392  return i1 >= typename DVL::const_iterator (i2);
393 }
394 
395 // This overloads is needed for const_iterator-iterator to work.
396 template <class DVL>
397 inline
398 typename DVL::const_iterator::difference_type
399 operator- (typename DVL::const_iterator i1,
401 {
402  return i1 - typename DVL::const_iterator (i2);
403 }
404 
405 
406 #endif // not ATHCONTAINERS_TOOLS_DVLITERATOR_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
base
std::string base
Definition: hcg.cxx:78
DataModel_detail::const_iterator::operator+=
const_iterator & operator+=(difference_type n)
Arithmetic.
Definition: DVLIterator.h:126
DataModel_detail::iterator::operator>=
bool operator>=(const iterator &i) const
Definition: DVLIterator.h:294
boost::detail::operator_arrow_result< T *, DataModel_detail::ElementProxy< U >, T ** >::Reference
DataModel_detail::ElementProxy< U > Reference
Definition: DVLIterator.h:50
operator>=
bool operator>=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:389
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
DataModel_detail::iterator::operator<=
bool operator<=(const iterator &i) const
Definition: DVLIterator.h:293
DataModel_detail::iterator::operator[]
ElementProxy operator[](int n) const
Element access.
Definition: DVLIterator.h:232
DataModel_detail::iterator::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy of the container from which this iterator was created.
Definition: DVLIterator.h:272
DataModel_detail::iterator::iterator_adaptor_
boost::iterator_adaptor< iterator, typename DVL::BaseContainer::iterator, typename DVL::value_type, typename DVL::BaseContainer::const_iterator::iterator_category, typename DVL::ElementProxy > iterator_adaptor_
Definition: DVLIterator.h:193
boost::detail::operator_arrow_result< T *, DataModel_detail::ElementProxy< U >, T ** >::Pointer
T ** Pointer
Definition: DVLIterator.h:51
skel.it
it
Definition: skel.GENtoEVGEN.py:396
DataModel_detail::const_iterator::dereference
const DVL::value_type dereference() const
Dereference the iterator.
Definition: DVLIterator.h:150
operator<=
bool operator<=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:382
detail
Definition: extract_histogram_tag.cxx:14
DataModel_detail::const_iterator::reference
value_type reference
Definition: DVLIterator.h:86
boost
Definition: DVLIterator.h:29
reference
Definition: hcg.cxx:437
DataModel_detail::const_iterator::BaseContainer
DVL::BaseContainer BaseContainer
Definition: DVLIterator.h:92
DataModel_detail::const_iterator::operator--
const_iterator & operator--()
Definition: DVLIterator.h:120
DataModel_detail::const_iterator::operator-
const_iterator operator-(difference_type n) const
Definition: DVLIterator.h:129
DataModel_detail::iterator::operator==
bool operator==(const iterator &i) const
Definition: DVLIterator.h:289
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
boost::detail::operator_arrow_result< T *, DataModel_detail::ElementProxy< U >, T ** >::ValueType
T * ValueType
Definition: DVLIterator.h:49
operator<
bool operator<(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:368
DataModel_detail::const_iterator::value_type
DVL::const_value_type value_type
Standard iterator typedefs.
Definition: DVLIterator.h:85
operator==
bool operator==(const typename DVL::const_iterator &i1, const DataModel_detail::iterator< DVL > &i2)
Definition: DVLIterator.h:354
DataModel_detail::iterator::iterator_core_access
friend class boost::iterator_core_access
Definition: DVLIterator.h:328
boost::detail::operator_arrow_result< T *, DataModel_detail::ElementProxy< U >, T ** >::make
static type make(Reference)
Definition: DVLIterator.h:53
DataModel_detail::const_iterator::operator<=
bool operator<=(const const_iterator &other) const
Definition: DVLIterator.h:138
operator>
bool operator>(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:375
DataModel_detail::const_iterator::operator*
reference operator*() const
Dereference. Operator-> doesn't make sense here.
Definition: DVLIterator.h:111
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
DataModel_detail::iterator::operator<
bool operator<(const iterator &i) const
Definition: DVLIterator.h:291
DataModel_detail::const_iterator::iterator_category
DVL::BaseContainer::const_iterator::iterator_category iterator_category
Definition: DVLIterator.h:89
beamspotman.n
n
Definition: beamspotman.py:731
DataModel_detail::const_iterator::Container
DVL Container
Definition: DVLIterator.h:91
DataModel_detail::iterator::operator!=
bool operator!=(const iterator &i) const
Definition: DVLIterator.h:290
operator!=
bool operator!=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:361
DataModel_detail::const_iterator::const_iterator
const_iterator(typename BaseContainer::const_iterator it)
Constructor.
Definition: DVLIterator.h:105
DataModel_detail::iterator::BaseContainer
DVL::BaseContainer BaseContainer
Definition: DVLIterator.h:202
DataModel_detail::iterator::iterator
iterator(typename BaseContainer::iterator it, DVL *container)
Constructor.
Definition: DVLIterator.h:218
boost::detail::operator_arrow_result< T *, DataModel_detail::ElementProxy< U >, T ** >::type
Pointer type
Definition: DVLIterator.h:52
DataModel_detail::const_iterator::operator>=
bool operator>=(const const_iterator &other) const
Definition: DVLIterator.h:139
OwnershipPolicy.h
DataModel_detail::iterator::testInsert
void testInsert(const char *op)
Test if we can insert; raise an exception if not.
Definition: DVLIterator.h:282
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
DataModel_detail::const_iterator::operator--
const_iterator operator--(int)
Definition: DVLIterator.h:121
DataModel_detail
Definition: CompareAndPrint.h:15
DataModel_detail::const_iterator::operator<
bool operator<(const const_iterator &other) const
Definition: DVLIterator.h:136
DataModel_detail::iterator::iterator
iterator()
Default constructor.
Definition: DVLIterator.h:208
DataModel_detail::const_iterator::operator>
bool operator>(const const_iterator &other) const
Definition: DVLIterator.h:137
DataModel_detail::iterator::m_container
DVL * m_container
The referenced container.
Definition: DVLIterator.h:343
DataModel_detail::iterator::ElementProxy
DVL::ElementProxy ElementProxy
Definition: DVLIterator.h:196
DataModel_detail::const_iterator::operator++
const_iterator & operator++()
Increment / decrement.
Definition: DVLIterator.h:117
DataModel_detail::iterator::operator->
DVL::pointer operator->()
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
DataModel_detail::iterator::const_iterator
DVL::const_iterator const_iterator
Definition: DVLIterator.h:197
DataModel_detail::iterator::operator-
iterator_adaptor_::difference_type operator-(const iterator &i) const
Definition: DVLIterator.h:312
DataModel_detail::const_iterator::operator-=
const_iterator & operator-=(difference_type n)
Definition: DVLIterator.h:127
DataModel_detail::const_iterator::difference_type
DVL::BaseContainer::const_iterator::difference_type difference_type
Definition: DVLIterator.h:88
DataModel_detail::const_iterator::operator==
bool operator==(const const_iterator &other) const
Comparisons.
Definition: DVLIterator.h:134
DataModel_detail::const_iterator::const_iterator
const_iterator()
Default constructor.
Definition: DVLIterator.h:98
DataModel_detail::const_iterator::m_it
BaseContainer::const_iterator m_it
The wrapped iterator.
Definition: DVLIterator.h:144
operator-
DVL::const_iterator::difference_type operator-(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Definition: DVLIterator.h:399
DataModel_detail::const_iterator::operator+
const_iterator operator+(difference_type n) const
Definition: DVLIterator.h:128
DataModel_detail::const_iterator::operator++
const_iterator operator++(int)
Definition: DVLIterator.h:118
DataModel_detail::iterator::operator>
bool operator>(const iterator &i) const
Definition: DVLIterator.h:292
DataModel_detail::iterator::dereference
ElementProxy dereference() const
Dereference the iterator.
Definition: DVLIterator.h:335
DataModel_detail::ElementProxy
Proxy for lvalue access to DataVector/DataList elements.
Definition: ElementProxy.h:26
DataModel_detail::iterator::container
const DVL * container() const
Return the container holding the referenced element.
Definition: DVLIterator.h:262
DataModel_detail::ATLAS_THREAD_SAFE
dvl_tinfo_map_t *s_dvl_tinfo_map ATLAS_THREAD_SAFE
Definition: DVLInfo.cxx:41
DataModel_detail::const_iterator::operator[]
reference operator[](difference_type n) const
Definition: DVLIterator.h:112
DataModel_detail::iterator::container
DVL * container()
Return the container holding the referenced element.
Definition: DVLIterator.h:253
checker_macros.h
Define macros for attributes used to control the static checker.
value_type
Definition: EDM_MasterSearch.h:11
xAOD::BaseContainer
DataVector< SG::AuxElement > BaseContainer
Definition: BaseContainer.h:7
DataModel_detail::DVLCast
casting operations for DataVector/DataList.
Definition: DVLCast.h:49
DVLCast.h
casting operations for DataVector/DataList.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
DataModel_detail::const_iterator::operator!=
bool operator!=(const const_iterator &other) const
Definition: DVLIterator.h:135
DataModel_detail::iterator::Container
DVL Container
Definition: DVLIterator.h:201
ElementProxy.h
Proxy for lvalue access to DataVector/DataList elements.
DataModel_detail::const_iterator::pointer
value_type * pointer
Definition: DVLIterator.h:87