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