Tulip  4.10.0
Better Visualization Through Research
GraphAbstract.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
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 TULIP_SUPERGRAPHABSTRACT_H
22 #define TULIP_SUPERGRAPHABSTRACT_H
23 
24 #include <set>
25 #include <vector>
26 #include <tulip/Graph.h>
27 #include <tulip/DataSet.h>
28 
29 namespace tlp {
30 
31 #define GRAPH_SEQ std::vector<Graph *>
32 
33 template<class C>struct Iterator;
34 class PropertyManager;
35 class GraphProperty;
36 
37 ///Abstract class for default graph operations.
38 class TLP_SCOPE GraphAbstract:public Graph {
39  friend class PropertyManager;
40 protected:
41  GraphAbstract(Graph *supergraph, unsigned int id);
42 public:
43  virtual ~GraphAbstract();
44  virtual void clear();
45  virtual Graph *addSubGraph(BooleanProperty *selection=NULL,
46  const std::string& name = "unnamed");
47  // used to force the id of the newly created subgraph
48  // when importing (tlp/tlpjson)
49  Graph *addSubGraph(unsigned int id,
50  BooleanProperty *selection=NULL,
51  const std::string& name = "");
52  virtual void delSubGraph(Graph *);
53  virtual void delAllSubGraphs(Graph *);
54  virtual Graph* getSuperGraph()const;
55  virtual Graph* getRoot() const;
56  virtual Iterator<Graph *>* getSubGraphs() const;
57  virtual bool isSubGraph(const Graph* sg) const;
58  virtual bool isDescendantGraph(const Graph* sg) const;
59  virtual Graph* getSubGraph(unsigned int id) const;
60  virtual Graph* getSubGraph(const std::string& name) const;
61  virtual Graph* getDescendantGraph(unsigned int id) const;
62  virtual Graph* getDescendantGraph(const std::string &name) const;
63  virtual Graph *getNthSubGraph(unsigned int n) const;
64  virtual unsigned int numberOfSubGraphs() const;
65  virtual unsigned int numberOfDescendantGraphs() const;
66 
67  //=======================================
68  virtual unsigned int deg(const node) const;
69  virtual unsigned int indeg(const node) const;
70  virtual unsigned int outdeg(const node) const;
71  virtual bool isMetaNode(const node) const;
72  virtual Graph* getNodeMetaInfo(const node) const;
73  virtual void delNodes(Iterator<node>* itN, bool deleteInAllGraphs);
74  virtual node source(const edge) const;
75  virtual void setSource(const edge, const node);
76  virtual node target(const edge) const;
77  virtual void setTarget(const edge, const node);
78  virtual const std::pair<node, node>& ends(const edge) const;
79  virtual void setEnds(const edge, const node, const node);
80  virtual node opposite(const edge, const node)const;
81  virtual void reverse(const edge);
82  virtual bool isMetaEdge(const edge) const;
83  virtual Iterator<edge>* getEdgeMetaInfo(const edge) const;
84  virtual void delEdges(Iterator<edge>* itE, bool deleteInAllGraphs = false);
85  //=======================================
86  virtual node getOneNode() const;
87  virtual node getRandomNode() const;
88  virtual node getInNode(const node,unsigned int ) const;
89  virtual node getOutNode(const node,unsigned int ) const;
90  virtual edge getOneEdge() const;
91  virtual edge getRandomEdge() const;
92  virtual unsigned int numberOfNodes() const;
93  virtual unsigned int numberOfEdges() const;
94  //========================================
95  bool existProperty(const std::string&) const;
96  bool existLocalProperty(const std::string&) const;
97  void delLocalProperty(const std::string&);
98  void addLocalProperty(const std::string &name, PropertyInterface *prop);
99  Iterator<std::string>* getLocalProperties() const;
100  Iterator<std::string>* getInheritedProperties() const;
101  Iterator<std::string>* getProperties() const;
102  Iterator<PropertyInterface*>* getLocalObjectProperties() const;
103  Iterator<PropertyInterface*>* getInheritedObjectProperties() const;
104  Iterator<PropertyInterface*>* getObjectProperties() const;
105  PropertyInterface* getProperty(const std::string &) const;
106 
107  // to get viewMetaGraph property
108  GraphProperty* getMetaGraphProperty();
109 
110  virtual void setName(const std::string &name);
111  virtual std::string getName() const;
112 
113  virtual Iterator<node>* bfs(const node root = node()) const;
114  virtual Iterator<node>* dfs(const node root = node()) const;
115 
116 protected:
117  DataSet& getNonConstAttributes();
118  void setSuperGraph(Graph *);
119  PropertyManager *propertyContainer;
120  const std::set<edge>& getReferencedEdges(const edge) const;
121 
122  virtual bool renameLocalProperty(PropertyInterface *prop,
123  const std::string& newName);
124 
125  // internally used to deal with sub graph deletion
126  virtual void clearSubGraphs();
127  virtual void removeSubGraph(Graph*);
128  virtual void restoreSubGraph(Graph*);
129  virtual void setSubGraphToKeep(Graph*);
130 
131 private:
132  DataSet attributes;
133  Graph *supergraph;
134  Graph* const root;
135  GRAPH_SEQ subgraphs;
136  Graph* subGraphToKeep;
137  // pointer to root viewMetaGraph property
138  GraphProperty* metaGraphProperty;
139  // notification of addition/deletion of inherited properties
140  void notifyBeforeAddInheritedProperty(const std::string& prop);
141  void notifyAddInheritedProperty(const std::string& prop);
142  void notifyBeforeDelInheritedProperty(const std::string& prop);
143  void notifyAfterDelInheritedProperty(const std::string& prop);
144  // notification of property renaming
145  void notifyBeforeRenameLocalProperty(PropertyInterface* prop,
146  const std::string& newName);
147  void notifyAfterRenameLocalProperty(PropertyInterface* prop,
148  const std::string& oldName);
149 };
150 
151 }
152 #endif
153 
154 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39