bpp-core3  3.0.0
AssociationGraphObserver.h
Go to the documentation of this file.
1 //
2 // File: AssociationGraphObserver.h
3 // Authors:
4 // Thomas Bigot
5 // Last modified: vendredi 4 novembre 2016, à 10h 21
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide utilitary
12  classes. This file belongs to the Bio++ Project.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
42 #define BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
43 
44 #include <iostream>
45 #include <map>
46 #include <memory>
47 #include <ostream>
48 #include <type_traits>
49 #include <vector>
50 
51 #include "../Clonable.h"
52 #include "../Exceptions.h"
53 #include "GraphObserver.h"
54 
55 namespace bpp
56 {
64 template<class N, class E>
66  public virtual GraphObserver
67 {
68 private:
71 
72 public:
73  typedef unsigned int NodeIndex;
74  typedef unsigned int EdgeIndex;
75 
81  template<class A, class B>
82  static B* copy(const A& a, typename std::enable_if< !std::is_base_of<B, A>::value && !std::is_abstract<B>::value, B*>::type* = 0)
83  {
84  return new B(a);
85  }
86 
87  template<class A, class B>
88  static B* copy(const A& a, typename std::enable_if< !std::is_base_of<B, A>::value && std::is_abstract<B>::value, B*>::type* = 0)
89  {
90  throw Exception("Unknow AssociationGraphObserver::copy(const A& a, typename std::enable_if< !std::is_base_of<B, A>::value&& std::is_abstract<B>::value, B*>::type* = 0)");
91  return 0;
92  }
93 
94  template<class A, class B>
95  static B* copy(const A& a, typename std::enable_if< std::is_base_of<B, A>::value && !std::is_abstract<A>::value, B*>::type* = 0)
96  {
97  return dynamic_cast<B*>(new A(a));
98  }
99 
100  template<class A, class B>
101  static B* copy(const A& a, typename std::enable_if< std::is_base_of<B, A>::value && std::is_abstract<A>::value && std::is_base_of<Clonable, A>::value, B*>::type* = 0)
102  {
103  return dynamic_cast<B*>(a.clone());
104  }
105 
106  template<class A, class B>
107  static B* copy(const A& a, typename std::enable_if< std::is_base_of<B, A>::value && std::is_abstract<A>::value && !std::is_base_of<Clonable, A>::value, B*>::type* = 0)
108  {
109  throw Exception("Unknow AssociationGraphObserver::copy(const A& a, typename std::enable_if< std::is_base_of<B, A>::value&& std::is_abstract<A>::value && !std::is_base_of<Clonable, A>::value, B*>::type*= 0)");
110  return 0;
111  }
112 
113 
117  // /@{
118 
124  virtual void createNode(std::shared_ptr<N> newNodeObject) = 0;
125 
126 
136  virtual void createNode(std::shared_ptr<N> objectOriginNode, std::shared_ptr<N> newNodeObject, std::shared_ptr<E> newEdgeObject = 00) = 0;
137 
147  virtual void link(std::shared_ptr<N> nodeObjectA, std::shared_ptr<N> nodeObjectB, std::shared_ptr<E> edgeObject = 00) = 0;
148 
156  virtual void unlink(std::shared_ptr<N> nodeObjectA, std::shared_ptr<N> nodeObjectB) = 0;
157 
162  virtual void deleteNode(std::shared_ptr<N> nodeObject) = 0;
163 
164  // /@}
165 
169  // /@{
170 
177  virtual void associateNode(std::shared_ptr<N> nodeObject, NodeGraphid node) = 0;
178 
185  virtual void associateEdge(std::shared_ptr<E> edgeObject, EdgeGraphid edge) = 0;
186 
194  virtual void dissociateNode(std::shared_ptr<N> nodeObject) = 0;
195  virtual void dissociateEdge(std::shared_ptr<E> edgeObject) = 0;
196 
197 
203  virtual NodeGraphid getNodeGraphid(const std::shared_ptr<N> nodeObject) const = 0;
204 
210  virtual EdgeGraphid getEdgeGraphid(const std::shared_ptr<E> edgeObject) const = 0;
211 
215  virtual const std::shared_ptr<N> getNodeFromGraphid(NodeGraphid) const = 0;
216  virtual std::shared_ptr<N> getNodeFromGraphid(NodeGraphid) = 0;
217 
218  virtual std::vector<std::shared_ptr<N> > getNodesFromGraphid(std::vector<NodeGraphid> ) const = 0;
219  virtual std::shared_ptr<E> getEdgeFromGraphid(EdgeGraphid) = 0;
220  virtual const std::shared_ptr<E> getEdgeFromGraphid(EdgeGraphid) const = 0;
221  virtual std::vector<std::shared_ptr<E> > getEdgesFromGraphid(std::vector<EdgeGraphid> ) const = 0;
222 
223 
228  virtual std::shared_ptr<N> getRoot() const = 0;
229 
230  virtual NodeIndex getRootIndex() const = 0;
231 
232  // /@}
233 
234 
238  // /@{
239 
244  virtual bool hasNodeIndex(const std::shared_ptr<N> nodeObject) const = 0;
245  virtual bool hasEdgeIndex(const std::shared_ptr<E> edgeObject) const = 0;
246 
253  virtual NodeIndex getNodeIndex(const std::shared_ptr<N> nodeObject) const = 0;
254  virtual std::vector<NodeIndex> getNodeIndexes(std::vector<std::shared_ptr<N> > nodeObjects) const = 0;
255 
256 
262  virtual EdgeIndex getEdgeIndex(const std::shared_ptr<E> edgeObject) const = 0;
263  virtual std::vector<EdgeIndex> getEdgeIndexes(std::vector<std::shared_ptr<E> > edgeObjects) const = 0;
264 
271  virtual NodeIndex setNodeIndex(const std::shared_ptr<N> nodeObject, NodeIndex index) = 0;
272 
279  virtual EdgeIndex setEdgeIndex(const std::shared_ptr<E> edgeObject, EdgeIndex index) = 0;
280 
286  virtual bool hasNode(NodeIndex nodeIndex) const = 0;
287 
293  virtual bool hasEdge(EdgeIndex edgeIndex) const = 0;
294 
301  virtual std::shared_ptr<N> getNode(NodeIndex nodeIndex) const = 0;
302 
308  virtual std::shared_ptr<E> getEdge(EdgeIndex edgeIndex) const = 0;
309 
310  // /@}
311 
315  // /@{
316 
323  {
324 public:
325  virtual ~NodeIterator() {}
326 
327  virtual void next() = 0;
328  virtual bool end() const = 0;
329  virtual void start() = 0;
330 
331  virtual std::shared_ptr<N> operator*() = 0;
332  };
333 
334 
335  /*
336  * @brief builds iterator on all Nodes of the graph
337  *
338  */
339 
340  virtual std::unique_ptr<NodeIterator> allNodesIterator() = 0;
341 
342  virtual std::unique_ptr<NodeIterator> allNodesIterator() const = 0;
343 
344  /*
345  * @brief builds iterator on the outgoing neighbor nodes of a Node
346  *
347  */
348 
349  virtual std::unique_ptr<NodeIterator> outgoingNeighborNodesIterator(std::shared_ptr<N> node) = 0;
350 
351  virtual std::unique_ptr<NodeIterator> outgoingNeighborNodesIterator(std::shared_ptr<N> node) const = 0;
352 
353  /*
354  * @brief builds iterator on the incoming neighbor nodes of a Node
355  *
356  */
357 
358  virtual std::unique_ptr<NodeIterator> incomingNeighborNodesIterator(std::shared_ptr<N> node) = 0;
359 
360  virtual std::unique_ptr<NodeIterator> incomingNeighborNodesIterator(std::shared_ptr<N> node) const = 0;
361 
368  virtual std::vector<std::shared_ptr<N> > getNeighbors(const std::shared_ptr<N> node) const = 0;
369  virtual std::vector<NodeIndex> getNeighbors(NodeIndex node) const = 0;
370 
376  virtual std::vector<std::shared_ptr<E> > getEdges(const std::shared_ptr<N> node) const = 0;
377  virtual std::vector<EdgeIndex> getEdges(NodeIndex node) const = 0;
378 
385  virtual std::vector<std::shared_ptr<N> > getOutgoingNeighbors(const std::shared_ptr<N> node) const = 0;
386  virtual std::vector<NodeIndex> getOutgoingNeighbors(NodeIndex node) const = 0;
387 
394  virtual std::vector<std::shared_ptr<E> > getOutgoingEdges(const std::shared_ptr<N> node) const = 0;
395  virtual std::vector<EdgeIndex> getOutgoingEdges(NodeIndex node) const = 0;
396 
397 
404  virtual std::vector<std::shared_ptr<N> > getIncomingNeighbors(const std::shared_ptr<N> node) const = 0;
405  virtual std::vector<NodeIndex> getIncomingNeighbors(NodeIndex node) const = 0;
406 
413  virtual std::vector<std::shared_ptr<E> > getIncomingEdges(const std::shared_ptr<N> node) const = 0;
414  virtual std::vector<EdgeIndex> getIncomingEdges(NodeIndex node) const = 0;
415 
416 
424  virtual std::vector<std::shared_ptr<N> > getLeavesFromNode(std::shared_ptr<N> node, unsigned int maxDepth) const = 0;
425 
430  virtual std::vector<std::shared_ptr<N> > getAllLeaves() const = 0;
431  virtual std::vector<NodeIndex> getAllLeavesIndexes() const = 0;
432 
437  virtual std::vector<std::shared_ptr<N> > getAllInnerNodes() const = 0;
438  virtual std::vector<NodeIndex> getAllInnerNodesIndexes() const = 0;
439 
444  virtual std::vector<std::shared_ptr<N> > getAllNodes() const = 0;
445  virtual std::vector<NodeIndex> getAllNodesIndexes() const = 0;
446 
453  {
454 public:
455  virtual ~EdgeIterator() {}
456 
457  virtual void next() = 0;
458  virtual bool end() const = 0;
459  virtual void start() = 0;
460 
461  virtual std::shared_ptr<E> operator*() = 0;
462  };
463 
464 
465  /*
466  * @brief builds iterator on all Nodes of the graph
467  *
468  */
469 
470  virtual std::unique_ptr<EdgeIterator> allEdgesIterator() = 0;
471 
472  /*
473  * @brief builds iterator on the outgoing neighbor nodes of a Node
474  *
475  */
476 
477  virtual std::unique_ptr<EdgeIterator> outgoingEdgesIterator(std::shared_ptr<N> node) = 0;
478 
479  /*
480  * @brief builds iterator on the incoming neighbor nodes of a Node
481  *
482  */
483 
484  virtual std::unique_ptr<EdgeIterator> incomingEdgesIterator(std::shared_ptr<N> node) = 0;
485 
491  virtual std::vector<std::shared_ptr<E> > getAllEdges() const = 0;
492  virtual std::vector<EdgeIndex> getAllEdgesIndexes() const = 0;
493 
494 
501  virtual std::shared_ptr<E> getEdgeLinking(std::shared_ptr<N> nodeA, std::shared_ptr<N> nodeB) const = 0;
502 
509  virtual void setEdgeLinking(std::shared_ptr<N> nodeA, std::shared_ptr<N> nodeB, std::shared_ptr<E> edge) = 0;
510 
511  // /@}
512 };
513 }
514 #endif // BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
virtual std::shared_ptr< E > operator*()=0
virtual std::shared_ptr< N > operator*()=0
Defines a Graph Associator. It is a template which follows (subscribed to) a Graph.
virtual std::vector< std::shared_ptr< N > > getNodesFromGraphid(std::vector< NodeGraphid >) const =0
virtual std::vector< std::shared_ptr< E > > getIncomingEdges(const std::shared_ptr< N > node) const =0
virtual std::vector< std::shared_ptr< E > > getEdges(const std::shared_ptr< N > node) const =0
virtual std::vector< std::shared_ptr< N > > getAllLeaves() const =0
virtual std::shared_ptr< N > getNode(NodeIndex nodeIndex) const =0
static B * copy(const A &a, typename std::enable_if< !std::is_base_of< B, A >::value &&std::is_abstract< B >::value, B * >::type *=0)
virtual std::vector< EdgeIndex > getAllEdgesIndexes() const =0
virtual std::unique_ptr< EdgeIterator > allEdgesIterator()=0
virtual std::vector< NodeIndex > getAllInnerNodesIndexes() const =0
virtual std::vector< std::shared_ptr< E > > getEdgesFromGraphid(std::vector< EdgeGraphid >) const =0
virtual NodeGraphid getNodeGraphid(const std::shared_ptr< N > nodeObject) const =0
virtual std::vector< EdgeIndex > getIncomingEdges(NodeIndex node) const =0
virtual void link(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB, std::shared_ptr< E > edgeObject=00)=0
virtual std::vector< std::shared_ptr< E > > getAllEdges() const =0
virtual NodeIndex setNodeIndex(const std::shared_ptr< N > nodeObject, NodeIndex index)=0
virtual std::unique_ptr< NodeIterator > outgoingNeighborNodesIterator(std::shared_ptr< N > node)=0
virtual void createNode(std::shared_ptr< N > objectOriginNode, std::shared_ptr< N > newNodeObject, std::shared_ptr< E > newEdgeObject=00)=0
virtual void associateNode(std::shared_ptr< N > nodeObject, NodeGraphid node)=0
static B * copy(const A &a, typename std::enable_if< std::is_base_of< B, A >::value &&std::is_abstract< A >::value &&std::is_base_of< Clonable, A >::value, B * >::type *=0)
virtual void setEdgeLinking(std::shared_ptr< N > nodeA, std::shared_ptr< N > nodeB, std::shared_ptr< E > edge)=0
virtual void deleteNode(std::shared_ptr< N > nodeObject)=0
virtual std::shared_ptr< N > getRoot() const =0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const =0
static B * copy(const A &a, typename std::enable_if< std::is_base_of< B, A >::value &&std::is_abstract< A >::value &&!std::is_base_of< Clonable, A >::value, B * >::type *=0)
virtual std::unique_ptr< EdgeIterator > outgoingEdgesIterator(std::shared_ptr< N > node)=0
virtual EdgeGraphid getEdgeGraphid(const std::shared_ptr< E > edgeObject) const =0
virtual bool hasNodeIndex(const std::shared_ptr< N > nodeObject) const =0
return if the object has an index.
virtual std::vector< std::shared_ptr< N > > getAllNodes() const =0
virtual NodeIndex getRootIndex() const =0
virtual std::unique_ptr< EdgeIterator > incomingEdgesIterator(std::shared_ptr< N > node)=0
virtual std::vector< NodeIndex > getNodeIndexes(std::vector< std::shared_ptr< N > > nodeObjects) const =0
virtual std::shared_ptr< N > getNodeFromGraphid(NodeGraphid)=0
virtual std::vector< EdgeIndex > getEdges(NodeIndex node) const =0
virtual void dissociateNode(std::shared_ptr< N > nodeObject)=0
virtual void unlink(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB)=0
virtual std::vector< EdgeIndex > getEdgeIndexes(std::vector< std::shared_ptr< E > > edgeObjects) const =0
virtual EdgeIndex setEdgeIndex(const std::shared_ptr< E > edgeObject, EdgeIndex index)=0
virtual std::shared_ptr< E > getEdgeFromGraphid(EdgeGraphid)=0
virtual NodeIndex getNodeIndex(const std::shared_ptr< N > nodeObject) const =0
virtual std::vector< NodeIndex > getOutgoingNeighbors(NodeIndex node) const =0
virtual std::vector< std::shared_ptr< E > > getOutgoingEdges(const std::shared_ptr< N > node) const =0
virtual bool hasEdgeIndex(const std::shared_ptr< E > edgeObject) const =0
virtual std::vector< NodeIndex > getAllNodesIndexes() const =0
virtual std::vector< std::shared_ptr< N > > getAllInnerNodes() const =0
static B * copy(const A &a, typename std::enable_if< !std::is_base_of< B, A >::value &&!std::is_abstract< B >::value, B * >::type *=0)
virtual std::vector< NodeIndex > getIncomingNeighbors(NodeIndex node) const =0
virtual bool hasNode(NodeIndex nodeIndex) const =0
virtual std::vector< std::shared_ptr< N > > getLeavesFromNode(std::shared_ptr< N > node, unsigned int maxDepth) const =0
static B * copy(const A &a, typename std::enable_if< std::is_base_of< B, A >::value &&!std::is_abstract< A >::value, B * >::type *=0)
virtual std::vector< std::shared_ptr< N > > getNeighbors(const std::shared_ptr< N > node) const =0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const =0
virtual std::shared_ptr< E > getEdgeLinking(std::shared_ptr< N > nodeA, std::shared_ptr< N > nodeB) const =0
virtual std::unique_ptr< NodeIterator > allNodesIterator() const =0
virtual std::unique_ptr< NodeIterator > allNodesIterator()=0
virtual std::vector< std::shared_ptr< N > > getIncomingNeighbors(const std::shared_ptr< N > node) const =0
virtual const std::shared_ptr< E > getEdgeFromGraphid(EdgeGraphid) const =0
virtual std::vector< NodeIndex > getNeighbors(NodeIndex node) const =0
virtual std::vector< NodeIndex > getAllLeavesIndexes() const =0
virtual bool hasEdge(EdgeIndex edgeIndex) const =0
virtual std::unique_ptr< NodeIterator > outgoingNeighborNodesIterator(std::shared_ptr< N > node) const =0
virtual void associateEdge(std::shared_ptr< E > edgeObject, EdgeGraphid edge)=0
virtual std::vector< std::shared_ptr< N > > getOutgoingNeighbors(const std::shared_ptr< N > node) const =0
virtual const std::shared_ptr< N > getNodeFromGraphid(NodeGraphid) const =0
virtual std::unique_ptr< NodeIterator > incomingNeighborNodesIterator(std::shared_ptr< N > node)=0
virtual void dissociateEdge(std::shared_ptr< E > edgeObject)=0
virtual std::vector< EdgeIndex > getOutgoingEdges(NodeIndex node) const =0
virtual std::unique_ptr< NodeIterator > incomingNeighborNodesIterator(std::shared_ptr< N > node) const =0
virtual void createNode(std::shared_ptr< N > newNodeObject)=0
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
Defines a Graph Observer. It is a template which follows (subscribed to) a Graph. The graph and the g...
Definition: GraphObserver.h:69
unsigned int NodeId
Definition: Graph.h:66
unsigned int EdgeId
Definition: Graph.h:67