21 #ifndef Tulip_SUPERGRAPHIMPL_H 22 #define Tulip_SUPERGRAPHIMPL_H 28 #include <tulip/GraphAbstract.h> 29 #include <tulip/GraphStorage.h> 30 #include <tulip/IdManager.h> 33 template<
class itType >
36 class GraphUpdatesRecorder;
39 class TLP_SCOPE GraphImpl:
public GraphAbstract {
41 friend class GraphUpdatesRecorder;
42 friend class TLPExport;
49 inline bool isElement(
const node n)
const {
50 return storage.isElement(n);
52 bool isElement(
const edge e)
const {
53 return storage.isElement(e);
55 edge existEdge(
const node source,
const node target,
56 bool directed =
true)
const;
58 void addNodes(
unsigned int nb);
59 void addNodes(
unsigned int nb, std::vector<node>& addedNodes);
60 void addNode(
const node);
62 edge addEdge(
const node ,
const node);
63 void addEdges(
const std::vector<std::pair<node, node> >& edges);
64 void addEdges(
const std::vector<std::pair<node, node> >& edges,
65 std::vector<edge>& addedEdges);
66 void addEdge(
const edge);
68 void delNode(
const tlp::node n,
bool deleteInAllGraphs =
false);
69 void delEdge(
const tlp::edge e,
bool deleteInAllGraphs =
false);
70 inline void setEdgeOrder(
const node n,
const std::vector<edge> &v) {
71 storage.setEdgeOrder(n, v);
73 inline void swapEdgeOrder(
const node n,
const edge e1,
const edge e2) {
74 storage.swapEdgeOrder(n, e1, e2);
77 inline const std::vector<node>& nodes()
const {
78 return storage.nodes();
80 inline unsigned int nodePos(
const node n)
const {
81 return storage.nodePos(n);
87 inline const std::vector<edge>& edges()
const {
88 return storage.edges();
90 inline unsigned int edgePos(
const edge e)
const {
91 return storage.edgePos(e);
97 std::vector<edge> getEdges(
const node source,
const node target,
98 bool directed =
true)
const;
99 bool getEdges(
const node source,
const node target,
bool directed,
100 std::vector<edge>& edges,
const Graph* sg = NULL,
101 bool onlyFirst =
false)
const {
102 return storage.getEdges(source, target, directed, edges, sg, onlyFirst);
104 inline const std::vector<edge>& allEdges(
const node n)
const {
105 return storage.adj(n);
108 inline unsigned int deg(
const node n)
const {
109 assert(isElement(n));
110 return storage.deg(n);
112 inline unsigned int indeg(
const node n)
const {
113 assert(isElement(n));
114 return storage.indeg(n);
116 inline unsigned int outdeg(
const node n)
const {
117 assert(isElement(n));
118 return storage.outdeg(n);
121 inline node source(
const edge e)
const {
122 assert(isElement(e));
123 return storage.source(e);
125 inline node target(
const edge e)
const {
126 assert(isElement(e));
127 return storage.target(e);
129 inline node opposite(
const edge e,
const node n)
const {
130 assert(isElement(e));
131 return storage.opposite(e, n);
133 inline const std::pair<node, node>& ends(
const edge e)
const {
134 return storage.ends(e);
136 inline void setSource(
const edge e,
const node newSrc) {
137 assert(isElement(e));
138 this->setEnds(e, newSrc, node());
140 inline void setTarget(
const edge e,
const node newTgt) {
141 assert(isElement(e));
142 this->setEnds(e, node(), newTgt);
144 void setEnds(
const edge,
const node,
const node);
145 void reverse(
const edge);
147 inline unsigned int numberOfEdges()
const {
148 return storage.numberOfEdges();
150 inline unsigned int numberOfNodes()
const {
151 return storage.numberOfNodes();
153 inline void sortElts() {
158 virtual void push(
bool unpopAllowed =
true,
159 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
160 virtual void pop(
bool unpopAllowed =
true);
161 virtual void popIfNoUpdates();
162 virtual void unpop();
163 virtual bool canPop();
164 virtual bool canUnpop();
165 virtual bool canPopThenUnpop();
168 void treatEvents(
const std::vector<Event> &);
171 unsigned int getSubGraphId(
unsigned int id);
172 void freeSubGraphId(
unsigned int id);
176 virtual void reserveNodes(
unsigned int nbNodes);
177 virtual void reserveEdges(
unsigned int nbEdges);
182 virtual void restoreNode(node);
183 virtual void restoreEdge(edge, node source, node target);
186 virtual void removeNode(
const node);
187 virtual void removeEdge(
const edge);
189 virtual bool canDeleteProperty(Graph* g, PropertyInterface *prop);
192 GraphStorage storage;
194 std::list<GraphUpdatesRecorder*> previousRecorders;
195 std::list<Graph *> observedGraphs;
196 std::list<PropertyInterface*> observedProps;
197 std::list<GraphUpdatesRecorder*> recorders;
199 void observeUpdates(Graph*);
200 void unobserveUpdates();
201 void delPreviousRecorders();
Interface for Tulip iterators. Allows basic iteration operations only.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.