aGrUM  0.16.0
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 140 of file nodeGraphPart.h.

Member Typedef Documentation

◆ const_pointer

types for STL compliance

Definition at line 153 of file nodeGraphPart.h.

◆ const_reference

types for STL compliance

Definition at line 151 of file nodeGraphPart.h.

◆ difference_type

types for STL compliance

Definition at line 154 of file nodeGraphPart.h.

◆ iterator_category

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

types for STL compliance

Definition at line 148 of file nodeGraphPart.h.

◆ pointer

types for STL compliance

Definition at line 152 of file nodeGraphPart.h.

◆ reference

types for STL compliance

Definition at line 150 of file nodeGraphPart.h.

◆ value_type

types for STL compliance

Definition at line 149 of file nodeGraphPart.h.

Constructor & Destructor Documentation

◆ NodeGraphPartIteratorSafe() [1/3]

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

default constructor

Definition at line 152 of file nodeGraphPart_inl.h.

References GUM_CONNECT, and whenNodeDeleted().

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

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

165  :
167  GUM_CONNECT(*const_cast< NodeGraphPart* >(_nodes),
168  onNodeDeleted,
169  *this,
171  GUM_CONS_CPY(NodeGraphPartIteratorSafe);
172  }
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:98
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 176 of file nodeGraphPart_inl.h.

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

177  :
178  NodeGraphPartIterator(std::move(it)) {
179  GUM_CONNECT(*const_cast< NodeGraphPart* >(_nodes),
180  onNodeDeleted,
181  *this,
183  GUM_CONS_MOV(NodeGraphPartIteratorSafe);
184  }
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:98
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 187 of file nodeGraphPart_inl.h.

References operator=().

187  {
188  GUM_DESTRUCTOR(NodeGraphPartIteratorSafe);
189  }
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 137 of file nodeGraphPart_inl.h.

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

137  {
138  _pos = id;
139 
140  if (_pos >= _nodes->bound()) {
141  _pos = _nodes->bound();
142  _valid = false;
143  } else {
144  _valid = _nodes->exists(_pos);
145  }
146  }
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 38 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++().

38  {
39  _valid = false;
40 
41  if (_pos > _nodes->bound()) { _pos = _nodes->bound(); }
42 
43  while (_pos < _nodes->bound()) {
44  if (!_nodes->__inHoles(_pos)) {
45  _valid = true;
46  return;
47  }
48 
49  ++_pos;
50  }
51  }
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 36 of file listener_inl.h.

References gum::Listener::__senders.

36  {
37  __senders.push_back(sender);
38  }
Senders_list __senders
Definition: listener.h:94

◆ detachSignal__()

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

Definition at line 40 of file listener_inl.h.

References gum::Listener::__senders.

40  {
41  auto del = std::remove(__senders.begin(), __senders.end(), sender);
42 
43  if (del != __senders.end()) __senders.erase(del, __senders.end());
44  }
Senders_list __senders
Definition: listener.h:94

◆ operator!=()

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

checks whether two iterators point toward different nodes

Definition at line 115 of file nodeGraphPart_inl.h.

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

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

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

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

◆ operator++()

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

increment the iterator

Definition at line 121 of file nodeGraphPart_inl.h.

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

121  {
122  ++_pos;
123  _validate();
124  return *this;
125  }
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 193 of file nodeGraphPart_inl.h.

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

Referenced by ~NodeGraphPartIteratorSafe().

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

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

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

109  {
110  return ((_pos == it._pos) && (_valid == it._valid) && (_nodes == it._nodes));
111  }
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 171 of file nodeGraphPart.cpp.

Referenced by NodeGraphPartIteratorSafe().

171  {
172  if (id == _pos) { // we just deleted the _pos in NodeGraphPart
173  _valid = false;
174  }
175 
176  if (_pos >= _nodes->bound()) { // moreover, it was the last position
177  _pos = _nodes->bound();
178  _valid = false;
179  }
180  }
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 143 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: