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