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

an iterator facade to DataHandle. More...

#include <SGIterator.h>

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

Public Member Functions

 Iterator ()
 Default constructor.
 Iterator (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 Iterator< DATA > &rhs) const
 Equality check.
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::Iterator< DATA >

an iterator facade to DataHandle.

Behaves like a forward iterator

Definition at line 224 of file SGIterator.h.

Constructor & Destructor Documentation

◆ Iterator() [1/2]

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

Default constructor.

◆ Iterator() [2/2]

template<class DATA>
SG::Iterator< DATA >::Iterator ( const SG::ConstProxyIterator< DATA > & itr,
const SG::ConstProxyIterator< DATA > & 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>
DATA & SG::Iterator< DATA >::dereference ( ) const
private

Dereference the iterator.

Used by the boost iterator adapter.

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

◆ eql()

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

Equality check.

◆ equal()

template<class DATA>
bool SG::Iterator< DATA >::equal ( const Iterator< 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]

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.

◆ setState() [2/2]

template<class DATA>
StatusCode SG::Iterator< DATA >::setState ( const SG::ConstProxyIterator< DATA > & itr,
const SG::ConstProxyIterator< DATA > & 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 first proxy is const or if the range is empty.

◆ boost::iterator_core_access

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

Definition at line 263 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: