Tulip  5.1.0
Large graphs analysis and drawing
GraphAbstract.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 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  DataSet attributes;
41  Graph* supergraph;
42  Graph* const root;
43  GRAPH_SEQ subgraphs;
44  Graph* subGraphToKeep;
45  // pointer to root viewMetaGraph property
46  GraphProperty* metaGraphProperty;
47 protected:
48  GraphAbstract(Graph *supergraph, unsigned int id = 0);
49 public:
50  virtual ~GraphAbstract();
51  virtual void clear();
52  // use to enforce subgraph id
53  Graph* addSubGraph(unsigned int id, BooleanProperty *selection=NULL,
54  const std::string& name = "unnamed");
55  virtual Graph *addSubGraph(BooleanProperty *selection=NULL,
56  const std::string& name = "unnamed") {
57  return addSubGraph(0, selection, name);
58  }
59  virtual void delSubGraph(Graph *);
60  virtual void delAllSubGraphs(Graph *);
61  inline Graph* getSuperGraph() const {
62  return supergraph;
63  }
64  inline Graph* getRoot() const {
65  return root;
66  }
67  virtual Iterator<Graph *>* getSubGraphs() const;
68  virtual bool isSubGraph(const Graph* sg) const;
69  virtual bool isDescendantGraph(const Graph* sg) const;
70  virtual Graph* getSubGraph(unsigned int id) const;
71  virtual Graph* getSubGraph(const std::string& name) const;
72  virtual Graph* getDescendantGraph(unsigned int id) const;
73  virtual Graph* getDescendantGraph(const std::string &name) const;
74  virtual Graph *getNthSubGraph(unsigned int n) const;
75  inline unsigned int numberOfSubGraphs() const {
76  return subgraphs.size();
77  }
78  virtual unsigned int numberOfDescendantGraphs() const;
79 
80  //=======================================
81  virtual bool isMetaNode(const node) const;
82  virtual Graph* getNodeMetaInfo(const node) const;
83  virtual void delNodes(Iterator<node>* itN, bool deleteInAllGraphs);
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  //========================================
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  return attributes;
119  }
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  // notification of addition/deletion of inherited properties
135  void notifyBeforeAddInheritedProperty(const std::string& prop);
136  void notifyAddInheritedProperty(const std::string& prop);
137  void notifyBeforeDelInheritedProperty(const std::string& prop);
138  void notifyAfterDelInheritedProperty(const std::string& prop);
139  // notification of property renaming
140  void notifyBeforeRenameLocalProperty(PropertyInterface* prop,
141  const std::string& newName);
142  void notifyAfterRenameLocalProperty(PropertyInterface* prop,
143  const std::string& oldName);
144 };
145 
146 }
147 #endif
148 
149 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39