ATLAS Offline Software
Loading...
Searching...
No Matches
SGIterator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4/*
5 */
10
11
13
14
25 bool isConst)
26{
27 setState (itr, itrEnd, isConst).ignore();
28}
29
30
35 : m_proxies (other.m_proxies)
36{
37 // Maintain shared ownership of elements in our range.
38 this->addRef();
39}
40
41
46{
47 // Release ownership of everything in our range.
48 this->release();
49}
50
51
57{
58 if (this != &other) {
59 // Assign, maintaining refcounts.
60 this->release();
61 m_proxies = other.m_proxies;
62 this->addRef();
63 }
64 return *this;
66
67
77StatusCode
80 bool isConst)
81{
82 if (!m_proxies.empty()) {
83 this->release();
84 m_proxies.clear();
85 }
86
87 // Save all valid proxies in reverse order. Also take out a refcount on each.
88 while (itr != itrEnd) {
89 --itrEnd;
90 DataProxy* dp = itrEnd->second;
91 if (dp->isValid() && (isConst || !dp->isConst())) {
92 m_proxies.push_back (dp);
93 dp->addRef();
94 }
95 }
96
97 if (m_proxies.empty()) {
98 return StatusCode::FAILURE;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104
111{
112 if (!m_proxies.empty()) {
113 m_proxies.back()->release();
114 m_proxies.pop_back();
115 }
116}
117
118
125{
126 // This should usually not be needed, since we check for constness
127 // when initializing the iterator. However, it is possible for a proxy
128 // to be marked as const after the iterator has been formed, so keep the check.
129 const SG::DataProxy* dp = this->proxy();
130 if (dp->isConst()) {
131 const IProxyDict* store = dp->store();
132 throw SG::ExcConstObject (dp->clID(),
133 dp->name(),
134 store ? store->name() : "(unknown)");
135 }
136}
137
138
142const std::string& SG::detail::IteratorBase::key() const
143{
144 return m_proxies.back()->name();
145}
A standard conforming forward iterator over items in StoreGate.
virtual const std::string & name() const override
Exception — Tried to retrieve non-const pointer to const object.
Implementation class, not to be used directly Iterates over valid proxies in the range.
Definition SGIterator.h:42
std::vector< SG::DataProxy * > m_proxies
All proxies in our range, in reverse order.
Definition SGIterator.h:176
const std::string & key() const
Get the key string with which the current object was stored.
DataProxy * proxy() const
The proxy pointed at by this iterator.
void increment()
Move to the next valid proxy.
IteratorBase & operator=(const IteratorBase &other)
Assignment.
void const_check() const
Const check: throw an exception if we're pointing at a const proxy.
IteratorBase()=default
Default constructor.
StatusCode setState(SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd, bool isConst)
Reset state of the iterator.
void addRef()
Add a reference count to all proxies in our range.
static std::string release
Definition computils.h:54
ProxyMap::const_iterator ConstProxyIterator
Definition ProxyMap.h:24