ATLAS Offline Software
Loading...
Searching...
No Matches
SGIterator.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4/*
5 */
6/**
7 * @file StoreGate/SGIterator.icc
8 * @brief A standard conforming forward iterator over items in StoreGate.
9 */
10
11
12/**
13 * @brief Equality check.
14 */
15inline
16bool SG::detail::IteratorBase::eql (const IteratorBase& rhs) const
17{
18 if (m_proxies.size() != rhs.m_proxies.size()) return false;
19 if (m_proxies.empty()) return true;
20 return m_proxies.back() == rhs.m_proxies.back();
21}
22
23
24/**
25 * @brief The proxy pointed at by this iterator.
26 */
27inline
28SG::DataProxy* SG::detail::IteratorBase::proxy() const
29{
30 return m_proxies.back();
31}
32
33
34/**
35 * @brief Add a reference count to all proxies in our range.
36 */
37inline
38void SG::detail::IteratorBase::addRef()
39{
40 for (DataProxy* dp : m_proxies) {
41 dp->addRef();
42 }
43}
44
45
46/**
47 * @brief Remove a reference count from all proxies in our range.
48 */
49inline
50void SG::detail::IteratorBase::release()
51{
52 for (DataProxy* dp : m_proxies) {
53 dp->release();
54 }
55}
56
57
58/**
59 * @brief Default constructor.
60 */
61template <class DATA>
62inline
63SG::ConstIterator<DATA>::ConstIterator()
64 : detail::IteratorBase()
65{
66}
67
68
69/**
70 * @brief Constructor from proxy iterator pair.
71 * @param itr Starting proxy iterator.
72 * @param itrEnd Ending proxy iterator.
73 *
74 * Will skip ahead to the first valid proxy.
75 */
76template <class DATA>
77inline
78SG::ConstIterator<DATA>::ConstIterator (const SG::ConstProxyIterator& itr,
79 const SG::ConstProxyIterator& itrEnd)
80 : detail::IteratorBase (itr, itrEnd, true)
81{
82}
83
84
85/**
86 * @brief Reset state of the iterator.
87 * @param itr Starting proxy iterator.
88 * @param itrEnd Ending proxy iterator.
89 *
90 * Will skip ahead to the first valid proxy.
91 * Will return failure if the range is empty.
92 */
93template <class DATA>
94inline
95StatusCode
96SG::ConstIterator<DATA>::setState (const SG::ConstProxyIterator& itr,
97 const SG::ConstProxyIterator& itrEnd)
98{
99 return detail::IteratorBase::setState (itr, itrEnd, true);
100}
101
102
103/**
104 * @brief Equality check.
105 *
106 * Used by the boost iterator adapter.
107 */
108template <class DATA>
109inline
110bool SG::ConstIterator<DATA>::equal(const ConstIterator& rhs) const
111{
112 return detail::IteratorBase::eql(rhs);
113}
114
115
116/**
117 * @brief Dereference the iterator.
118 *
119 * Used by the boost iterator adapter.
120 *
121 * Will throw SG::ExcInvalidIterator() if the proxy is not valid.
122 */
123template <class DATA>
124const DATA& SG::ConstIterator<DATA>::dereference() const
125{
126 const DATA* ptr = SG::DataProxy_cast<DATA> (this->proxy());
127 if (!ptr) {
128 throw SG::ExcInvalidIterator();
129 }
130 return *ptr;
131}
132
133
134/**
135 * @brief Default constructor.
136 */
137template <class DATA>
138inline
139SG::Iterator<DATA>::Iterator()
140 : detail::IteratorBase()
141{
142}
143
144
145/**
146 * @brief Constructor from proxy iterator pair.
147 * @param itr Starting proxy iterator.
148 * @param itrEnd Ending proxy iterator.
149 *
150 * Will skip ahead to the first valid proxy.
151 */
152template <class DATA>
153inline
154SG::Iterator<DATA>::Iterator (const SG::ConstProxyIterator& itr,
155 const SG::ConstProxyIterator& itrEnd)
156 : detail::IteratorBase (itr, itrEnd, false)
157{
158}
159
160
161/**
162 * @brief Reset state of the iterator.
163 * @param itr Starting proxy iterator.
164 * @param itrEnd Ending proxy iterator.
165 *
166 * Will skip ahead to the first valid proxy.
167 * Will return failure if the first proxy is const or if the range is empty.
168 */
169template <class DATA>
170inline
171StatusCode
172SG::Iterator<DATA>::setState (const SG::ConstProxyIterator& itr,
173 const SG::ConstProxyIterator& itrEnd)
174{
175 return detail::IteratorBase::setState (itr, itrEnd, false);
176}
177
178
179/**
180 * @brief Equality check.
181 *
182 * Used by the boost iterator adapter.
183 */
184template <class DATA>
185inline
186bool SG::Iterator<DATA>::equal(const Iterator<DATA>& rhs) const
187{
188 return detail::IteratorBase::eql(rhs);
189}
190
191
192/**
193 * @brief Dereference the iterator.
194 *
195 * Used by the boost iterator adapter.
196 *
197 * Will throw SG::ExcInvalidIterator() if the proxy is not valid.
198 * Will throw SG::ExcConstObject if the proxy is const.
199 */
200template <class DATA>
201DATA& SG::Iterator<DATA>::dereference() const
202{
203 this->const_check();
204 DATA* ptr = SG::DataProxy_cast<DATA> (this->proxy());
205 if (!ptr) {
206 throw SG::ExcInvalidIterator();
207 }
208 return *ptr;
209}