ATLAS Offline Software
Loading...
Searching...
No Matches
SG::ConstIterator< DATA > Class Template Reference

a const_iterator facade to DataHandle. More...

#include <SGIterator.h>

Inheritance diagram for SG::ConstIterator< DATA >:
Collaboration diagram for SG::ConstIterator< DATA >:

Public Member Functions

 ConstIterator ()
 Default constructor.
 ConstIterator (const SG::ConstProxyIterator &itr, const SG::ConstProxyIterator &itrEnd)
 Constructor from proxy iterator pair.
StatusCode setState (const SG::ConstProxyIterator &itr, const SG::ConstProxyIterator &itrEnd)
 Reset state of the iterator.
DataProxyproxy () const
 The proxy pointed at by this iterator.
const std::string & key () const
 Get the key string with which the current object was stored.

Protected Member Functions

StatusCode setState (SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd, bool isConst)
 Reset state of the iterator.
void increment ()
 Move to the next valid proxy.
bool eql (const IteratorBase &rhs) const
 Equality check.
void const_check () const
 Const check: throw an exception if we're pointing at a const proxy.

Private Member Functions

bool equal (const ConstIterator &rhs) const
 Equality check.
const DATA & dereference () const
 Dereference the iterator.
void addRef ()
 Add a reference count to all proxies in our range.
void release ()
 Remove a reference count from all proxies in our range.

Private Attributes

std::vector< SG::DataProxy * > m_proxies
 All proxies in our range, in reverse order.

Friends

class boost::iterator_core_access

Detailed Description

template<class DATA>
class SG::ConstIterator< DATA >

a const_iterator facade to DataHandle.

Behaves like a forward iterator

Definition at line 158 of file SGIterator.h.

Constructor & Destructor Documentation

◆ ConstIterator() [1/2]

template<class DATA>
SG::ConstIterator< DATA >::ConstIterator ( )

Default constructor.

◆ ConstIterator() [2/2]

template<class DATA>
SG::ConstIterator< DATA >::ConstIterator ( const SG::ConstProxyIterator & itr,
const SG::ConstProxyIterator & itrEnd )
explicit

Constructor from proxy iterator pair.

Parameters
itrStarting proxy iterator.
itrEndEnding proxy iterator.

Will skip ahead to the first valid proxy.

Member Function Documentation

◆ addRef()

void SG::detail::IteratorBase::addRef ( )
privateinherited

Add a reference count to all proxies in our range.

◆ const_check()

void SG::detail::IteratorBase::const_check ( ) const
protectedinherited

Const check: throw an exception if we're pointing at a const proxy.

Called when dereferencing a non-const iterator.

Definition at line 137 of file SGIterator.cxx.

138{
139 // This should usually not be needed, since we check for constness
140 // when initializing the iterator. However, it is possible for a proxy
141 // to be marked as const after the iterator has been formed, so keep the check.
142 const SG::DataProxy* dp = this->proxy();
143 if (dp->isConst()) {
144 const IProxyDict* store = dp->store();
145 throw SG::ExcConstObject (dp->clID(),
146 dp->name(),
147 store ? store->name() : "(unknown)");
148 }
149}
virtual const std::string & name() const override
Definition TestStore.cxx:97
DataProxy * proxy() const
The proxy pointed at by this iterator.
TestStore store
Definition TestStore.cxx:23

◆ dereference()

template<class DATA>
const DATA & SG::ConstIterator< DATA >::dereference ( ) const
private

Dereference the iterator.

Used by the boost iterator adapter.

Will throw SG::ExcInvalidIterator() if the proxy is not valid.

◆ eql()

bool SG::detail::IteratorBase::eql ( const IteratorBase & rhs) const
protectedinherited

Equality check.

◆ equal()

template<class DATA>
bool SG::ConstIterator< DATA >::equal ( const ConstIterator< DATA > & rhs) const
private

Equality check.

Used by the boost iterator adapter.

◆ increment()

void SG::detail::IteratorBase::increment ( )
protectedinherited

Move to the next valid proxy.

Used by the boost iterator adapter.

Definition at line 123 of file SGIterator.cxx.

124{
125 if (!m_proxies.empty()) {
126 m_proxies.back()->release();
127 m_proxies.pop_back();
128 }
129}
std::vector< SG::DataProxy * > m_proxies
All proxies in our range, in reverse order.
Definition SGIterator.h:146

◆ key()

const std::string & SG::detail::IteratorBase::key ( ) const
inherited

Get the key string with which the current object was stored.

Definition at line 155 of file SGIterator.cxx.

156{
157 return m_proxies.back()->name();
158}

◆ proxy()

DataProxy * SG::detail::IteratorBase::proxy ( ) const
inherited

The proxy pointed at by this iterator.

◆ release()

void SG::detail::IteratorBase::release ( )
privateinherited

Remove a reference count from all proxies in our range.

◆ setState() [1/2]

template<class DATA>
StatusCode SG::ConstIterator< DATA >::setState ( const SG::ConstProxyIterator & itr,
const SG::ConstProxyIterator & itrEnd )

Reset state of the iterator.

Parameters
itrStarting proxy iterator.
itrEndEnding proxy iterator.

Will skip ahead to the first valid proxy. Will return failure if the range is empty.

◆ setState() [2/2]

StatusCode SG::detail::IteratorBase::setState ( SG::ConstProxyIterator itr,
SG::ConstProxyIterator itrEnd,
bool isConst )
protectedinherited

Reset state of the iterator.

Parameters
itrStarting proxy iterator.
itrEndEnding proxy iterator.
isConstIs this for a const iterator?

Will skip ahead to the first valid proxy. Returns FAILURE if the range is empty.

Definition at line 94 of file SGIterator.cxx.

97{
98 this->release();
99 m_proxies.clear();
100
101 while (itr != itrEnd) {
102 --itrEnd;
103 DataProxy* dp = itrEnd->second;
104 if (dp->isValid() && (isConst || !dp->isConst())) {
105 m_proxies.push_back (dp);
106 dp->addRef();
107 }
108 }
109
110 if (m_proxies.empty()) {
111 return StatusCode::FAILURE;
112 }
113
114 return StatusCode::SUCCESS;
115}
void release()
Remove a reference count from all proxies in our range.

◆ boost::iterator_core_access

template<class DATA>
friend class boost::iterator_core_access
friend

Definition at line 197 of file SGIterator.h.

Member Data Documentation

◆ m_proxies

std::vector<SG::DataProxy*> SG::detail::IteratorBase::m_proxies
privateinherited

All proxies in our range, in reverse order.

Definition at line 146 of file SGIterator.h.


The documentation for this class was generated from the following file: