bpp-core3  3.0.0
AssociationDAGraphImplObserver.h
Go to the documentation of this file.
1 //
2 // File: AssociationDAGraphImplObserver.h
3 // Authors:
4 // Laurent Guéguen
5 // Last modified: lundi 19 décembre 2016, à 22h 14
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_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
42 #define BPP_GRAPH_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
43 
44 #include <iostream>
45 #include <map>
46 #include <memory>
47 #include <ostream>
48 #include <vector>
49 
52 #include "DAGraphImpl.h"
53 
54 namespace bpp
55 {
56 template<class N, class E, class DAGraphImpl>
58  public AssociationDAGraphObserver<N, E>,
59  public AssociationGraphImplObserver<N, E, DAGraphImpl>
60 {
61 public:
64 
65  typedef typename Graph::NodeId NodeGraphid;
66  typedef typename Graph::EdgeId EdgeGraphid;
67 
68 public:
75  {}
76 
82  AssociationDAGraphImplObserver(std::shared_ptr<DAGraphImpl> subjectDAGraph) :
83  AssociationGraphImplObserver<N, E, DAGraphImpl>(subjectDAGraph)
84  {}
85 
92  AssociationGraphImplObserver<N, E, DAGraphImpl>(dAGraphObserver)
93  {}
94 
95 
101  template<class N2, class E2>
103  AssociationGraphImplObserver<N, E, DAGraphImpl>(dAGraphObserver)
104  {}
105 
111  {
113  return *this;
114  }
115 
120  {}
121 
126  {
128  }
129 
130 
135  bool isValid() const
136  {
137  return this->getGraph()->isValid();
138  }
139 
144  bool isRooted() const
145  {
146  return this->getGraph()->isRooted();
147  }
148 
149 
155  std::vector<std::shared_ptr<N> > getFathers(const std::shared_ptr<N> node) const
156  {
157  return this->getNodesFromGraphid(this->getGraph()->getFathers(this->getNodeGraphid(node)));
158  }
159 
160  std::vector<NodeIndex> getFathers(const NodeIndex node) const
161  {
162  return this->getNodeIndexes(this->getNodesFromGraphid(this->getGraph()->getFathers(this->getNodeGraphid(this->getNode(node)))));
163  }
164 
170  void rootAt(const std::shared_ptr<N> root)
171  {
172  this->getGraph()->rootAt(this->getNodeGraphid(root));
173  }
174 
178  bool hasFather(const std::shared_ptr<N> nodeObject) const
179  {
180  return this->getGraph()->hasFather(this->getNodeGraphid(nodeObject));
181  }
182 
183  bool hasFather(const NodeIndex node) const
184  {
185  return this->getGraph()->hasFather(this->getNodeGraphid(this->getNode(node)));
186  }
187 
192  std::vector<std::shared_ptr<N> > getSons(const std::shared_ptr<N> node) const
193  {
194  return this->getNodesFromGraphid(this->getGraph()->getSons(this->getNodeGraphid(node)));
195  }
196 
197  std::vector<NodeIndex> getSons(const NodeIndex node) const
198  {
199  return this->getNodeIndexes(this->getNodesFromGraphid(this->getGraph()->getSons(this->getNodeGraphid(this->getNode(node)))));
200  }
201 
202 
208  std::shared_ptr<N> getSon(const std::shared_ptr<E> edge) const
209  {
210  return this->getNodeFromGraphid(this->getGraph()->getBottom(this->getEdgeGraphid(edge)));
211  }
212 
213  NodeIndex getSon(const EdgeIndex edgeId) const
214  {
215  return this->getNodeIndex(this->getNodeFromGraphid(this->getGraph()->getBottom(this->getEdgeGraphid(this->getEdge(edgeId)))));
216  }
217 
218 
224  std::shared_ptr<N> getFatherOfEdge(const std::shared_ptr<E> edge) const
225  {
226  return this->getNodeFromGraphid(this->getGraph()->getTop(this->getEdgeGraphid(edge)));
227  }
228 
230  {
231  return this->getNodeIndex(this->getNodeFromGraphid(this->getGraph()->getTop(this->getEdgeGraphid(this->getEdge(edge)))));
232  }
233 
239  size_t getNumberOfFathers(const std::shared_ptr<N> node) const
240  {
241  return this->getGraph()->getNumberOfFathers(this->getNodeGraphid(node));
242  }
243 
249  size_t getNumberOfSons(const std::shared_ptr<N> node) const
250  {
251  return this->getGraph()->getNumberOfSons(this->getNodeGraphid(node));
252  }
253 
260  std::vector<std::shared_ptr<N> > getLeavesUnderNode(std::shared_ptr<N> node) const
261  {
262  return this->getNodesFromGraphid(this->getGraph()->getLeavesUnderNode(this->getNodeGraphid(node)));
263  }
264 
269  std::vector<std::shared_ptr<N> > removeFathers(const std::shared_ptr<N> node)
270  {
271  return this->getNodesFromGraphid(this->getGraph()->removeFathers(this->getNodeGraphid(node)));
272  }
273 
278  void removeFather(const std::shared_ptr<N> node, const std::shared_ptr<N> father)
279  {
280  this->getGraph()->removeFather(this->getNodeGraphid(node), this->getNodeGraphid(father));
281  }
282 
287  std::vector<std::shared_ptr<N> > removeSons(const std::shared_ptr<N> node)
288  {
289  return this->getNodesFromGraphid(this->getGraph()->removeSons(this->getNodeGraphid(node)));
290  }
291 
295  void removeSon(const std::shared_ptr<N> node, const std::shared_ptr<N> son)
296  {
297  this->getGraph()->removeSon(this->getNodeGraphid(node), this->getNodeGraphid(son));
298  }
299 
307  void addFather(const std::shared_ptr<N> nodeObject, const std::shared_ptr<N> fatherNodeObject, const std::shared_ptr<E> edgeObject = 0)
308  {
309  if (edgeObject)
310  try
311  {
312  this->getGraph()->addFather(this->getNodeGraphid(nodeObject), this->getNodeGraphid(fatherNodeObject), this->getEdgeGraphid(edgeObject));
313  }
314  catch (Exception& e)
315  {
316  this->link(fatherNodeObject, nodeObject, edgeObject);
317  }
318  else
319  this->getGraph()->addFather(this->getNodeGraphid(nodeObject), this->getNodeGraphid(fatherNodeObject));
320  }
321 
329  void addSon(const std::shared_ptr<N> nodeObject, const std::shared_ptr<N> sonNodeObject, const std::shared_ptr<E> edgeObject = 0)
330  {
331  if (edgeObject)
332  try
333  {
334  this->getGraph()->addSon(this->getNodeGraphid(nodeObject), this->getNodeGraphid(sonNodeObject), this->getEdgeGraphid(edgeObject));
335  }
336  catch (Exception& e)
337  {
338  this->link(nodeObject, sonNodeObject, edgeObject);
339  }
340  else
341  this->getGraph()->addSon(this->getNodeGraphid(nodeObject), this->getNodeGraphid(sonNodeObject));
342  }
343 
349  /*
350  * @brief builds iterator on the fathers of a Node
351  *
352  */
353  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> fathersIterator(std::shared_ptr<N> node)
354  {
355  return this->incomingNeighborNodesIterator(node);
356  }
357 
358  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> fathersIterator(std::shared_ptr<N> node) const
359  {
360  return this->incomingNeighborNodesIterator(node);
361  }
362 
363  /*
364  * @brief builds iterator on the sons of a Node
365  *
366  */
367  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> sonsIterator(std::shared_ptr<N> node)
368  {
369  return this->outgoingNeighborNodesIterator(node);
370  }
371 
372  std::unique_ptr<typename AssociationDAGraphObserver<N, E>::NodeIterator> sonsIterator(std::shared_ptr<N> node) const
373  {
374  return this->outgoingNeighborNodesIterator(node);
375  }
376 
384  std::vector<std::shared_ptr<N> > getBelowNodes(const std::shared_ptr<N> localRoot)
385  {
386  return this->getNodesFromGraphid(this->getGraph()->getBelowNodes(this->getNodeGraphid(localRoot)));
387  }
388 
389  std::vector<std::shared_ptr<E> > getBelowEdges(const std::shared_ptr<N> localRoot)
390  {
392  }
393 };
394 
395 /********************/
396 
397 template<class N, class E>
399 
400 /********************/
401 }
402 #endif // BPP_GRAPH_ASSOCIATIONDAGRAPHIMPLOBSERVER_H
void rootAt(const std::shared_ptr< N > root)
Sets the root and make the DAG directed from root to leaves.
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > fathersIterator(std::shared_ptr< N > node) const
std::shared_ptr< N > getSon(const std::shared_ptr< E > edge) const
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > sonsIterator(std::shared_ptr< N > node) const
void removeFather(const std::shared_ptr< N > node, const std::shared_ptr< N > father)
AssociationDAGraphImplObserver< N, E, DAGraphImpl > & operator=(bpp::AssociationDAGraphImplObserver< N, E, DAGraphImpl > const &dAGraphObserver)
AssociationGraphObserver< N, E >::EdgeIndex EdgeIndex
AssociationDAGraphImplObserver(bpp::AssociationDAGraphImplObserver< N, E, DAGraphImpl > const &dAGraphObserver)
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > fathersIterator(std::shared_ptr< N > node)
std::vector< std::shared_ptr< N > > getFathers(const std::shared_ptr< N > node) const
void addSon(const std::shared_ptr< N > nodeObject, const std::shared_ptr< N > sonNodeObject, const std::shared_ptr< E > edgeObject=0)
AssociationDAGraphImplObserver(std::shared_ptr< DAGraphImpl > subjectDAGraph)
std::vector< std::shared_ptr< N > > getBelowNodes(const std::shared_ptr< N > localRoot)
Get Below Objects.
std::vector< std::shared_ptr< N > > removeSons(const std::shared_ptr< N > node)
std::vector< std::shared_ptr< N > > removeFathers(const std::shared_ptr< N > node)
std::shared_ptr< N > getFatherOfEdge(const std::shared_ptr< E > edge) const
bool hasFather(const std::shared_ptr< N > nodeObject) const
std::vector< std::shared_ptr< E > > getBelowEdges(const std::shared_ptr< N > localRoot)
void addFather(const std::shared_ptr< N > nodeObject, const std::shared_ptr< N > fatherNodeObject, const std::shared_ptr< E > edgeObject=0)
std::vector< NodeIndex > getSons(const NodeIndex node) const
std::vector< std::shared_ptr< N > > getSons(const std::shared_ptr< N > node) const
size_t getNumberOfSons(const std::shared_ptr< N > node) const
std::vector< NodeIndex > getFathers(const NodeIndex node) const
NodeIndex getFatherOfEdge(const EdgeIndex edge) const
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
std::vector< std::shared_ptr< N > > getLeavesUnderNode(std::shared_ptr< N > node) const
std::unique_ptr< typename AssociationDAGraphObserver< N, E >::NodeIterator > sonsIterator(std::shared_ptr< N > node)
NodeIndex getSon(const EdgeIndex edgeId) const
AssociationDAGraphImplObserver< N, E, DAGraphImpl > * clone() const
size_t getNumberOfFathers(const std::shared_ptr< N > node) const
AssociationDAGraphImplObserver(bpp::AssociationDAGraphImplObserver< N2, E2, DAGraphImpl > const &dAGraphObserver)
void removeSon(const std::shared_ptr< N > node, const std::shared_ptr< N > son)
Defines a DA Graph Associator. It is a template which follows (subscribed to) a Graph.
void link(Nref nodeObjectA, Nref nodeObjectB, Eref edgeObject=00)
std::unique_ptr< typename AssociationGraphObserver< N, E >::NodeIterator > outgoingNeighborNodesIterator(Nref node)
std::unique_ptr< typename AssociationGraphObserver< N, E >::NodeIterator > incomingNeighborNodesIterator(Nref node)
std::vector< Eref > getEdgesFromGraphid(std::vector< EdgeGraphid > edges) const
std::vector< NodeIndex > getNodeIndexes(std::vector< Nref > nodes) const
std::vector< Nref > getNodesFromGraphid(std::vector< NodeGraphid > nodes) const
AssociationGraphImplObserver< N, E, GraphImpl > & operator=(bpp::AssociationGraphImplObserver< N, E, GraphImpl > const &graphObserver)
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
unsigned int NodeId
Definition: Graph.h:66
unsigned int EdgeId
Definition: Graph.h:67