bpp-core3  3.0.0
AssociationGraphObserver.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
6 #define BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
7 
8 #include <iostream>
9 #include <map>
10 #include <memory>
11 #include <ostream>
12 #include <type_traits>
13 #include <vector>
14 
15 #include "../Clonable.h"
16 #include "../Exceptions.h"
17 #include "GraphObserver.h"
18 
19 namespace bpp
20 {
28 template<class N, class E>
30  public virtual GraphObserver
31 {
32 private:
35 
36 public:
37  typedef unsigned int NodeIndex;
38  typedef unsigned int EdgeIndex;
39 
44  template<class A, class B>
45  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)
46  {
47  return new B(a);
48  }
49 
50  template<class A, class B>
51  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)
52  {
53  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)");
54  return 0;
55  }
56 
57  template<class A, class B>
58  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)
59  {
60  return dynamic_cast<B*>(new A(a));
61  }
62 
63  template<class A, class B>
64  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)
65  {
66  return dynamic_cast<B*>(a.clone());
67  }
68 
69  template<class A, class B>
70  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)
71  {
72  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)");
73  return 0;
74  }
75 
76 
80  // /@{
81 
87  virtual void createNode(std::shared_ptr<N> newNodeObject) = 0;
88 
89 
99  virtual void createNode(std::shared_ptr<N> objectOriginNode, std::shared_ptr<N> newNodeObject, std::shared_ptr<E> newEdgeObject = 00) = 0;
100 
110  virtual void link(std::shared_ptr<N> nodeObjectA, std::shared_ptr<N> nodeObjectB, std::shared_ptr<E> edgeObject = 00) = 0;
111 
119  virtual void unlink(std::shared_ptr<N> nodeObjectA, std::shared_ptr<N> nodeObjectB) = 0;
120 
125  virtual void deleteNode(std::shared_ptr<N> nodeObject) = 0;
126 
127  // /@}
128 
132  // /@{
133 
140  virtual void associateNode(std::shared_ptr<N> nodeObject, NodeGraphid node) = 0;
141 
148  virtual void associateEdge(std::shared_ptr<E> edgeObject, EdgeGraphid edge) = 0;
149 
157  virtual void dissociateNode(std::shared_ptr<N> nodeObject) = 0;
158  virtual void dissociateEdge(std::shared_ptr<E> edgeObject) = 0;
159 
160 
166  virtual NodeGraphid getNodeGraphid(const std::shared_ptr<N> nodeObject) const = 0;
167 
173  virtual EdgeGraphid getEdgeGraphid(const std::shared_ptr<E> edgeObject) const = 0;
174 
178  virtual const std::shared_ptr<N> getNodeFromGraphid(NodeGraphid) const = 0;
179  virtual std::shared_ptr<N> getNodeFromGraphid(NodeGraphid) = 0;
180 
181  virtual std::vector<std::shared_ptr<N>> getNodesFromGraphid(std::vector<NodeGraphid> ) const = 0;
182  virtual std::shared_ptr<E> getEdgeFromGraphid(EdgeGraphid) = 0;
183  virtual const std::shared_ptr<E> getEdgeFromGraphid(EdgeGraphid) const = 0;
184  virtual std::vector<std::shared_ptr<E>> getEdgesFromGraphid(std::vector<EdgeGraphid> ) const = 0;
185 
186 
191  virtual std::shared_ptr<N> getRoot() const = 0;
192 
193  virtual NodeIndex getRootIndex() const = 0;
194 
195  // /@}
196 
197 
201  // /@{
202 
207  virtual bool hasNodeIndex(const std::shared_ptr<N> nodeObject) const = 0;
208  virtual bool hasEdgeIndex(const std::shared_ptr<E> edgeObject) const = 0;
209 
216  virtual NodeIndex getNodeIndex(const std::shared_ptr<N> nodeObject) const = 0;
217  virtual std::vector<NodeIndex> getNodeIndexes(std::vector<std::shared_ptr<N>> nodeObjects) const = 0;
218 
219 
225  virtual EdgeIndex getEdgeIndex(const std::shared_ptr<E> edgeObject) const = 0;
226  virtual std::vector<EdgeIndex> getEdgeIndexes(std::vector<std::shared_ptr<E>> edgeObjects) const = 0;
227 
234  virtual NodeIndex setNodeIndex(const std::shared_ptr<N> nodeObject, NodeIndex index) = 0;
235 
242  virtual EdgeIndex setEdgeIndex(const std::shared_ptr<E> edgeObject, EdgeIndex index) = 0;
243 
249  virtual bool hasNode(NodeIndex nodeIndex) const = 0;
250 
256  virtual bool hasEdge(EdgeIndex edgeIndex) const = 0;
257 
264  virtual std::shared_ptr<N> getNode(NodeIndex nodeIndex) const = 0;
265 
271  virtual std::shared_ptr<E> getEdge(EdgeIndex edgeIndex) const = 0;
272 
273  // /@}
274 
278  // /@{
279 
286  {
287 public:
288  virtual ~NodeIterator() {}
289 
290  virtual void next() = 0;
291  virtual bool end() const = 0;
292  virtual void start() = 0;
293 
294  virtual std::shared_ptr<N> operator*() = 0;
295  };
296 
297 
298  /*
299  * @brief builds iterator on all Nodes of the graph
300  *
301  */
302 
303  virtual std::unique_ptr<NodeIterator> allNodesIterator() = 0;
304 
305  virtual std::unique_ptr<NodeIterator> allNodesIterator() const = 0;
306 
307  /*
308  * @brief builds iterator on the outgoing neighbor nodes of a Node
309  *
310  */
311 
312  virtual std::unique_ptr<NodeIterator> outgoingNeighborNodesIterator(std::shared_ptr<N> node) = 0;
313 
314  virtual std::unique_ptr<NodeIterator> outgoingNeighborNodesIterator(std::shared_ptr<N> node) const = 0;
315 
316  /*
317  * @brief builds iterator on the incoming neighbor nodes of a Node
318  *
319  */
320 
321  virtual std::unique_ptr<NodeIterator> incomingNeighborNodesIterator(std::shared_ptr<N> node) = 0;
322 
323  virtual std::unique_ptr<NodeIterator> incomingNeighborNodesIterator(std::shared_ptr<N> node) const = 0;
324 
331  virtual std::vector<std::shared_ptr<N>> getNeighbors(const std::shared_ptr<N> node) const = 0;
332  virtual std::vector<NodeIndex> getNeighbors(NodeIndex node) const = 0;
333 
339  virtual std::vector<std::shared_ptr<E>> getEdges(const std::shared_ptr<N> node) const = 0;
340  virtual std::vector<EdgeIndex> getEdges(NodeIndex node) const = 0;
341 
348  virtual std::vector<std::shared_ptr<N>> getOutgoingNeighbors(const std::shared_ptr<N> node) const = 0;
349  virtual std::vector<NodeIndex> getOutgoingNeighbors(NodeIndex node) const = 0;
350 
357  virtual std::vector<std::shared_ptr<E>> getOutgoingEdges(const std::shared_ptr<N> node) const = 0;
358  virtual std::vector<EdgeIndex> getOutgoingEdges(NodeIndex node) const = 0;
359 
360 
367  virtual std::vector<std::shared_ptr<N>> getIncomingNeighbors(const std::shared_ptr<N> node) const = 0;
368  virtual std::vector<NodeIndex> getIncomingNeighbors(NodeIndex node) const = 0;
369 
376  virtual std::vector<std::shared_ptr<E>> getIncomingEdges(const std::shared_ptr<N> node) const = 0;
377  virtual std::vector<EdgeIndex> getIncomingEdges(NodeIndex node) const = 0;
378 
379 
387  virtual std::vector<std::shared_ptr<N>> getLeavesFromNode(std::shared_ptr<N> node, unsigned int maxDepth) const = 0;
388 
393  virtual std::vector<std::shared_ptr<N>> getAllLeaves() const = 0;
394  virtual std::vector<NodeIndex> getAllLeavesIndexes() const = 0;
395 
400  virtual std::vector<std::shared_ptr<N>> getAllInnerNodes() const = 0;
401  virtual std::vector<NodeIndex> getAllInnerNodesIndexes() const = 0;
402 
407  virtual std::vector<std::shared_ptr<N>> getAllNodes() const = 0;
408  virtual std::vector<NodeIndex> getAllNodesIndexes() const = 0;
409 
416  {
417 public:
418  virtual ~EdgeIterator() {}
419 
420  virtual void next() = 0;
421  virtual bool end() const = 0;
422  virtual void start() = 0;
423 
424  virtual std::shared_ptr<E> operator*() = 0;
425  };
426 
427 
428  /*
429  * @brief builds iterator on all Nodes of the graph
430  *
431  */
432 
433  virtual std::unique_ptr<EdgeIterator> allEdgesIterator() = 0;
434 
435  /*
436  * @brief builds iterator on the outgoing neighbor nodes of a Node
437  *
438  */
439 
440  virtual std::unique_ptr<EdgeIterator> outgoingEdgesIterator(std::shared_ptr<N> node) = 0;
441 
442  /*
443  * @brief builds iterator on the incoming neighbor nodes of a Node
444  *
445  */
446 
447  virtual std::unique_ptr<EdgeIterator> incomingEdgesIterator(std::shared_ptr<N> node) = 0;
448 
454  virtual std::vector<std::shared_ptr<E>> getAllEdges() const = 0;
455  virtual std::vector<EdgeIndex> getAllEdgesIndexes() const = 0;
456 
457 
464  virtual std::shared_ptr<E> getEdgeLinking(std::shared_ptr<N> nodeA, std::shared_ptr<N> nodeB) const = 0;
465 
472  virtual void setEdgeLinking(std::shared_ptr<N> nodeA, std::shared_ptr<N> nodeB, std::shared_ptr<E> edge) = 0;
473 
474  // /@}
475 };
476 }
477 #endif // BPP_GRAPH_ASSOCIATIONGRAPHOBSERVER_H
virtual std::unique_ptr< NodeIterator > incomingNeighborNodesIterator(std::shared_ptr< N > node)=0
virtual std::vector< std::shared_ptr< E > > getIncomingEdges(const std::shared_ptr< N > node) const =0
virtual std::vector< std::shared_ptr< N > > getNodesFromGraphid(std::vector< NodeGraphid >) const =0
Defines a Graph Associator. It is a template which follows (subscribed to) a Graph.
virtual std::vector< std::shared_ptr< N > > getLeavesFromNode(std::shared_ptr< N > node, unsigned int maxDepth) const =0
virtual std::vector< EdgeIndex > getAllEdgesIndexes() const =0
virtual std::unique_ptr< EdgeIterator > outgoingEdgesIterator(std::shared_ptr< N > node)=0
virtual std::vector< NodeIndex > getAllNodesIndexes() 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::shared_ptr< E > getEdgeFromGraphid(EdgeGraphid)=0
virtual std::vector< std::shared_ptr< N > > getAllInnerNodes() const =0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const =0
virtual void unlink(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB)=0
virtual std::vector< std::shared_ptr< E > > getAllEdges() 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::vector< std::shared_ptr< N > > getAllLeaves() const =0
virtual bool hasNode(NodeIndex nodeIndex) const =0
virtual EdgeGraphid getEdgeGraphid(const std::shared_ptr< E > edgeObject) const =0
virtual std::unique_ptr< EdgeIterator > allEdgesIterator()=0
virtual NodeGraphid getNodeGraphid(const std::shared_ptr< N > nodeObject) const =0
unsigned int NodeId
Definition: Graph.h:30
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< B >::value, B *>::type *=0)
virtual std::vector< std::shared_ptr< E > > getEdgesFromGraphid(std::vector< EdgeGraphid >) const =0
virtual void deleteNode(std::shared_ptr< N > nodeObject)=0
virtual bool hasNodeIndex(const std::shared_ptr< N > nodeObject) const =0
return if the object has an index.
virtual NodeIndex getNodeIndex(const std::shared_ptr< N > nodeObject) const =0
virtual std::vector< std::shared_ptr< N > > getAllNodes() const =0
virtual std::vector< EdgeIndex > getEdgeIndexes(std::vector< std::shared_ptr< E >> edgeObjects) const =0
virtual std::vector< std::shared_ptr< E > > getOutgoingEdges(const std::shared_ptr< N > node) const =0
virtual std::unique_ptr< NodeIterator > outgoingNeighborNodesIterator(std::shared_ptr< N > node)=0
virtual std::shared_ptr< N > operator*()=0
virtual void link(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB, std::shared_ptr< E > edgeObject=00)=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 > incomingEdgesIterator(std::shared_ptr< N > node)=0
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
virtual void dissociateNode(std::shared_ptr< N > nodeObject)=0
virtual std::unique_ptr< NodeIterator > allNodesIterator()=0
virtual std::shared_ptr< N > getRoot() const =0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const =0
virtual EdgeIndex setEdgeIndex(const std::shared_ptr< E > edgeObject, EdgeIndex index)=0
virtual void setEdgeLinking(std::shared_ptr< N > nodeA, std::shared_ptr< N > nodeB, std::shared_ptr< E > edge)=0
virtual std::vector< std::shared_ptr< N > > getNeighbors(const std::shared_ptr< N > node) const =0
virtual NodeIndex setNodeIndex(const std::shared_ptr< N > nodeObject, NodeIndex index)=0
virtual const std::shared_ptr< N > getNodeFromGraphid(NodeGraphid) const =0
virtual std::shared_ptr< E > getEdgeLinking(std::shared_ptr< N > nodeA, std::shared_ptr< N > nodeB) 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< E > > getEdges(const std::shared_ptr< N > node) const =0
Defines a Graph Observer. It is a template which follows (subscribed to) a Graph. The graph and the g...
Definition: GraphObserver.h:31
virtual std::vector< NodeIndex > getNodeIndexes(std::vector< std::shared_ptr< N >> nodeObjects) const =0
virtual std::vector< NodeIndex > getAllInnerNodesIndexes() const =0
virtual void createNode(std::shared_ptr< N > newNodeObject)=0
virtual bool hasEdgeIndex(const std::shared_ptr< E > edgeObject) const =0
virtual std::vector< std::shared_ptr< N > > getIncomingNeighbors(const std::shared_ptr< N > node) const =0
virtual void dissociateEdge(std::shared_ptr< E > edgeObject)=0
virtual NodeIndex getRootIndex() const =0
unsigned int EdgeId
Definition: Graph.h:31
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 std::shared_ptr< N > getNode(NodeIndex nodeIndex) const =0
virtual bool hasEdge(EdgeIndex edgeIndex) const =0
virtual std::vector< NodeIndex > getAllLeavesIndexes() const =0