aGrUM  0.16.0
nodeGraphPart.h
Go to the documentation of this file.
1 
28 #ifndef GUM_NODE_GRAPH_PART_H
29 #define GUM_NODE_GRAPH_PART_H
30 
31 #include <algorithm>
32 #include <utility>
33 
34 #include <agrum/agrum.h>
35 
37 
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 
43 namespace gum_tests {
44 
45  class NodeGraphPartTestSuite;
46 }
47 
48 #endif
49 
50 namespace gum {
51 
52  class NodeGraphPart;
53 
59  friend class NodeGraphPart;
60 
61  public:
64  using iterator_category = std::forward_iterator_tag;
65  using value_type = NodeId;
67  using const_reference = const value_type&;
68  using pointer = value_type*;
69  using const_pointer = const value_type*;
70  using difference_type = std::ptrdiff_t;
72 
73  // ############################################################################
75  // ############################################################################
77 
81  NodeGraphPartIterator(const NodeGraphPart& nodes) noexcept;
82 
84  NodeGraphPartIterator(const NodeGraphPartIterator& it) noexcept;
85 
88 
90  virtual ~NodeGraphPartIterator() noexcept;
91 
93 
94  // ############################################################################
96  // ############################################################################
98 
100  NodeGraphPartIterator& operator=(const NodeGraphPartIterator& it) noexcept;
101 
103  NodeGraphPartIterator& operator=(NodeGraphPartIterator&& it) noexcept;
104 
106  bool operator==(const NodeGraphPartIterator& it) const noexcept;
107 
109  bool operator!=(const NodeGraphPartIterator& it) const noexcept;
110 
112  NodeGraphPartIterator& operator++() noexcept;
113 
115  value_type operator*() const;
116 
118 
119  protected:
121  void _setPos(NodeId id) noexcept;
122 
124  void _validate() noexcept;
125 
127  const NodeGraphPart* _nodes;
128 
130  NodeId _pos{0};
131 
132  // is this iterator still valid ?
133  bool _valid{false};
134  };
135 
141  : public NodeGraphPartIterator
142  , public Listener {
143  friend class NodeGraphPart;
144 
145  public:
148  using iterator_category = std::forward_iterator_tag;
151  using const_reference = const value_type&;
152  using pointer = value_type*;
153  using const_pointer = const value_type*;
154  using difference_type = std::ptrdiff_t;
156 
157  // ############################################################################
159  // ############################################################################
161 
164 
167 
170 
173 
175 
176  // ############################################################################
178  // ############################################################################
180 
183 
186 
188 
189  // ############################################################################
191  // ############################################################################
193 
195 
199  void whenNodeDeleted(const void* src, NodeId id);
200 
202  };
203 
257  public:
265 
266  // something strange with SWIG (with "using", these definitions cored dump
267  // the
268  // swig process)
273 
274  Signaler1< NodeId > onNodeAdded;
275  Signaler1< NodeId > onNodeDeleted;
276 
277  // ############################################################################
279  // ############################################################################
281 
283 
290  explicit NodeGraphPart(Size holes_size = HashTableConst::default_size,
291  bool holes_resize_policy = true);
292 
294 
295  NodeGraphPart(const NodeGraphPart& s);
296 
298  virtual ~NodeGraphPart();
299 
301 
302  // ############################################################################
304  // ############################################################################
306 
308 
309  NodeGraphPart& operator=(const NodeGraphPart& p);
310 
312 
313  bool operator==(const NodeGraphPart& p) const;
314 
316 
317  bool operator!=(const NodeGraphPart& p) const;
318 
320 
321  // ############################################################################
323  // ############################################################################
325 
327 
330  void populateNodes(const NodeGraphPart& s);
331 
333 
335  template < typename T >
336  void populateNodesFromProperty(const NodeProperty< T >& h);
337 
342  NodeId nextNodeId() const;
343 
345 
346  virtual NodeId addNode();
347 
353  std::vector< NodeId > addNodes(Size n);
354 
356 
360  virtual void addNodeWithId(const NodeId id);
361 
363 
367  virtual void eraseNode(const NodeId id);
368 
370  bool existsNode(const NodeId id) const;
371 
373  bool exists(const NodeId id) const;
374 
376  bool emptyNodes() const;
377 
379  bool empty() const;
380 
382  virtual void clearNodes();
383 
385  virtual void clear();
386 
388  Size sizeNodes() const;
389 
391  Size size() const;
392 
394  NodeId bound() const;
395 
397 
404  NodeSet asNodeSet() const;
405 
407  const NodeGraphPart& nodes() const;
408 
411  node_iterator_safe beginSafe() const;
412 
415  const node_iterator_safe& endSafe() const noexcept;
416 
419  node_iterator begin() const noexcept;
420 
423  const node_iterator& end() const noexcept;
424 
426  std::string toString() const;
427 
429 
438  template < typename VAL >
439  NodeProperty< VAL > nodesProperty(VAL (*f)(const NodeId&),
440  Size size = 0) const;
441 
443 
453  template < typename VAL >
454  NodeProperty< VAL > nodesProperty(const VAL& a, Size size = 0) const;
455 
459  template < typename VAL >
460  List< VAL > listMapNodes(VAL (*f)(const NodeId&)) const;
461 
463 
464  private:
465  friend class NodeGraphPartIterator;
467 
469 
470  friend class gum_tests::NodeGraphPartTestSuite;
471 
473  void __updateEndIteratorSafe();
474 
476  void __clearNodes();
477 
480  void __eraseHole(NodeId id);
481 
484  void __addHole(NodeId id);
485 
486  // ############################################################################
488  // ############################################################################
490 
492  bool __inHoles(NodeId id) const;
493 
495  Size __sizeHoles() const;
496 
498 
502  NodeSet* __holes;
503 
505  Size __holes_size;
506 
508  bool __holes_resize_policy;
509 
511  NodeGraphPartIteratorSafe __endIteratorSafe;
512 
514  NodeId __boundVal;
515  };
516 
518  std::ostream& operator<<(std::ostream&, const NodeGraphPart&);
519 
520 } /* namespace gum */
521 
522 #ifndef GUM_NO_INLINE
524 #endif // GUM_NOINLINE
525 
527 
528 #endif // GUM_NODE_GRAPH_PART_H
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: nodeGraphPart.h:64
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
value_type & reference
types for STL compliance
Definition: nodeGraphPart.h:66
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeGraphPartIterator NodeConstIterator
NodeId value_type
types for STL compliance
Definition: nodeGraphPart.h:65
STL namespace.
NodeGraphPartIteratorSafe NodeIteratorSafe
Generic doubly linked lists.
Definition: list.h:372
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeGraphPartIteratorSafe NodeConstIteratorSafe
Unsafe iterator on the node set of a graph.
Definition: nodeGraphPart.h:58
Signaler1< NodeId > onNodeAdded
const value_type * const_pointer
types for STL compliance
Definition: nodeGraphPart.h:69
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:243
std::ptrdiff_t difference_type
types for STL compliance
Definition: nodeGraphPart.h:70
Class for node sets in graph.
const value_type & const_reference
types for STL compliance
Definition: nodeGraphPart.h:67
NodeGraphPartIterator NodeIterator
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:65
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:251
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Signaler1< NodeId > onNodeDeleted
Safe iterator on the node set of a graph.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:74
value_type * pointer
types for STL compliance
Definition: nodeGraphPart.h:68
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.