aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::NodeGraphPartIteratorSafe Class Referencefinal

Safe iterator on the node set of a graph. More...

#include <nodeGraphPart.h>

Inheritance diagram for gum::NodeGraphPartIteratorSafe:
Collaboration diagram for gum::NodeGraphPartIteratorSafe:

Public Types

using iterator_category = std::forward_iterator_tag
 types for STL compliance
using value_type = NodeId
 types for STL compliance
using reference = value_type&
 types for STL compliance
using const_reference = const value_type&
 types for STL compliance
using pointer = value_type*
 types for STL compliance
using const_pointer = const value_type*
 types for STL compliance
using difference_type = std::ptrdiff_t
 types for STL compliance

Public Member Functions

void _attachSignal_ (__sig__::ISignaler *sender)
void _detachSignal_ (__sig__::ISignaler *sender)
Constructors / Destructors
 NodeGraphPartIteratorSafe (const NodeGraphPart &nodes)
 default constructor
 NodeGraphPartIteratorSafe (const NodeGraphPartIteratorSafe &it)
 copy constructor
 NodeGraphPartIteratorSafe (NodeGraphPartIteratorSafe &&it)
 move constructor
 ~NodeGraphPartIteratorSafe () final
 destructor
Operators
NodeGraphPartIteratorSafeoperator= (const NodeGraphPartIteratorSafe &it)
 copy assignment operator
NodeGraphPartIteratorSafeoperator= (NodeGraphPartIteratorSafe &&it)
 move assignment operator
Accessors / Modifiers
void whenNodeDeleted (const void *src, NodeId id)
 called when a node is deleted in the iterated NodeGraphPart
Operators
bool operator== (const NodeGraphPartIterator &it) const noexcept
 checks whether two iterators point toward the same node
NodeGraphPartIteratoroperator++ () noexcept
 increment the iterator
value_type operator* () const
 dereferencing operator

Protected Member Functions

void setPos_ (NodeId id) noexcept
 this function is used by NodeGraphPart to update
void validate_ () noexcept
 ensure that the nodeId is either end() either a valid NodeId

Protected Attributes

const NodeGraphPartnodes_
 the nodegraphpart on which points the iterator
NodeId pos_ {0}
 the nodeid on which the iterator points currently
bool valid_ {false}

Private Types

using Senders_list = std::vector< __sig__::ISignaler* >
 Alias for the list of signal senders.

Private Attributes

Senders_list _senders_

Friends

class NodeGraphPart

Detailed Description

Safe iterator on the node set of a graph.

Definition at line 149 of file nodeGraphPart.h.

Member Typedef Documentation

◆ const_pointer

types for STL compliance

Definition at line 160 of file nodeGraphPart.h.

◆ const_reference

types for STL compliance

Definition at line 158 of file nodeGraphPart.h.

◆ difference_type

types for STL compliance

Definition at line 161 of file nodeGraphPart.h.

◆ iterator_category

using gum::NodeGraphPartIteratorSafe::iterator_category = std::forward_iterator_tag

types for STL compliance

Definition at line 155 of file nodeGraphPart.h.

◆ pointer

types for STL compliance

Definition at line 159 of file nodeGraphPart.h.

◆ reference

types for STL compliance

Definition at line 157 of file nodeGraphPart.h.

◆ Senders_list

using gum::Listener::Senders_list = std::vector< __sig__::ISignaler* >
privateinherited

Alias for the list of signal senders.

Definition at line 96 of file listener.h.

◆ value_type

types for STL compliance

Definition at line 156 of file nodeGraphPart.h.

Constructor & Destructor Documentation

◆ NodeGraphPartIteratorSafe() [1/3]

INLINE gum::NodeGraphPartIteratorSafe::NodeGraphPartIteratorSafe ( const NodeGraphPart & nodes)
explicit

default constructor

Definition at line 156 of file nodeGraphPart_inl.h.

156 :
157 NodeGraphPartIterator(nodes) {
158 GUM_CONNECT(*const_cast< NodeGraphPart* >(&nodes),
159 onNodeDeleted,
160 *this,
162 GUM_CONSTRUCTOR(NodeGraphPartIteratorSafe);
163 }
void whenNodeDeleted(const void *src, NodeId id)
called when a node is deleted in the iterated NodeGraphPart
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
NodeGraphPartIterator(const NodeGraphPart &nodes) noexcept
Default constructor.
#define GUM_CONNECT(sender, signal, receiver, target)
Definition listener.h:117

References gum::NodeGraphPartIterator::NodeGraphPartIterator(), NodeGraphPartIteratorSafe(), GUM_CONNECT, NodeGraphPart, and whenNodeDeleted().

Referenced by NodeGraphPartIteratorSafe(), NodeGraphPartIteratorSafe(), NodeGraphPartIteratorSafe(), ~NodeGraphPartIteratorSafe(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NodeGraphPartIteratorSafe() [2/3]

INLINE gum::NodeGraphPartIteratorSafe::NodeGraphPartIteratorSafe ( const NodeGraphPartIteratorSafe & it)

copy constructor

Definition at line 167 of file nodeGraphPart_inl.h.

167 :
169 GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
170 onNodeDeleted,
171 *this,
173 GUM_CONS_CPY(NodeGraphPartIteratorSafe);
174 }
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator

References gum::NodeGraphPartIterator::NodeGraphPartIterator(), NodeGraphPartIteratorSafe(), GUM_CONNECT, NodeGraphPart, gum::NodeGraphPartIterator::nodes_, and whenNodeDeleted().

Here is the call graph for this function:

◆ NodeGraphPartIteratorSafe() [3/3]

INLINE gum::NodeGraphPartIteratorSafe::NodeGraphPartIteratorSafe ( NodeGraphPartIteratorSafe && it)

move constructor

Definition at line 178 of file nodeGraphPart_inl.h.

178 :
179 NodeGraphPartIterator(std::move(it)) {
180 GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
181 onNodeDeleted,
182 *this,
184 GUM_CONS_MOV(NodeGraphPartIteratorSafe);
185 }

References gum::NodeGraphPartIterator::NodeGraphPartIterator(), NodeGraphPartIteratorSafe(), GUM_CONNECT, NodeGraphPart, gum::NodeGraphPartIterator::nodes_, and whenNodeDeleted().

Here is the call graph for this function:

◆ ~NodeGraphPartIteratorSafe()

INLINE gum::NodeGraphPartIteratorSafe::~NodeGraphPartIteratorSafe ( )
final

destructor

Definition at line 188 of file nodeGraphPart_inl.h.

188 {
189 GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
190 }

References NodeGraphPartIteratorSafe().

Here is the call graph for this function:

Member Function Documentation

◆ _attachSignal_()

INLINE void gum::Listener::_attachSignal_ ( __sig__::ISignaler * sender)
inherited

Definition at line 57 of file listener_inl.h.

57{ _senders_.push_back(sender); }
Senders_list _senders_
Definition listener.h:113

References _senders_.

◆ _detachSignal_()

INLINE void gum::Listener::_detachSignal_ ( __sig__::ISignaler * sender)
inherited

Definition at line 59 of file listener_inl.h.

59 {
60 auto del = std::remove(_senders_.begin(), _senders_.end(), sender);
61
62 if (del != _senders_.end()) _senders_.erase(del, _senders_.end());
63 }

References _senders_.

Referenced by gum::__sig__::BasicSignaler< Args >::detach().

Here is the caller graph for this function:

◆ operator*()

INLINE NodeId gum::NodeGraphPartIterator::operator* ( ) const
inherited

dereferencing operator

Definition at line 134 of file nodeGraphPart_inl.h.

134 {
135 if (!valid_) { GUM_ERROR(UndefinedIteratorValue, "This iterator is not valid !") }
136
137 return pos_;
138 }
NodeId pos_
the nodeid on which the iterator points currently
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References GUM_ERROR, pos_, and valid_.

◆ operator++()

INLINE NodeGraphPartIterator & gum::NodeGraphPartIterator::operator++ ( )
noexceptinherited

increment the iterator

Definition at line 127 of file nodeGraphPart_inl.h.

127 {
128 ++pos_;
129 validate_();
130 return *this;
131 }
void validate_() noexcept
ensure that the nodeId is either end() either a valid NodeId

References NodeGraphPartIterator(), pos_, and validate_().

Here is the call graph for this function:

◆ operator=() [1/2]

INLINE NodeGraphPartIteratorSafe & gum::NodeGraphPartIteratorSafe::operator= ( const NodeGraphPartIteratorSafe & it)

copy assignment operator

Definition at line 194 of file nodeGraphPart_inl.h.

194 {
195 // avoid self assignment
196 if (&it != this) {
198 Listener::operator=(it);
199 GUM_OP_CPY(NodeGraphPartIteratorSafe);
200 }
201
202 return *this;
203 }
NodeGraphPartIterator & operator=(const NodeGraphPartIterator &it) noexcept
copy assignment operator

References NodeGraphPartIteratorSafe(), and gum::NodeGraphPartIterator::operator=().

Here is the call graph for this function:

◆ operator=() [2/2]

INLINE NodeGraphPartIteratorSafe & gum::NodeGraphPartIteratorSafe::operator= ( NodeGraphPartIteratorSafe && it)

move assignment operator

Definition at line 207 of file nodeGraphPart_inl.h.

207 {
208 // avoid self assignment
209 if (&it != this) {
211 Listener::operator=(std::move(it));
212 GUM_OP_MOV(NodeGraphPartIteratorSafe);
213 }
214
215 return *this;
216 }

References NodeGraphPartIteratorSafe(), and gum::NodeGraphPartIterator::operator=().

Here is the call graph for this function:

◆ operator==()

INLINE bool gum::NodeGraphPartIterator::operator== ( const NodeGraphPartIterator & it) const
noexceptinherited

checks whether two iterators point toward the same node

Definition at line 122 of file nodeGraphPart_inl.h.

122 {
123 return ((pos_ == it.pos_) && (valid_ == it.valid_) && (nodes_ == it.nodes_));
124 }

References NodeGraphPartIterator(), nodes_, pos_, and valid_.

Here is the call graph for this function:

◆ setPos_()

INLINE void gum::NodeGraphPartIterator::setPos_ ( NodeId id)
protectednoexceptinherited

this function is used by NodeGraphPart to update

Definition at line 141 of file nodeGraphPart_inl.h.

141 {
142 pos_ = id;
143
144 if (pos_ >= nodes_->bound()) {
145 pos_ = nodes_->bound();
146 valid_ = false;
147 } else {
148 valid_ = nodes_->exists(pos_);
149 }
150 }

References nodes_, pos_, and valid_.

◆ validate_()

INLINE void gum::NodeGraphPartIterator::validate_ ( )
protectednoexceptinherited

ensure that the nodeId is either end() either a valid NodeId

Definition at line 59 of file nodeGraphPart_inl.h.

59 {
60 valid_ = false;
61
62 if (pos_ > nodes_->bound()) { pos_ = nodes_->bound(); }
63
64 while (pos_ < nodes_->bound()) {
65 if (!nodes_->_inHoles_(pos_)) {
66 valid_ = true;
67 return;
68 }
69
70 ++pos_;
71 }
72 }

References nodes_, pos_, and valid_.

Referenced by gum::NodeGraphPart::begin(), gum::NodeGraphPart::beginSafe(), and operator++().

Here is the caller graph for this function:

◆ whenNodeDeleted()

void gum::NodeGraphPartIteratorSafe::whenNodeDeleted ( const void * src,
NodeId id )

called when a node is deleted in the iterated NodeGraphPart

Parameters
srcthe NodeGraphPart
idid of deleted node

Definition at line 254 of file nodeGraphPart.cpp.

254 {
255 if (id == pos_) { // we just deleted the pos_ in NodeGraphPart
256 valid_ = false;
257 }
258
259 if (pos_ >= nodes_->bound()) { // moreover, it was the last position
260 pos_ = nodes_->bound();
261 valid_ = false;
262 }
263 }

References gum::NodeGraphPartIterator::nodes_, gum::NodeGraphPartIterator::pos_, and gum::NodeGraphPartIterator::valid_.

Referenced by NodeGraphPartIteratorSafe(), NodeGraphPartIteratorSafe(), and NodeGraphPartIteratorSafe().

Here is the caller graph for this function:

◆ NodeGraphPart

friend class NodeGraphPart
friend

Member Data Documentation

◆ _senders_

Senders_list gum::Listener::_senders_
privateinherited

Definition at line 113 of file listener.h.

Referenced by Listener(), ~Listener(), _attachSignal_(), and _detachSignal_().

◆ nodes_

◆ pos_

NodeId gum::NodeGraphPartIterator::pos_ {0}
protectedinherited

the nodeid on which the iterator points currently

Definition at line 139 of file nodeGraphPart.h.

139{0};

Referenced by NodeGraphPartIterator(), NodeGraphPartIterator(), operator*(), operator++(), operator=(), operator=(), operator==(), setPos_(), validate_(), and gum::NodeGraphPartIteratorSafe::whenNodeDeleted().

◆ valid_

bool gum::NodeGraphPartIterator::valid_ {false}
protectedinherited

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