Tulip  5.1.0
Large graphs analysis and drawing
GraphDecorator.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 DOXYGEN_NOTFOR_DEVEL
22 
23 #ifndef Tulip_GraphDecorator_H
24 #define Tulip_GraphDecorator_H
25 
26 #include <tulip/Graph.h>
27 
28 namespace tlp {
29 
30 class TLP_SCOPE GraphDecorator : public Graph {
31 public:
32  GraphDecorator(Graph* s);
33  virtual ~GraphDecorator();
34 
35  virtual void clear();
36  virtual Graph *addSubGraph(BooleanProperty *selection=0,
37  const std::string& name = "unnamed");
38  virtual void delSubGraph(Graph * s);
39  virtual void delAllSubGraphs(Graph *s);
40  virtual Graph* getSuperGraph()const;
41  virtual void setSuperGraph(Graph* s);
42  virtual Graph* getRoot() const;
43  virtual Iterator<Graph *> * getSubGraphs() const;
44  virtual bool isSubGraph(const Graph* sg) const;
45  virtual bool isDescendantGraph(const Graph* sg) const;
46  virtual Graph* getSubGraph(unsigned int id) const;
47  virtual Graph* getSubGraph(const std::string &name) const;
48  virtual Graph* getDescendantGraph(unsigned int id) const;
49  virtual Graph* getDescendantGraph(const std::string &name) const;
50  virtual unsigned int numberOfSubGraphs() const;
51  virtual unsigned int numberOfDescendantGraphs() const;
52 
53  //============================================================
54  virtual node source(const edge e)const;
55  virtual void setSource(const edge, const node);
56  virtual node target(const edge e)const;
57  virtual void setTarget(const edge, const node);
58  virtual node opposite(const edge e, const node n)const;
59  virtual edge existEdge(const node n, const node m, bool directed = true)const;
60  virtual bool hasEdge(const node source, const node target,
61  bool directed = true) const;
62  virtual std::vector<edge> getEdges(const node source, const node target,
63  bool directed = true) const;
64  virtual const std::pair<node, node>& ends(const edge e) const;
65  virtual void setEnds(const edge, const node, const node);
66  virtual void reverse(const edge e);
67  virtual unsigned int deg(const node n)const;
68  virtual unsigned int indeg(const node n)const;
69  virtual unsigned int outdeg(const node n)const;
70  virtual Graph* getNodeMetaInfo(const node n)const;
71 
72  //============================================================
73  virtual node createMetaNode(const std::vector<node> &nodes, bool multiEdges = true, bool delAllEdge = true);
74  virtual void createMetaNodes(Iterator<Graph *> *itS, Graph *quotientGraph, std::vector<node>& metaNodes);
75  virtual node createMetaNode(Graph* subGraph, bool multiEdges = true, bool delAllEdge = true);
76 
77  //============================================================
78  virtual node getOneNode() const;
79  virtual node getRandomNode() const;
80  virtual node getInNode(const node n,unsigned int i)const;
81  virtual node getOutNode(const node n,unsigned int i) const;
82  virtual edge getOneEdge() const;
83  virtual edge getRandomEdge() const;
84 
85  virtual unsigned int numberOfNodes()const;
86  virtual unsigned int numberOfEdges()const;
87 
88  //=========================================================================
89 
90  virtual void reserveNodes(unsigned int nbNodes);
91  virtual void reserveEdges(unsigned int nbEdges);
92 
93  //============================================================
94  virtual bool isElement(const node n) const;
95  virtual bool isMetaNode(const node n) const;
96  virtual bool isElement(const edge e) const;
97  virtual bool isMetaEdge(const edge e) const;
98  virtual node addNode();
99  virtual void addNodes(unsigned int nb);
100  virtual void addNodes(unsigned int nb, std::vector<node>& addedNodes);
101  virtual void addNode(const node);
102  virtual void addNodes(Iterator<node>* nodes);
103  virtual edge addEdge(const node n1, const node n2);
104  virtual void addEdges(const std::vector<std::pair<node, node> >& edges);
105  virtual void addEdges(const std::vector<std::pair<node, node> >& edges,
106  std::vector<edge>& addedEdges);
107  virtual void addEdge(const edge);
108  virtual void addEdges(Iterator<edge>* edges);
109  virtual void delNode(const tlp::node n, bool deleteInAllGraphs = false);
110  virtual void delNodes(Iterator<node>* itN, bool deleteInAllGraphs);
111  virtual void delEdge(const tlp::edge e, bool deleteInAllGraphs = false);
112  virtual void delEdges(Iterator<edge>* itE, bool deleteInAllGraphs = false);
113  virtual void setEdgeOrder(const node n,const std::vector<edge> & s);
114  virtual void swapEdgeOrder(const node n ,const edge e1, const edge e2);
115 
116  virtual const std::vector<node>& nodes() const;
117  virtual unsigned int nodePos(const node) const;
118  virtual Iterator<node>* getNodes() const;
119  virtual Iterator<node>* getInNodes(const node n) const;
120  virtual Iterator<node>* getOutNodes(const node n) const;
121  virtual Iterator<node>* getInOutNodes(const node n) const;
122  virtual Iterator<node>* bfs(const node root = node()) const;
123  virtual Iterator<node>* dfs(const node root = node()) const;
124  virtual const std::vector<edge>& edges() const;
125  virtual unsigned int edgePos(const edge) const;
126  virtual Iterator<edge>* getEdges() const;
127  virtual Iterator<edge>* getOutEdges(const node n) const;
128  virtual Iterator<edge>* getInOutEdges(const node n) const;
129  virtual Iterator<edge>* getInEdges(const node n) const;
130  virtual const std::vector<edge>& allEdges(const node n) const;
131  virtual Iterator<edge>* getEdgeMetaInfo(const edge) const;
132  virtual void sortElts();
133  //============================================================
134  template<typename PropertyType>
135  PropertyType* getProperty(const std::string &name);
136  virtual PropertyInterface* getProperty(const std::string &name) const;
137  virtual bool existProperty(const std::string&name) const;
138  virtual bool existLocalProperty(const std::string&name) const;
139  virtual void delLocalProperty(const std::string&name);
140  virtual void addLocalProperty(const std::string &name, PropertyInterface *prop);
141  virtual Iterator<std::string>* getLocalProperties() const;
142  virtual Iterator<std::string>* getInheritedProperties() const;
143  virtual Iterator<std::string>* getProperties() const;
144  virtual Iterator<PropertyInterface*>* getLocalObjectProperties() const;
145  virtual Iterator<PropertyInterface*>* getInheritedObjectProperties() const;
146  virtual Iterator<PropertyInterface*>* getObjectProperties() const;
147  // updates management
148  virtual void push(bool unpopAllowed = true,
149  std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
150  virtual void pop(bool unpopAllowed = true);
151  virtual void popIfNoUpdates();
152  virtual void unpop();
153  virtual bool canPop();
154  virtual bool canUnpop();
155  virtual bool canPopThenUnpop();
156  //============================================================
157 
158  virtual void setName(const std::string &name);
159  virtual std::string getName() const;
160 
161 protected:
162  virtual DataSet & getNonConstAttributes();
163  Graph* graph_component;
164  // designed to reassign an id to a previously deleted elt
165  // called by GraphUpdatesRecorder
166  virtual void restoreNode(node);
167  virtual void restoreEdge(edge, node source, node target);
168  // designed to only update own structures
169  // used by GraphUpdatesRecorder
170  virtual void removeNode(const node);
171  virtual void removeEdge(const edge);
172  // internally used to deal with sub graph deletion
173  virtual void removeSubGraph(Graph*);
174  virtual void clearSubGraphs();
175  virtual void restoreSubGraph(Graph*);
176  virtual void setSubGraphToKeep(Graph*);
177  // internally used for property renaming
178  virtual bool renameLocalProperty(PropertyInterface* prop,
179  const std::string& newName);
180 };
181 
182 //====================================================================================
183 template<typename PropertyType>
184 PropertyType* GraphDecorator::getProperty(const std::string &name) {
185  if (graph_component->existProperty(name)) {
186  tlp::PropertyInterface* prop = graph_component->getProperty(name);
187  assert (dynamic_cast<PropertyType *>(prop)!=NULL);
188  return dynamic_cast<PropertyType *>(prop);
189  }
190  else {
191  return graph_component->getLocalProperty<PropertyType>(name);
192  }
193 }
194 
195 }
196 
197 #endif
198 
199 #endif //DOXYGEN_NOTFOR_DEVEL
200 ///@endcond
PropertyInterface describes the interface of a graph property.
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39
The edge struct represents an edge in a Graph object.
Definition: Edge.h:39
The node struct represents a node in a Graph object.
Definition: Node.h:39