ATLAS Offline Software
Loading...
Searching...
No Matches
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*/
12
13
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
29namespace boost { namespace detail {
30
31
43template <class T, class U>
44struct operator_arrow_result<T*,
46 T**>
47{
48public:
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
61namespace DataModel_detail {
62
63
80template <class DVL>
82{
83public:
85 typedef typename DVL::const_value_type value_type;
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;
92 typedef typename DVL::BaseContainer BaseContainer;
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
126 const_iterator& operator+= (difference_type n) { m_it += n; return *this; }
127 const_iterator& operator-= (difference_type n) { m_it -= n; return *this; }
128 const_iterator operator+ (difference_type n) const { const_iterator tmp = *this; tmp += n; return tmp; }
129 const_iterator operator- (difference_type n) const { const_iterator tmp = *this; tmp -= n; return tmp; }
130 difference_type operator- (const_iterator other) const { return m_it - other.m_it; }
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
142private:
144 typename BaseContainer::const_iterator m_it;
145
150 const typename DVL::value_type dereference() const
151 {
153 }
154};
155
156
170template <class DVL>
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{
185private:
186 // Shorthand for the base class type.
187 typedef boost::iterator_adaptor<iterator,
188 typename DVL::BaseContainer::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
200public:
201 typedef DVL Container;
202 typedef typename DVL::BaseContainer BaseContainer;
203
204
209 m_container(0)
210 {}
211
212
218 iterator (typename BaseContainer::iterator it,
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
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
324private:
325 typename DVL::pointer operator-> ();
326
327 // Required for iterator_adaptor to work.
328 friend class boost::iterator_core_access;
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.
352template <class DVL>
353inline
354bool operator== (const typename DVL::const_iterator& i1,
356{
357 return i1 == typename DVL::const_iterator (i2);
358}
359template <class DVL>
360inline
361bool operator!= (typename DVL::const_iterator i1,
363{
364 return i1 != typename DVL::const_iterator (i2);
365}
366template <class DVL>
367inline
368bool operator< (typename DVL::const_iterator i1,
370{
371 return i1 < typename DVL::const_iterator (i2);
372}
373template <class DVL>
374inline
375bool operator> (typename DVL::const_iterator i1,
377{
378 return i1 > typename DVL::const_iterator (i2);
379}
380template <class DVL>
381inline
382bool operator<= (typename DVL::const_iterator i1,
384{
385 return i1 <= typename DVL::const_iterator (i2);
386}
387template <class DVL>
388inline
389bool 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.
396template <class DVL>
397inline
398typename DVL::const_iterator::difference_type
399operator- (typename DVL::const_iterator i1,
401{
402 return i1 - typename DVL::const_iterator (i2);
403}
404
405
406#endif // not ATHCONTAINERS_TOOLS_DVLITERATOR_H
casting operations for DataVector/DataList.
bool operator!=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
bool operator<=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
bool operator>(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
bool operator>=(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
bool operator<(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
bool operator==(const typename DVL::const_iterator &i1, const DataModel_detail::iterator< DVL > &i2)
DVL::const_iterator::difference_type operator-(typename DVL::const_iterator i1, DataModel_detail::iterator< DVL > i2)
Proxy for lvalue access to DataVector/DataList elements.
Define macros for attributes used to control the static checker.
Proxy for lvalue access to DataVector/DataList elements.
bool operator>(const const_iterator &other) const
bool operator>=(const const_iterator &other) const
DataVector::BaseContainer::const_iterator::iterator_category iterator_category
Definition DVLIterator.h:89
const_iterator()
Default constructor.
Definition DVLIterator.h:98
reference operator*() const
Dereference. Operator-> doesn't make sense here.
const_iterator operator-(difference_type n) const
bool operator==(const const_iterator &other) const
Comparisons.
const DVL::value_type dereference() const
Dereference the iterator.
bool operator!=(const const_iterator &other) const
const_iterator(typename BaseContainer::const_iterator it)
Constructor.
DataVector::const_value_type value_type
Definition DVLIterator.h:85
const_iterator operator--(int)
DataVector::BaseContainer::const_iterator::difference_type difference_type
Definition DVLIterator.h:88
const_iterator & operator+=(difference_type n)
Arithmetic.
const_iterator & operator-=(difference_type n)
const_iterator & operator++()
Increment / decrement.
const_iterator operator+(difference_type n) const
const_iterator operator++(int)
bool operator<=(const const_iterator &other) const
reference operator[](difference_type n) const
bool operator<(const const_iterator &other) const
(Non-const) Iterator class for DataVector/DataList.
bool operator>=(const iterator &i) const
ConstDataVector::BaseContainer BaseContainer
bool operator==(const iterator &i) const
ConstDataVector::ElementProxy ElementProxy
iterator(typename BaseContainer::iterator it, DVL *container)
Constructor.
boost::iterator_adaptor< iterator, typename ConstDataVector::BaseContainer::iterator, typename ConstDataVector::value_type, typename ConstDataVector::BaseContainer::const_iterator::iterator_category, typename ConstDataVector::ElementProxy > iterator_adaptor_
bool operator<=(const iterator &i) const
const DVL * container() const
Return the container holding the referenced element.
ConstDataVector::const_iterator const_iterator
void testInsert(const char *op)
Test if we can insert; raise an exception if not.
ElementProxy operator[](int n) const
Element access.
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy of the container from which this iterator was created.
ElementProxy dereference() const
Dereference the iterator.
bool operator<(const iterator &i) const
iterator()
Default constructor.
bool operator!=(const iterator &i) const
iterator_adaptor_::difference_type operator-(const iterator &i) const
bool operator>(const iterator &i) const
std::string base
Definition hcg.cxx:81
dvl_tinfo_map_t *s_dvl_tinfo_map ATLAS_THREAD_SAFE
Definition DVLInfo.cxx:41
OwnershipPolicy
casting operations for DataVector/DataList.
Definition DVLCast.h:49