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

an iterator facade to DATA. More...

#include <SGIterator.h>

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

Public Member Functions

 Iterator ()
 Default constructor.
 Iterator (SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd)
 Constructor from proxy iterator pair.
StatusCode setState (SG::ConstProxyIterator itr, SG::ConstProxyIterator itrEnd)
 Reset state of the iterator.
DataProxy * proxy () 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.
template<DataProxyIterator ITERATOR>
StatusCode setState (ITERATOR itr, ITERATOR 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 DATA.

Behaves like a forward iterator

Definition at line 345 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 ( SG::ConstProxyIterator< DATA > itr,
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 124 of file SGIterator.cxx.

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}
virtual const std::string & name() const override
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 110 of file SGIterator.cxx.

111{
112 if (!m_proxies.empty()) {
113 m_proxies.back()->release();
114 m_proxies.pop_back();
115 }
116}
std::vector< SG::DataProxy * > m_proxies
All proxies in our range, in reverse order.
Definition SGIterator.h:176

◆ key()

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

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

Definition at line 142 of file SGIterator.cxx.

143{
144 return m_proxies.back()->name();
145}

◆ 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/3]

template<DataProxyIterator ITERATOR>
StatusCode SG::detail::IteratorBase::setState ( ITERATOR itr,
ITERATOR itrEnd,
bool isConst )
protectedinherited

Reset state of the iterator.

Parameters
itrStarting iterator over DataProxy*.
itrEndEnding iterator.
isConstIs this for a const iterator?

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

◆ setState() [2/3]

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 78 of file SGIterator.cxx.

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}
void release()
Remove a reference count from all proxies in our range.

◆ setState() [3/3]

template<class DATA>
StatusCode SG::Iterator< DATA >::setState ( SG::ConstProxyIterator< DATA > itr,
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 384 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 176 of file SGIterator.h.


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