aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
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  friend class NodeGraphPart;
142 
143  public:
146  using iterator_category = std::forward_iterator_tag;
149  using const_reference = const value_type&;
150  using pointer = value_type*;
151  using const_pointer = const value_type*;
152  using difference_type = std::ptrdiff_t;
154 
155  // ############################################################################
157  // ############################################################################
159 
162 
165 
168 
171 
173 
174  // ############################################################################
176  // ############################################################################
178 
181 
184 
186 
187  // ############################################################################
189  // ############################################################################
191 
193 
197  void whenNodeDeleted(const void* src, NodeId id);
198 
200  };
201 
255  public:
263 
264  // something strange with SWIG (with "using", these definitions cored dump
265  // the
266  // swig process)
271 
272  Signaler1< NodeId > onNodeAdded;
273  Signaler1< NodeId > onNodeDeleted;
274 
275  // ############################################################################
277  // ############################################################################
279 
281 
288  explicit NodeGraphPart(Size holes_size = HashTableConst::default_size,
289  bool holes_resize_policy = true);
290 
292 
293  NodeGraphPart(const NodeGraphPart& s);
294 
296  virtual ~NodeGraphPart();
297 
299 
300  // ############################################################################
302  // ############################################################################
304 
306 
307  NodeGraphPart& operator=(const NodeGraphPart& p);
308 
310 
311  bool operator==(const NodeGraphPart& p) const;
312 
314 
315  bool operator!=(const NodeGraphPart& p) const;
316 
318 
319  // ############################################################################
321  // ############################################################################
323 
325 
328  void populateNodes(const NodeGraphPart& s);
329 
331 
333  template < typename T >
334  void populateNodesFromProperty(const NodeProperty< T >& h);
335 
340  NodeId nextNodeId() const;
341 
343 
344  virtual NodeId addNode();
345 
351  std::vector< NodeId > addNodes(Size n);
352 
354 
358  virtual void addNodeWithId(const NodeId id);
359 
361 
365  virtual void eraseNode(const NodeId id);
366 
368  bool existsNode(const NodeId id) const;
369 
371  bool exists(const NodeId id) const;
372 
374  bool emptyNodes() const;
375 
377  bool empty() const;
378 
380  virtual void clearNodes();
381 
383  virtual void clear();
384 
386  Size sizeNodes() const;
387 
389  Size size() const;
390 
392  NodeId bound() const;
393 
395 
402  NodeSet asNodeSet() const;
403 
405  const NodeGraphPart& nodes() const;
406 
409  node_iterator_safe beginSafe() const;
410 
413  const node_iterator_safe& endSafe() const noexcept;
414 
417  node_iterator begin() const noexcept;
418 
421  const node_iterator& end() const noexcept;
422 
424  std::string toString() const;
425 
427 
436  template < typename VAL >
437  NodeProperty< VAL > nodesProperty(VAL (*f)(const NodeId&),
438  Size size = 0) const;
439 
441 
451  template < typename VAL >
452  NodeProperty< VAL > nodesProperty(const VAL& a, Size size = 0) const;
453 
457  template < typename VAL >
458  List< VAL > listMapNodes(VAL (*f)(const NodeId&)) const;
459 
461 
462  private:
463  friend class NodeGraphPartIterator;
465 
467 
468  friend class gum_tests::NodeGraphPartTestSuite;
469 
471  void __updateEndIteratorSafe();
472 
474  void __clearNodes();
475 
478  void __eraseHole(NodeId id);
479 
482  void __addHole(NodeId id);
483 
484  // ############################################################################
486  // ############################################################################
488 
490  bool __inHoles(NodeId id) const;
491 
493  Size __sizeHoles() const;
494 
496 
500  NodeSet* __holes;
501 
503  Size __holes_size;
504 
506  bool __holes_resize_policy;
507 
509  NodeGraphPartIteratorSafe __endIteratorSafe;
510 
512  NodeId __boundVal;
513  };
514 
516  std::ostream& operator<<(std::ostream&, const NodeGraphPart&);
517 
518 } /* namespace gum */
519 
520 #ifndef GUM_NO_INLINE
522 #endif // GUM_NOINLINE
523 
525 
526 #endif // GUM_NODE_GRAPH_PART_H
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: nodeGraphPart.h:64
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
value_type & reference
types for STL compliance
Definition: nodeGraphPart.h:66
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.