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-2026 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 <iterator>
24#include <cstdlib>
25
26namespace DataModel_detail {
27
28
45template <class DVL>
47{
48public:
50 typedef typename DVL::const_value_type value_type;
53 typedef typename DVL::BaseContainer::const_iterator::difference_type difference_type;
54 typedef typename DVL::BaseContainer::const_iterator::iterator_category iterator_category;
55
56 typedef DVL Container;
57 typedef typename DVL::BaseContainer BaseContainer;
58
59
64
65
70 const_iterator (typename BaseContainer::const_iterator it)
71 : m_it (it)
72 {}
73
74
76 reference operator*() const { return dereference(); }
78 { const_iterator tmp = *this + n; return *tmp; }
79
80
82 const_iterator& operator++() { ++m_it; return *this; }
84 { const_iterator tmp = *this; ++m_it; return tmp; }
85 const_iterator& operator--() { --m_it; return *this; }
87 { const_iterator tmp = *this; --m_it; return tmp; }
88
89
91 const_iterator& operator+= (difference_type n) { m_it += n; return *this; }
92 const_iterator& operator-= (difference_type n) { m_it -= n; return *this; }
93 const_iterator operator+ (difference_type n) const { const_iterator tmp = *this; tmp += n; return tmp; }
94 const_iterator operator- (difference_type n) const { const_iterator tmp = *this; tmp -= n; return tmp; }
95 difference_type operator- (const_iterator other) const { return m_it - other.m_it; }
96
97
99 bool operator== (const const_iterator& other) const { return m_it == other.m_it; }
100 bool operator!= (const const_iterator& other) const { return m_it != other.m_it; }
101 bool operator< (const const_iterator& other) const { return m_it < other.m_it; }
102 bool operator> (const const_iterator& other) const { return m_it > other.m_it; }
103 bool operator<= (const const_iterator& other) const { return m_it <= other.m_it; }
104 bool operator>= (const const_iterator& other) const { return m_it >= other.m_it; }
105
106
107private:
109 typename BaseContainer::const_iterator m_it;
110
115 const typename DVL::value_type dereference() const
116 {
118 }
119};
120
121
135template <class DVL>
137 : public boost::iterator_adaptor<iterator<DVL>,
138 typename DVL::BaseContainer::iterator,
139 typename DVL::value_type, // Value
140 // Note: Can't use boost::use_default here.
141 // Otherwise, we get boost's new-fangled
142 // iterator categories, which won't work
143 // with libstdc++'s implementation
144 // of sort().
145 // CategoryOrTraversal
146 typename DVL::BaseContainer::
147 const_iterator::iterator_category,
148 typename DVL::ElementProxy> // Reference
149{
150private:
151 // Shorthand for the base class type.
152 typedef boost::iterator_adaptor<iterator,
153 typename DVL::BaseContainer::iterator,
154 typename DVL::value_type, // Value
155 // CategoryOrTraversal
156 typename DVL::BaseContainer::
157 const_iterator::iterator_category,
158 typename DVL::ElementProxy> iterator_adaptor_;
159
160 // Copy some other names
161 typedef typename DVL::ElementProxy ElementProxy;
162 typedef typename DVL::const_iterator const_iterator;
163
164
165public:
166 typedef DVL Container;
167 typedef typename DVL::BaseContainer BaseContainer;
168
169
174 m_container(0)
175 {}
176
177
183 iterator (typename BaseContainer::iterator it,
184 DVL* container)
185 : iterator_adaptor_ (it),
187 {}
188
189
198 {
200 return ElementProxy (this->base()+n, container);
201 }
202
203
209 operator const_iterator() const
210 {
211 return const_iterator (this->base());
212 }
213
214
219 {
220 return m_container;
221 }
222
223
227 const DVL* container() const
228 {
229 return m_container;
230 }
231
232
238 {
239 return m_container->ownPolicy();
240 }
241
242
247 void testInsert (const char* op)
248 {
249 m_container->testInsert (op);
250 }
251
252
253 // These are needed for iterator/const_iterator comparisons to work.
254 bool operator== (const iterator& i) const { return this->base() == i.base();}
255 bool operator!= (const iterator& i) const { return this->base() != i.base();}
256 bool operator< (const iterator& i) const { return this->base() < i.base();}
257 bool operator> (const iterator& i) const { return this->base() > i.base();}
258 bool operator<= (const iterator& i) const { return this->base() <= i.base();}
259 bool operator>= (const iterator& i) const { return this->base() >= i.base();}
260
261 // These are needed for iterator/const_iterator comparisons to work.
262 bool operator== (const const_iterator& i) const
263 { return static_cast<const_iterator>(*this)==i; }
264 bool operator!= (const const_iterator& i) const
265 { return static_cast<const_iterator>(*this)!=i; }
266 bool operator< (const const_iterator& i) const
267 { return static_cast<const_iterator>(*this)<i; }
268 bool operator> (const const_iterator& i) const
269 { return static_cast<const_iterator>(*this)>i; }
270 bool operator<= (const const_iterator& i) const
271 { return static_cast<const_iterator>(*this)<=i; }
272 bool operator>= (const const_iterator& i) const
273 { return static_cast<const_iterator>(*this)>=i; }
274
275 // These overloads are needed for iterator-const_iterator to work.
276 typename iterator_adaptor_::difference_type
277 operator- (const iterator& i) const
278 { return this->base() - i.base(); }
279 iterator operator- (typename iterator_adaptor_::difference_type i) const
280 {
282 return iterator (this->base() - i, container);
283 }
284 typename iterator_adaptor_::difference_type
286 { return static_cast<const_iterator>(*this) - i; }
287
288
289private:
290 typename DVL::pointer operator-> ();
291
292 // Required for iterator_adaptor to work.
293 friend class boost::iterator_core_access;
294
295
301 {
303 return ElementProxy (this->base(), container);
304 }
305
306
309};
310
311
312} // namespace DataModel_detail
313
314
315// We need to define these to allow comparisons of
316// iterator and const_iterator.
317template <class DVL>
318inline
319bool operator== (const typename DVL::const_iterator& i1,
321{
322 return i1 == typename DVL::const_iterator (i2);
323}
324template <class DVL>
325inline
326bool operator!= (typename DVL::const_iterator i1,
328{
329 return i1 != typename DVL::const_iterator (i2);
330}
331template <class DVL>
332inline
333bool operator< (typename DVL::const_iterator i1,
335{
336 return i1 < typename DVL::const_iterator (i2);
337}
338template <class DVL>
339inline
340bool operator> (typename DVL::const_iterator i1,
342{
343 return i1 > typename DVL::const_iterator (i2);
344}
345template <class DVL>
346inline
347bool operator<= (typename DVL::const_iterator i1,
349{
350 return i1 <= typename DVL::const_iterator (i2);
351}
352template <class DVL>
353inline
354bool operator>= (typename DVL::const_iterator i1,
356{
357 return i1 >= typename DVL::const_iterator (i2);
358}
359
360// This overloads is needed for const_iterator-iterator to work.
361template <class DVL>
362inline
363typename DVL::const_iterator::difference_type
364operator- (typename DVL::const_iterator i1,
366{
367 return i1 - typename DVL::const_iterator (i2);
368}
369
370
371#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.
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:54
const_iterator()
Default constructor.
Definition DVLIterator.h:63
reference operator*() const
Dereference. Operator-> doesn't make sense here.
Definition DVLIterator.h:76
const_iterator operator-(difference_type n) const
Definition DVLIterator.h:94
bool operator==(const const_iterator &other) const
Comparisons.
Definition DVLIterator.h:99
const DVL::value_type dereference() const
Dereference the iterator.
bool operator!=(const const_iterator &other) const
const_iterator(typename BaseContainer::const_iterator it)
Constructor.
Definition DVLIterator.h:70
DataVector::const_value_type value_type
Definition DVLIterator.h:50
const_iterator operator--(int)
Definition DVLIterator.h:86
DataVector::BaseContainer::const_iterator::difference_type difference_type
Definition DVLIterator.h:53
const_iterator & operator+=(difference_type n)
Arithmetic.
Definition DVLIterator.h:91
const_iterator & operator-=(difference_type n)
Definition DVLIterator.h:92
const_iterator & operator++()
Increment / decrement.
Definition DVLIterator.h:82
const_iterator operator+(difference_type n) const
Definition DVLIterator.h:93
const_iterator operator++(int)
Definition DVLIterator.h:83
bool operator<=(const const_iterator &other) const
const_iterator & operator--()
Definition DVLIterator.h:85
reference operator[](difference_type n) const
Definition DVLIterator.h:77
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:83
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