Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
ObservableGraph.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef GRAPHOBSERVABLE_H
22 #define GRAPHOBSERVABLE_H
23 #include <list>
24 #include <map>
25 #include <algorithm>
26 
27 #include <tulip/Node.h>
28 #include <tulip/Edge.h>
29 #include "tulip/Observable.h"
30 
31 namespace tlp {
32 
33 class Graph;
34 
35 //=========================================================
36 
37 /**
38  * @ingroup Observation
39  * \class GraphObserver
40  * \brief That class receives a message (call back/handler function)
41  * after each modification of a Graph.
42  *
43  * To receive a notification from an ObservableGraph, the GraphObserver must
44  * first be connected to the ObservableGraph.
45  * This is done by calling ObservableGraph::addGraphObserver.
46  *
47  * Depending on which messages you want to receive, you need to override different functions of GraphObserver.
48  *
49  * If manageObservables is set to true, the GraphObserver will automatically
50  * unregister from an ObservableGraph when deleted. (ie, unregistering is done
51  * automatically)
52  *
53  * The Observer pattern is described pp293-304 of the book 'Design Patterns' by Gamma, Helm, Johnson, and Vlissides.
54  *
55  * PrintObserver This is a small example of an observer that displays a message on the standard output each time a
56  * a node is added to a graph.
57  * \code
58  * class PrintObs : public GraphObserver {
59  * void addNode(Graph *g, const node n) {
60  * tlp::debug() << "node " << n.id << " added in " << g << endl << flush;
61  * }
62  * };
63  *
64  * int main() {
65  * Graph *g = tlp::newGraph();
66  * PrintObs obs;
67  * g->addListener(&obs);
68  * g->addNode(); //output node 0 added in 0x
69  * g->addNode(); //output node 0 added in 0x
70  * }
71  * \endcode
72  */
73 class _DEPRECATED TLP_SCOPE GraphObserver {
74 
75 public:
76  virtual ~GraphObserver() {}
77  virtual void addNode(Graph *, const node ) {}
78  virtual void addEdge(Graph *, const edge ) {}
79  virtual void beforeSetEnds(Graph *, const edge) {}
80  virtual void afterSetEnds(Graph *, const edge) {}
81  virtual void delNode(Graph *,const node ) {}
82  virtual void delEdge(Graph *,const edge ) {}
83  virtual void reverseEdge(Graph *,const edge ) {}
84  virtual void destroy(Graph *) {}
85  virtual void addSubGraph(Graph *, Graph *) {}
86  virtual void delSubGraph(Graph *, Graph *) {}
87  virtual void addLocalProperty(Graph*, const std::string&) {}
88  virtual void delLocalProperty(Graph*, const std::string&) {}
89  virtual void beforeSetAttribute(Graph*, const std::string&) {}
90  virtual void afterSetAttribute(Graph*, const std::string&) {}
91  virtual void removeAttribute(Graph*, const std::string&) {}
92 protected:
93  void treatEvent(const Event&);
94 };
95 
96 }
97 
98 
99 #endif
100 
101 ///@endcond