bpp-core3  3.0.0
AssociationDAGraphImplObserver.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_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
6 #define BPP_GRAPH_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
7 
8 #include <iostream>
9 #include <map>
10 #include <memory>
11 #include <ostream>
12 #include <vector>
13 
16 #include "DAGraphImpl.h"
17 
18 namespace bpp
19 {
20 template<class N, class E, class DAGraphImpl>
22  public AssociationDAGraphObserver<N, E>,
23  public AssociationGraphImplObserver<N, E, DAGraphImpl>
24 {
25 public:
28 
29  typedef typename Graph::NodeId NodeGraphid;
30  typedef typename Graph::EdgeId EdgeGraphid;
31 
32 public:
39  {}
40 
46  AssociationDAGraphImplObserver(std::shared_ptr<DAGraphImpl> subjectDAGraph) :
47  AssociationGraphImplObserver<N, E, DAGraphImpl>(subjectDAGraph)
48  {}
49 
56  AssociationGraphImplObserver<N, E, DAGraphImpl>(dAGraphObserver)
57  {}
58 
59 
65  template<class N2, class E2>
67  AssociationGraphImplObserver<N, E, DAGraphImpl>(dAGraphObserver)
68  {}
69 
75  {
77  return *this;
78  }
79 
84  {}
85 
90  {
92  }
93 
94 
99  bool isValid() const
100  {
101  return this->getGraph()->isValid();
102  }
103 
108  bool isRooted() const
109  {
110  return this->getGraph()->isRooted();
111  }
112 
113 
119  std::vector<std::shared_ptr<N>> getFathers(const std::shared_ptr<N> node) const
120  {
121  return this->getNodesFromGraphid(this->getGraph()->getFathers(this->getNodeGraphid(node)));
122  }
123 
124  std::vector<NodeIndex> getFathers(const NodeIndex node) const
125  {
126  return this->getNodeIndexes(this->getNodesFromGraphid(this->getGraph()->getFathers(this->getNodeGraphid(this->getNode(node)))));
127  }
128 
134  void rootAt(const std::shared_ptr<N> root)
135  {
136  this->getGraph()->rootAt(this->getNodeGraphid(root));
137  }
138 
142  bool hasFather(const std::shared_ptr<N> nodeObject) const
143  {
144  return this->getGraph()->hasFather(this->getNodeGraphid(nodeObject));
145  }
146 
147  bool hasFather(const NodeIndex node) const
148  {
149  return this->getGraph()->hasFather(this->getNodeGraphid(this->getNode(node)));
150  }
151 
156  std::vector<std::shared_ptr<N>> getSons(const std::shared_ptr<N> node) const
157  {
158  return this->getNodesFromGraphid(this->getGraph()->getSons(this->getNodeGraphid(node)));
159  }
160 
161  std::vector<NodeIndex> getSons(const NodeIndex node) const
162  {
163  return this->getNodeIndexes(this->getNodesFromGraphid(this->getGraph()->getSons(this->getNodeGraphid(this->getNode(node)))));
164  }
165 
166 
172  std::shared_ptr<N> getSon(const std::shared_ptr<E> edge) const
173  {
174  return this->getNodeFromGraphid(this->getGraph()->getBottom(this->getEdgeGraphid(edge)));
175  }
176 
177  NodeIndex getSon(const EdgeIndex edgeId) const
178  {
179  return this->getNodeIndex(this->getNodeFromGraphid(this->getGraph()->getBottom(this->getEdgeGraphid(this->getEdge(edgeId)))));
180  }
181 
182 
188  std::shared_ptr<N> getFatherOfEdge(const std::shared_ptr<E> edge) const
189  {
190  return this->getNodeFromGraphid(this->getGraph()->getTop(this->getEdgeGraphid(edge)));
191  }
192 
193  NodeIndex getFatherOfEdge(const EdgeIndex edge) const
194  {
195  return this->getNodeIndex(this->getNodeFromGraphid(this->getGraph()->getTop(this->getEdgeGraphid(this->getEdge(edge)))));
196  }
197 
203  size_t getNumberOfFathers(const std::shared_ptr<N> node) const
204  {
205  return this->getGraph()->getNumberOfFathers(this->getNodeGraphid(node));
206  }
207 
213  size_t getNumberOfSons(const std::shared_ptr<N> node) const
214  {
215  return this->getGraph()->getNumberOfSons(this->getNodeGraphid(node));
216  }
217 
224  std::vector<std::shared_ptr<N>> getLeavesUnderNode(std::shared_ptr<N> node) const
225  {
226  return this->getNodesFromGraphid(this->getGraph()->getLeavesUnderNode(this->getNodeGraphid(node)));
227  }
228 
233  std::vector<std::shared_ptr<N>> removeFathers(const std::shared_ptr<N> node)
234  {
235  return this->getNodesFromGraphid(this->getGraph()->removeFathers(this->getNodeGraphid(node)));
236  }
237 
242  void removeFather(const std::shared_ptr<N> node, const std::shared_ptr<N> father)
243  {
244  this->getGraph()->removeFather(this->getNodeGraphid(node), this->getNodeGraphid(father));
245  }
246 
251  std::vector<std::shared_ptr<N>> removeSons(const std::shared_ptr<N> node)
252  {
253  return this->getNodesFromGraphid(this->getGraph()->removeSons(this->getNodeGraphid(node)));
254  }
255 
259  void removeSon(const std::shared_ptr<N> node, const std::shared_ptr<N> son)
260  {
261  this->getGraph()->removeSon(this->getNodeGraphid(node), this->getNodeGraphid(son));
262  }
263 
271  void addFather(const std::shared_ptr<N> nodeObject, const std::shared_ptr<N> fatherNodeObject, const std::shared_ptr<E> edgeObject = 0)
272  {
273  if (edgeObject)
274  try
275  {
276  this->getGraph()->addFather(this->getNodeGraphid(nodeObject), this->getNodeGraphid(fatherNodeObject), this->getEdgeGraphid(edgeObject));
277  }
278  catch (Exception& e)
279  {
280  this->link(fatherNodeObject, nodeObject, edgeObject);
281  }
282  else
283  this->getGraph()->addFather(this->getNodeGraphid(nodeObject), this->getNodeGraphid(fatherNodeObject));
284  }
285 
293  void addSon(const std::shared_ptr<N> nodeObject, const std::shared_ptr<N> sonNodeObject, const std::shared_ptr<E> edgeObject = 0)
294  {
295  if (edgeObject)
296  try
297  {
298  this->getGraph()->addSon(this->getNodeGraphid(nodeObject), this->getNodeGraphid(sonNodeObject), this->getEdgeGraphid(edgeObject));
299  }
300  catch (Exception& e)
301  {
302  this->link(nodeObject, sonNodeObject, edgeObject);
303  }
304  else
305  this->getGraph()->addSon(this->getNodeGraphid(nodeObject), this->getNodeGraphid(sonNodeObject));
306  }
307 
313  /*
314  * @brief builds iterator on the fathers of a Node
315  *
316  */
317  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> fathersIterator(std::shared_ptr<N> node)
318  {
319  return this->incomingNeighborNodesIterator(node);
320  }
321 
322  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> fathersIterator(std::shared_ptr<N> node) const
323  {
324  return this->incomingNeighborNodesIterator(node);
325  }
326 
327  /*
328  * @brief builds iterator on the sons of a Node
329  *
330  */
331  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> sonsIterator(std::shared_ptr<N> node)
332  {
333  return this->outgoingNeighborNodesIterator(node);
334  }
335 
336  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> sonsIterator(std::shared_ptr<N> node) const
337  {
338  return this->outgoingNeighborNodesIterator(node);
339  }
340 
348  std::vector<std::shared_ptr<N>> getBelowNodes(const std::shared_ptr<N> localRoot)
349  {
350  return this->getNodesFromGraphid(this->getGraph()->getBelowNodes(this->getNodeGraphid(localRoot)));
351  }
352 
353  std::vector<std::shared_ptr<E>> getBelowEdges(const std::shared_ptr<N> localRoot)
354  {
356  }
357 };
358 
359 /********************/
360 
361 template<class N, class E>
363 
364 /********************/
365 }
366 #endif // BPP_GRAPH_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
void link(Nref nodeObjectA, Nref nodeObjectB, Eref edgeObject=00)
bool hasFather(const std::shared_ptr< N > nodeObject) const
std::vector< std::shared_ptr< N > > removeSons(const std::shared_ptr< N > node)
std::vector< std::shared_ptr< N > > getSons(const std::shared_ptr< N > node) const
size_t getNumberOfSons(const std::shared_ptr< N > node) const
AssociationGraphObserver< N, E >::EdgeIndex EdgeIndex
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > sonsIterator(std::shared_ptr< N > node)
std::vector< Nref > getNodesFromGraphid(std::vector< NodeGraphid > nodes) const
void addSon(const std::shared_ptr< N > nodeObject, const std::shared_ptr< N > sonNodeObject, const std::shared_ptr< E > edgeObject=0)
Defines a DA Graph Associator. It is a template which follows (subscribed to) a Graph.
AssociationDAGraphImplObserver(bpp::AssociationDAGraphImplObserver< N2, E2, DAGraphImpl > const &dAGraphObserver)
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > fathersIterator(std::shared_ptr< N > node) const
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > sonsIterator(std::shared_ptr< N > node) const
AssociationDAGraphImplObserver< N, E, DAGraphImpl > * clone() const
size_t getNumberOfFathers(const std::shared_ptr< N > node) const
std::vector< std::shared_ptr< N > > getLeavesUnderNode(std::shared_ptr< N > node) const
unsigned int NodeId
Definition: Graph.h:30
std::vector< Eref > getEdgesFromGraphid(std::vector< EdgeGraphid > edges) const
AssociationGraphImplObserver< N, E, GraphImpl > & operator=(bpp::AssociationGraphImplObserver< N, E, GraphImpl > const &graphObserver)
std::shared_ptr< N > getSon(const std::shared_ptr< E > edge) const
std::vector< std::shared_ptr< E > > getBelowEdges(const std::shared_ptr< N > localRoot)
NodeIndex getSon(const EdgeIndex edgeId) const
void removeFather(const std::shared_ptr< N > node, const std::shared_ptr< N > father)
void addFather(const std::shared_ptr< N > nodeObject, const std::shared_ptr< N > fatherNodeObject, const std::shared_ptr< E > edgeObject=0)
std::vector< NodeIndex > getNodeIndexes(std::vector< Nref > nodes) const
void removeSon(const std::shared_ptr< N > node, const std::shared_ptr< N > son)
NodeIndex getFatherOfEdge(const EdgeIndex edge) const
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > fathersIterator(std::shared_ptr< N > node)
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
std::vector< NodeIndex > getFathers(const NodeIndex node) const
AssociationDAGraphImplObserver(std::shared_ptr< DAGraphImpl > subjectDAGraph)
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
std::vector< std::shared_ptr< N > > getFathers(const std::shared_ptr< N > node) const
std::vector< std::shared_ptr< N > > removeFathers(const std::shared_ptr< N > node)
std::vector< NodeIndex > getSons(const NodeIndex node) const
std::unique_ptr< typename AssociationGraphObserver< N, E >::NodeIterator > outgoingNeighborNodesIterator(Nref node)
AssociationDAGraphImplObserver< N, E, DAGraphImpl > & operator=(bpp::AssociationDAGraphImplObserver< N, E, DAGraphImpl > const &dAGraphObserver)
std::unique_ptr< typename AssociationGraphObserver< N, E >::NodeIterator > incomingNeighborNodesIterator(Nref node)
void rootAt(const std::shared_ptr< N > root)
Sets the root and make the DAG directed from root to leaves.
AssociationDAGraphImplObserver(bpp::AssociationDAGraphImplObserver< N, E, DAGraphImpl > const &dAGraphObserver)
std::shared_ptr< N > getFatherOfEdge(const std::shared_ptr< E > edge) const
std::vector< std::shared_ptr< N > > getBelowNodes(const std::shared_ptr< N > localRoot)
Get Below Objects.
unsigned int EdgeId
Definition: Graph.h:31