aGrUM  0.14.2
nodeGraphPart.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_NODE_GRAPH_PART_H
26 #define GUM_NODE_GRAPH_PART_H
27 
28 #include <algorithm>
29 #include <utility>
30 
31 #include <agrum/agrum.h>
32 
34 
37 
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 
40 namespace gum_tests {
41 
42  class NodeGraphPartTestSuite;
43 }
44 
45 #endif
46 
47 namespace gum {
48 
49  class NodeGraphPart;
50 
56  friend class NodeGraphPart;
57 
58  public:
61  using iterator_category = std::forward_iterator_tag;
62  using value_type = NodeId;
64  using const_reference = const value_type&;
65  using pointer = value_type*;
66  using const_pointer = const value_type*;
67  using difference_type = std::ptrdiff_t;
69 
70  // ############################################################################
72  // ############################################################################
74 
78  NodeGraphPartIterator(const NodeGraphPart& nodes) noexcept;
79 
81  NodeGraphPartIterator(const NodeGraphPartIterator& it) noexcept;
82 
85 
87  virtual ~NodeGraphPartIterator() noexcept;
88 
90 
91  // ############################################################################
93  // ############################################################################
95 
97  NodeGraphPartIterator& operator=(const NodeGraphPartIterator& it) noexcept;
98 
100  NodeGraphPartIterator& operator=(NodeGraphPartIterator&& it) noexcept;
101 
103  bool operator==(const NodeGraphPartIterator& it) const noexcept;
104 
106  bool operator!=(const NodeGraphPartIterator& it) const noexcept;
107 
109  NodeGraphPartIterator& operator++() noexcept;
110 
112  value_type operator*() const;
113 
115 
116  protected:
118  void _setPos(NodeId id) noexcept;
119 
121  void _validate() noexcept;
122 
124  const NodeGraphPart* _nodes;
125 
127  NodeId _pos{0};
128 
129  // is this iterator still valid ?
130  bool _valid{false};
131  };
132 
138  : public NodeGraphPartIterator
139  , public Listener {
140  friend class NodeGraphPart;
141 
142  public:
145  using iterator_category = std::forward_iterator_tag;
148  using const_reference = const value_type&;
149  using pointer = value_type*;
150  using const_pointer = const value_type*;
151  using difference_type = std::ptrdiff_t;
153 
154  // ############################################################################
156  // ############################################################################
158 
161 
164 
167 
170 
172 
173  // ############################################################################
175  // ############################################################################
177 
180 
183 
185 
186  // ############################################################################
188  // ############################################################################
190 
192 
196  void whenNodeDeleted(const void* src, NodeId id);
197 
199  };
200 
254  public:
262 
263  // something strange with SWIG (with "using", these definitions cored dump
264  // the
265  // swig process)
270 
271  Signaler1< NodeId > onNodeAdded;
272  Signaler1< NodeId > onNodeDeleted;
273 
274  // ############################################################################
276  // ############################################################################
278 
280 
287  explicit NodeGraphPart(Size holes_size = HashTableConst::default_size,
288  bool holes_resize_policy = true);
289 
291 
292  NodeGraphPart(const NodeGraphPart& s);
293 
295  virtual ~NodeGraphPart();
296 
298 
299  // ############################################################################
301  // ############################################################################
303 
305 
306  NodeGraphPart& operator=(const NodeGraphPart& p);
307 
309 
310  bool operator==(const NodeGraphPart& p) const;
311 
313 
314  bool operator!=(const NodeGraphPart& p) const;
315 
317 
318  // ############################################################################
320  // ############################################################################
322 
324 
327  void populateNodes(const NodeGraphPart& s);
328 
330 
332  template < typename T >
333  void populateNodesFromProperty(const NodeProperty< T >& h);
334 
339  NodeId nextNodeId() const;
340 
342 
343  virtual NodeId addNode();
344 
350  std::vector< NodeId > addNodes(Size n);
351 
353 
357  virtual void addNodeWithId(const NodeId id);
358 
360 
364  virtual void eraseNode(const NodeId id);
365 
367  bool existsNode(const NodeId id) const;
368 
370  bool exists(const NodeId id) const;
371 
373  bool emptyNodes() const;
374 
376  bool empty() const;
377 
379  virtual void clearNodes();
380 
382  virtual void clear();
383 
385  Size sizeNodes() const;
386 
388  Size size() const;
389 
391  NodeId bound() const;
392 
394 
401  NodeSet asNodeSet() const;
402 
404  const NodeGraphPart& nodes() const;
405 
408  node_iterator_safe beginSafe() const;
409 
412  const node_iterator_safe& endSafe() const noexcept;
413 
416  node_iterator begin() const noexcept;
417 
420  const node_iterator& end() const noexcept;
421 
423  std::string toString() const;
424 
426 
435  template < typename VAL >
436  NodeProperty< VAL > nodesProperty(VAL (*f)(const NodeId&),
437  Size size = 0) const;
438 
440 
450  template < typename VAL >
451  NodeProperty< VAL > nodesProperty(const VAL& a, Size size = 0) const;
452 
456  template < typename VAL >
457  List< VAL > listMapNodes(VAL (*f)(const NodeId&)) const;
458 
460 
461  private:
462  friend class NodeGraphPartIterator;
464 
466 
467  friend class gum_tests::NodeGraphPartTestSuite;
468 
470  void __updateEndIteratorSafe();
471 
473  void __clearNodes();
474 
477  void __eraseHole(NodeId id);
478 
481  void __addHole(NodeId id);
482 
483  // ############################################################################
485  // ############################################################################
487 
489  bool __inHoles(NodeId id) const;
490 
492  Size __sizeHoles() const;
493 
495 
499  NodeSet* __holes;
500 
502  Size __holes_size;
503 
505  bool __holes_resize_policy;
506 
508  NodeGraphPartIteratorSafe __endIteratorSafe;
509 
511  NodeId __boundVal;
512  };
513 
515  std::ostream& operator<<(std::ostream&, const NodeGraphPart&);
516 
517 } /* namespace gum */
518 
519 #ifndef GUM_NO_INLINE
521 #endif // GUM_NOINLINE
522 
524 
525 #endif // GUM_NODE_GRAPH_PART_H
std::forward_iterator_tag iterator_category
types for STL compliance
Definition: nodeGraphPart.h:61
Inline implementation of the base node set class for graphs.
value_type & reference
types for STL compliance
Definition: nodeGraphPart.h:63
Class of listener.
NodeGraphPartIterator NodeConstIterator
NodeId value_type
types for STL compliance
Definition: nodeGraphPart.h:62
STL namespace.
NodeGraphPartIteratorSafe NodeIteratorSafe
Generic doubly linked lists.
Definition: list.h:369
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
Classes of signaler.
NodeGraphPartIteratorSafe NodeConstIteratorSafe
Unsafe iterator on the node set of a graph.
Definition: nodeGraphPart.h:55
Signaler1< NodeId > onNodeAdded
const value_type * const_pointer
types for STL compliance
Definition: nodeGraphPart.h:66
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:243
std::ptrdiff_t difference_type
types for STL compliance
Definition: nodeGraphPart.h:67
Class for node sets in graph.
const value_type & const_reference
types for STL compliance
Definition: nodeGraphPart.h:64
NodeGraphPartIterator NodeIterator
NodeId nextNodeId()
Returns the next value of an unique counter for PRM&#39;s node id.
Definition: utils_prm.cpp:63
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.h:251
Implementation of the NodeGraphPart.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Signaler1< NodeId > onNodeDeleted
Safe iterator on the node set of a graph.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Every class who would catch signal from signaler should derive from Listener.
Definition: listener.h:72
value_type * pointer
types for STL compliance
Definition: nodeGraphPart.h:65
some utils for topology : NodeId, Edge, Arc and consorts ...