2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
7 * @file StoreGate/SGIterator.icc
8 * @brief A standard conforming forward iterator over items in StoreGate.
13 * @brief Equality check.
16 bool SG::detail::IteratorBase::eql (const IteratorBase& rhs) const
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();
25 * @brief The proxy pointed at by this iterator.
28 SG::DataProxy* SG::detail::IteratorBase::proxy() const
30 return m_proxies.back();
35 * @brief Add a reference count to all proxies in our range.
38 void SG::detail::IteratorBase::addRef()
40 for (DataProxy* dp : m_proxies) {
47 * @brief Remove a reference count from all proxies in our range.
50 void SG::detail::IteratorBase::release()
52 for (DataProxy* dp : m_proxies) {
59 * @brief Default constructor.
63 SG::ConstIterator<DATA>::ConstIterator()
64 : detail::IteratorBase()
70 * @brief Constructor from proxy iterator pair.
71 * @param itr Starting proxy iterator.
72 * @param itrEnd Ending proxy iterator.
74 * Will skip ahead to the first valid proxy.
78 SG::ConstIterator<DATA>::ConstIterator (const SG::ConstProxyIterator& itr,
79 const SG::ConstProxyIterator& itrEnd)
80 : detail::IteratorBase (itr, itrEnd, true)
86 * @brief Reset state of the iterator.
87 * @param itr Starting proxy iterator.
88 * @param itrEnd Ending proxy iterator.
90 * Will skip ahead to the first valid proxy.
91 * Will return failure if the range is empty.
96 SG::ConstIterator<DATA>::setState (const SG::ConstProxyIterator& itr,
97 const SG::ConstProxyIterator& itrEnd)
99 return detail::IteratorBase::setState (itr, itrEnd, true);
104 * @brief Equality check.
106 * Used by the boost iterator adapter.
108 template <class DATA>
110 bool SG::ConstIterator<DATA>::equal(const ConstIterator& rhs) const
112 return detail::IteratorBase::eql(rhs);
117 * @brief Dereference the iterator.
119 * Used by the boost iterator adapter.
121 * Will throw SG::ExcInvalidIterator() if the proxy is not valid.
123 template <class DATA>
124 const DATA& SG::ConstIterator<DATA>::dereference() const
126 const DATA* ptr = SG::DataProxy_cast<DATA> (this->proxy());
128 throw SG::ExcInvalidIterator();
135 * @brief Default constructor.
137 template <class DATA>
139 SG::Iterator<DATA>::Iterator()
140 : detail::IteratorBase()
146 * @brief Constructor from proxy iterator pair.
147 * @param itr Starting proxy iterator.
148 * @param itrEnd Ending proxy iterator.
150 * Will skip ahead to the first valid proxy.
152 template <class DATA>
154 SG::Iterator<DATA>::Iterator (const SG::ConstProxyIterator& itr,
155 const SG::ConstProxyIterator& itrEnd)
156 : detail::IteratorBase (itr, itrEnd, false)
162 * @brief Reset state of the iterator.
163 * @param itr Starting proxy iterator.
164 * @param itrEnd Ending proxy iterator.
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.
169 template <class DATA>
172 SG::Iterator<DATA>::setState (const SG::ConstProxyIterator& itr,
173 const SG::ConstProxyIterator& itrEnd)
175 return detail::IteratorBase::setState (itr, itrEnd, false);
180 * @brief Equality check.
182 * Used by the boost iterator adapter.
184 template <class DATA>
186 bool SG::Iterator<DATA>::equal(const Iterator<DATA>& rhs) const
188 return detail::IteratorBase::eql(rhs);
193 * @brief Dereference the iterator.
195 * Used by the boost iterator adapter.
197 * Will throw SG::ExcInvalidIterator() if the proxy is not valid.
198 * Will throw SG::ExcConstObject if the proxy is const.
200 template <class DATA>
201 DATA& SG::Iterator<DATA>::dereference() const
204 DATA* ptr = SG::DataProxy_cast<DATA> (this->proxy());
206 throw SG::ExcInvalidIterator();