aGrUM  0.20.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 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 151 of file nodeGraphPart_inl.h.

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

152  :
153  NodeGraphPartIterator(nodes) {
154  GUM_CONNECT(*const_cast< NodeGraphPart* >(&nodes),
155  onNodeDeleted,
156  *this,
158  GUM_CONSTRUCTOR(NodeGraphPartIteratorSafe);
159  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:97
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 163 of file nodeGraphPart_inl.h.

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

164  :
166  GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
167  onNodeDeleted,
168  *this,
170  GUM_CONS_CPY(NodeGraphPartIteratorSafe);
171  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:97
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 175 of file nodeGraphPart_inl.h.

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

176  :
177  NodeGraphPartIterator(std::move(it)) {
178  GUM_CONNECT(*const_cast< NodeGraphPart* >(nodes_),
179  onNodeDeleted,
180  *this,
182  GUM_CONS_MOV(NodeGraphPartIteratorSafe);
183  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
#define GUM_CONNECT(sender, signal, receiver, target)
Definition: listener.h:97
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 186 of file nodeGraphPart_inl.h.

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

186  {
187  GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
188  }
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  {
36  senders__.push_back(sender);
37  }
Senders_list senders__
Definition: listener.h:93
+ Here is the call graph for this function:

◆ detachSignal__()

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

Definition at line 39 of file listener_inl.h.

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

39  {
40  auto del = std::remove(senders__.begin(), senders__.end(), sender);
41 
42  if (del != senders__.end()) senders__.erase(del, senders__.end());
43  }
Senders_list senders__
Definition: listener.h:93
+ 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 114 of file nodeGraphPart_inl.h.

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

115  {
116  return !(operator==(it));
117  }
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 127 of file nodeGraphPart_inl.h.

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

127  {
128  if (!valid_) {
129  GUM_ERROR(UndefinedIteratorValue, "This iterator is not valid !");
130  }
131 
132  return pos_;
133  }
NodeId pos_
the nodeid on which the iterator points currently
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ operator++()

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

increment the iterator

Definition at line 120 of file nodeGraphPart_inl.h.

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

120  {
121  ++pos_;
122  validate_();
123  return *this;
124  }
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 192 of file nodeGraphPart_inl.h.

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

192  {
193  // avoid self assignment
194  if (&it != this) {
196  Listener:: operator=(it);
197  GUM_OP_CPY(NodeGraphPartIteratorSafe);
198  }
199 
200  return *this;
201  }
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 205 of file nodeGraphPart_inl.h.

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

205  {
206  // avoid self assignment
207  if (&it != this) {
208  NodeGraphPartIterator::operator=(std::move(it));
209  Listener:: operator=(std::move(it));
210  GUM_OP_MOV(NodeGraphPartIteratorSafe);
211  }
212 
213  return *this;
214  }
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 107 of file nodeGraphPart_inl.h.

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

108  {
109  return ((pos_ == it.pos_) && (valid_ == it.valid_) && (nodes_ == it.nodes_));
110  }
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 136 of file nodeGraphPart_inl.h.

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

136  {
137  pos_ = id;
138 
139  if (pos_ >= nodes_->bound()) {
140  pos_ = nodes_->bound();
141  valid_ = false;
142  } else {
143  valid_ = nodes_->exists(pos_);
144  }
145  }
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: