aGrUM  0.14.2
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 NodeGraphPart_nodes
 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 137 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 149 of file nodeGraphPart_inl.h.

References GUM_CONNECT, and whenNodeDeleted().

150  :
151  NodeGraphPartIterator(nodes) {
152  GUM_CONNECT(*const_cast< NodeGraphPart* >(&nodes),
153  onNodeDeleted,
154  *this,
156  GUM_CONSTRUCTOR(NodeGraphPartIteratorSafe);
157  }
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 161 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_nodes, GUM_CONNECT, and whenNodeDeleted().

162  :
164  GUM_CONNECT(*const_cast< NodeGraphPart* >(_nodes),
165  onNodeDeleted,
166  *this,
168  GUM_CONS_CPY(NodeGraphPartIteratorSafe);
169  }
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
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() [3/3]

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

move constructor

Definition at line 173 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_nodes, GUM_CONNECT, and whenNodeDeleted().

174  :
175  NodeGraphPartIterator(std::move(it)) {
176  GUM_CONNECT(*const_cast< NodeGraphPart* >(_nodes),
177  onNodeDeleted,
178  *this,
180  GUM_CONS_MOV(NodeGraphPartIteratorSafe);
181  }
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
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()

INLINE gum::NodeGraphPartIteratorSafe::~NodeGraphPartIteratorSafe ( )

destructor

Definition at line 184 of file nodeGraphPart_inl.h.

References operator=().

184  {
185  GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
186  }
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
+ Here is the call graph for this function:

Member Function Documentation

◆ _setPos()

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

this function is used by NodeGraphPart to update

Definition at line 134 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_nodes, gum::NodeGraphPartIterator::_pos, gum::NodeGraphPartIterator::_valid, gum::NodeGraphPart::bound(), and gum::NodeGraphPart::exists().

134  {
135  _pos = id;
136 
137  if (_pos >= _nodes->bound()) {
138  _pos = _nodes->bound();
139  _valid = false;
140  } else {
141  _valid = _nodes->exists(_pos);
142  }
143  }
bool exists(const NodeId id) const
alias for existsNode
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
NodeId _pos
the nodeid on which the iterator points currently
+ 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 35 of file nodeGraphPart_inl.h.

References gum::NodeGraphPart::__inHoles(), gum::NodeGraphPartIterator::_nodes, gum::NodeGraphPartIterator::_pos, gum::NodeGraphPartIterator::_valid, and gum::NodeGraphPart::bound().

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

35  {
36  _valid = false;
37 
38  if (_pos > _nodes->bound()) { _pos = _nodes->bound(); }
39 
40  while (_pos < _nodes->bound()) {
41  if (!_nodes->__inHoles(_pos)) {
42  _valid = true;
43  return;
44  }
45 
46  ++_pos;
47  }
48  }
bool __inHoles(NodeId id) const
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
NodeId _pos
the nodeid on which the iterator points currently
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachSignal__()

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

Definition at line 33 of file listener_inl.h.

References gum::Listener::__senders.

33  {
34  __senders.push_back(sender);
35  }
Senders_list __senders
Definition: listener.h:92

◆ detachSignal__()

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

Definition at line 37 of file listener_inl.h.

References gum::Listener::__senders.

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

◆ operator!=()

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

checks whether two iterators point toward different nodes

Definition at line 112 of file nodeGraphPart_inl.h.

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

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

References gum::NodeGraphPartIterator::_pos, gum::NodeGraphPartIterator::_valid, and GUM_ERROR.

125  {
126  if (!_valid) {
127  GUM_ERROR(UndefinedIteratorValue, "This iterator is not valid !");
128  }
129 
130  return _pos;
131  }
NodeId _pos
the nodeid on which the iterator points currently
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ operator++()

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

increment the iterator

Definition at line 118 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_pos, and gum::NodeGraphPartIterator::_validate().

118  {
119  ++_pos;
120  _validate();
121  return *this;
122  }
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 190 of file nodeGraphPart_inl.h.

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

Referenced by ~NodeGraphPartIteratorSafe().

190  {
191  // avoid self assignment
192  if (&it != this) {
194  Listener:: operator=(it);
195  GUM_OP_CPY(NodeGraphPartIteratorSafe);
196  }
197 
198  return *this;
199  }
NodeGraphPartIterator & operator=(const NodeGraphPartIterator &it) noexcept
copy assignment operator
NodeGraphPartIteratorSafe(const NodeGraphPart &nodes)
default constructor
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [2/2]

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

move assignment operator

Definition at line 203 of file nodeGraphPart_inl.h.

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

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

References gum::NodeGraphPartIterator::_nodes, gum::NodeGraphPartIterator::_pos, and gum::NodeGraphPartIterator::_valid.

Referenced by gum::NodeGraphPartIterator::operator!=(), and gum::NodeGraphPart::operator!=().

106  {
107  return ((_pos == it._pos) && (_valid == it._valid) && (_nodes == it._nodes));
108  }
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
NodeId _pos
the nodeid on which the iterator points currently
+ 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 168 of file nodeGraphPart.cpp.

Referenced by NodeGraphPartIteratorSafe().

168  {
169  if (id == _pos) { // we just deleted the _pos in NodeGraphPart
170  _valid = false;
171  }
172 
173  if (_pos >= _nodes->bound()) { // moreover, it was the last position
174  _pos = _nodes->bound();
175  _valid = false;
176  }
177  }
const NodeGraphPart * _nodes
the nodegraphpart on which points the iterator
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
NodeId _pos
the nodeid on which the iterator points currently
+ Here is the caller 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

◆ _pos

◆ _valid


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