aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::NodeGraphPartIteratorSafe Class Reference

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 ()
 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
bool operator!= (const NodeGraphPartIterator &it) const noexcept
 checks whether two iterators point toward different nodes
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 157 of file nodeGraphPart.h.

Member Typedef Documentation

◆ const_pointer

types for STL compliance

Definition at line 168 of file nodeGraphPart.h.

◆ const_reference

types for STL compliance

Definition at line 166 of file nodeGraphPart.h.

◆ difference_type

types for STL compliance

Definition at line 169 of file nodeGraphPart.h.

◆ iterator_category

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

types for STL compliance

Definition at line 163 of file nodeGraphPart.h.

◆ pointer

types for STL compliance

Definition at line 167 of file nodeGraphPart.h.

◆ reference

types for STL compliance

Definition at line 165 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 164 of file nodeGraphPart.h.

Constructor & Destructor Documentation

◆ NodeGraphPartIteratorSafe() [1/3]

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

default constructor

Definition at line 161 of file nodeGraphPart_inl.h.

161 :
162 NodeGraphPartIterator(nodes) {
163 GUM_CONNECT(*const_cast< NodeGraphPart* >(&nodes),
164 onNodeDeleted,
165 *this,
167 GUM_CONSTRUCTOR(NodeGraphPartIteratorSafe);
168 }
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 172 of file nodeGraphPart_inl.h.

172 :
174 GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
175 onNodeDeleted,
176 *this,
178 GUM_CONS_CPY(NodeGraphPartIteratorSafe);
179 }
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 183 of file nodeGraphPart_inl.h.

183 :
184 NodeGraphPartIterator(std::move(it)) {
185 GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
186 onNodeDeleted,
187 *this,
189 GUM_CONS_MOV(NodeGraphPartIteratorSafe);
190 }

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 ( )

destructor

Definition at line 193 of file nodeGraphPart_inl.h.

193 {
194 GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
195 }

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 56 of file listener_inl.h.

56{ _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 58 of file listener_inl.h.

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

References _senders_.

◆ operator!=()

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

checks whether two iterators point toward different nodes

Definition at line 127 of file nodeGraphPart_inl.h.

127 {
128 return !(operator==(it));
129 }
bool operator==(const NodeGraphPartIterator &it) const noexcept
checks whether two iterators point toward the same node

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

Here is the call graph for this function:

◆ operator*()

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

dereferencing operator

Definition at line 139 of file nodeGraphPart_inl.h.

139 {
140 if (!valid_) { GUM_ERROR(UndefinedIteratorValue, "This iterator is not valid !") }
141
142 return pos_;
143 }
NodeId pos_
the nodeid on which the iterator points currently
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References GUM_ERROR, pos_, and valid_.

◆ operator++()

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

increment the iterator

Definition at line 132 of file nodeGraphPart_inl.h.

132 {
133 ++pos_;
134 validate_();
135 return *this;
136 }
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 199 of file nodeGraphPart_inl.h.

199 {
200 // avoid self assignment
201 if (&it != this) {
203 Listener::operator=(it);
204 GUM_OP_CPY(NodeGraphPartIteratorSafe);
205 }
206
207 return *this;
208 }
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 212 of file nodeGraphPart_inl.h.

212 {
213 // avoid self assignment
214 if (&it != this) {
216 Listener::operator=(std::move(it));
217 GUM_OP_MOV(NodeGraphPartIteratorSafe);
218 }
219
220 return *this;
221 }

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 121 of file nodeGraphPart_inl.h.

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

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 146 of file nodeGraphPart_inl.h.

146 {
147 pos_ = id;
148
149 if (pos_ >= nodes_->bound()) {
150 pos_ = nodes_->bound();
151 valid_ = false;
152 } else {
153 valid_ = nodes_->exists(pos_);
154 }
155 }

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 58 of file nodeGraphPart_inl.h.

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

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 190 of file nodeGraphPart.cpp.

190 {
191 if (id == pos_) { // we just deleted the pos_ in NodeGraphPart
192 valid_ = false;
193 }
194
195 if (pos_ >= nodes_->bound()) { // moreover, it was the last position
196 pos_ = nodes_->bound();
197 valid_ = false;
198 }
199 }

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 147 of file nodeGraphPart.h.

147{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: