aGrUM  0.20.3
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 Member Functions

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

Public Types

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

Protected Attributes

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

Protected Member Functions

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

Friends

class NodeGraphPart
 

Detailed Description

Safe iterator on the node set of a graph.

Definition at line 139 of file nodeGraphPart.h.

Member Typedef Documentation

◆ const_pointer

types for STL compliance

Definition at line 150 of file nodeGraphPart.h.

◆ const_reference

types for STL compliance

Definition at line 148 of file nodeGraphPart.h.

◆ difference_type

types for STL compliance

Definition at line 151 of file nodeGraphPart.h.

◆ iterator_category

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

types for STL compliance

Definition at line 145 of file nodeGraphPart.h.

◆ pointer

types for STL compliance

Definition at line 149 of file nodeGraphPart.h.

◆ reference

types for STL compliance

Definition at line 147 of file nodeGraphPart.h.

◆ value_type

types for STL compliance

Definition at line 146 of file nodeGraphPart.h.

Constructor & Destructor Documentation

◆ NodeGraphPartIteratorSafe() [1/3]

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

default constructor

Definition at line 140 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

140  :
141  NodeGraphPartIterator(nodes) {
142  GUM_CONNECT(*const_cast< NodeGraphPart* >(&nodes),
143  onNodeDeleted,
144  *this,
146  GUM_CONSTRUCTOR(NodeGraphPartIteratorSafe);
147  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:96
NodeGraphPartIterator(const NodeGraphPart &nodes) noexcept
Default constructor.
void whenNodeDeleted(const void *src, NodeId id)
called when a node is deleted in the iterated NodeGraphPart
+ Here is the call graph for this function:

◆ NodeGraphPartIteratorSafe() [2/3]

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

copy constructor

Definition at line 151 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

151  :
153  GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
154  onNodeDeleted,
155  *this,
157  GUM_CONS_CPY(NodeGraphPartIteratorSafe);
158  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:96
NodeGraphPartIterator(const NodeGraphPart &nodes) noexcept
Default constructor.
void whenNodeDeleted(const void *src, NodeId id)
called when a node is deleted in the iterated NodeGraphPart
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ Here is the call graph for this function:

◆ NodeGraphPartIteratorSafe() [3/3]

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

move constructor

Definition at line 162 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

162  :
163  NodeGraphPartIterator(std::move(it)) {
164  GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
165  onNodeDeleted,
166  *this,
168  GUM_CONS_MOV(NodeGraphPartIteratorSafe);
169  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:96
NodeGraphPartIterator(const NodeGraphPart &nodes) noexcept
Default constructor.
void whenNodeDeleted(const void *src, NodeId id)
called when a node is deleted in the iterated NodeGraphPart
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ Here is the call graph for this function:

◆ ~NodeGraphPartIteratorSafe()

INLINE gum::NodeGraphPartIteratorSafe::~NodeGraphPartIteratorSafe ( )

destructor

Definition at line 172 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

172  {
173  GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
174  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
+ Here is the call graph for this function:

Member Function Documentation

◆ _attachSignal_()

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

Definition at line 35 of file listener_inl.h.

References gum::Set< Key, Alloc >::emplace().

35 { _senders_.push_back(sender); }
Senders_list _senders_
Definition: listener.h:92
+ Here is the call graph for this function:

◆ _detachSignal_()

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

Definition at line 37 of file listener_inl.h.

References gum::Set< Key, Alloc >::emplace().

37  {
38  auto del = std::remove(_senders_.begin(), _senders_.end(), sender);
39 
40  if (del != _senders_.end()) _senders_.erase(del, _senders_.end());
41  }
Senders_list _senders_
Definition: listener.h:92
+ 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 different nodes

Definition at line 106 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

106  {
107  return !(operator==(it));
108  }
bool operator==(const NodeGraphPartIterator &it) const noexcept
checks whether two iterators point toward the same node
+ Here is the call graph for this function:

◆ operator*()

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

dereferencing operator

Definition at line 118 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

118  {
119  if (!valid_) { GUM_ERROR(UndefinedIteratorValue, "This iterator is not valid !") }
120 
121  return pos_;
122  }
NodeId pos_
the nodeid on which the iterator points currently
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ operator++()

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

increment the iterator

Definition at line 111 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

111  {
112  ++pos_;
113  validate_();
114  return *this;
115  }
void validate_() noexcept
ensure that the nodeId is either end() either a valid NodeId
NodeId pos_
the nodeid on which the iterator points currently
+ 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 178 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

178  {
179  // avoid self assignment
180  if (&it != this) {
182  Listener:: operator=(it);
183  GUM_OP_CPY(NodeGraphPartIteratorSafe);
184  }
185 
186  return *this;
187  }
NodeGraphPartIterator & operator=(const NodeGraphPartIterator &it) noexcept
copy assignment operator
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
+ Here is the call graph for this function:

◆ operator=() [2/2]

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

move assignment operator

Definition at line 191 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

191  {
192  // avoid self assignment
193  if (&it != this) {
194  NodeGraphPartIterator::operator=(std::move(it));
195  Listener:: operator=(std::move(it));
196  GUM_OP_MOV(NodeGraphPartIteratorSafe);
197  }
198 
199  return *this;
200  }
NodeGraphPartIterator & operator=(const NodeGraphPartIterator &it) noexcept
copy assignment operator
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
+ 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 100 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

100  {
101  return ((pos_ == it.pos_) && (valid_ == it.valid_) && (nodes_ == it.nodes_));
102  }
NodeId pos_
the nodeid on which the iterator points currently
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ 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 125 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

125  {
126  pos_ = id;
127 
128  if (pos_ >= nodes_->bound()) {
129  pos_ = nodes_->bound();
130  valid_ = false;
131  } else {
132  valid_ = nodes_->exists(pos_);
133  }
134  }
bool exists(const NodeId id) const
alias for existsNode
NodeId pos_
the nodeid on which the iterator points currently
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ Here is the call graph for this function:

◆ validate_()

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

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

Definition at line 37 of file nodeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

37  {
38  valid_ = false;
39 
40  if (pos_ > nodes_->bound()) { pos_ = nodes_->bound(); }
41 
42  while (pos_ < nodes_->bound()) {
43  if (!nodes_->_inHoles_(pos_)) {
44  valid_ = true;
45  return;
46  }
47 
48  ++pos_;
49  }
50  }
NodeId pos_
the nodeid on which the iterator points currently
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
bool _inHoles_(NodeId id) const
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ Here is the call 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 170 of file nodeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

170  {
171  if (id == pos_) { // we just deleted the pos_ in NodeGraphPart
172  valid_ = false;
173  }
174 
175  if (pos_ >= nodes_->bound()) { // moreover, it was the last position
176  pos_ = nodes_->bound();
177  valid_ = false;
178  }
179  }
NodeId pos_
the nodeid on which the iterator points currently
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
const NodeGraphPart * nodes_
the nodegraphpart on which points the iterator
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ NodeGraphPart

friend class NodeGraphPart
friend

Definition at line 140 of file nodeGraphPart.h.

Member Data Documentation

◆ nodes_

const NodeGraphPart* gum::NodeGraphPartIterator::nodes_
protectedinherited

the nodegraphpart on which points the iterator

Definition at line 126 of file nodeGraphPart.h.

◆ pos_

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

the nodeid on which the iterator points currently

Definition at line 129 of file nodeGraphPart.h.

◆ valid_

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

Definition at line 132 of file nodeGraphPart.h.


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