22 #ifndef GRAPHSTORAGE_H
23 #define GRAPHSTORAGE_H
27 #include <tulip/Node.h>
28 #include <tulip/Edge.h>
29 #include <tulip/IdManager.h>
30 #include <tulip/SimpleVector.h>
31 #include <tulip/MutableContainer.h>
41 class GraphStorageIdsMemento {
43 virtual ~GraphStorageIdsMemento() {}
63 bool isElement(
const node n)
const;
68 bool isElement(
const edge e)
const;
75 void reserveNodes(
size_t nb);
82 void reserveEdges(
size_t nb);
89 void reserveAdj(node n,
size_t nb);
96 void reserveAdj(
size_t nb);
101 void restoreAdj(node n,
const std::vector<edge>& edges);
106 node getOneNode()
const;
113 Iterator<node>* getNodes()
const;
120 const GraphStorageIdsMemento* getIdsMemento();
125 void restoreIdsMemento(
const GraphStorageIdsMemento*);
131 Iterator<edge>* getEdges()
const;
138 Iterator<edge>* getInOutEdges(node n)
const;
143 void getInOutEdges(node n, std::vector<edge>& edges,
144 bool loopsOnlyOnce =
false)
const;
150 Iterator<edge>* getOutEdges(node n)
const;
156 Iterator<edge>* getInEdges(node n)
const;
162 Iterator<node>* getInOutNodes(node n)
const;
168 Iterator<node>* getInNodes(node n)
const;
174 Iterator<node>* getOutNodes(node n)
const;
179 unsigned int deg(node n)
const;
184 unsigned int outdeg(node n)
const;
189 unsigned int indeg(node n)
const;
194 unsigned int numberOfEdges()
const;
199 unsigned int numberOfNodes()
const;
204 const std::pair<node, node>& ends(
const edge e)
const;
209 node source(edge e)
const;
214 node target(edge e)
const;
219 node opposite(edge e, node n)
const;
226 void setEnds(
const edge e,
const node newSrc,
const node newTgt);
234 void setSource(
const edge e,
const node n);
242 void setTarget(
const edge e,
const node n);
247 void reverse(
const edge e);
252 void setEdgeOrder(
const node n,
const std::vector<edge> &v );
258 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2);
266 node addNode(node n);
284 void addNodes(
unsigned int nb, std::vector<node>& addedNodes);
292 void restoreNodes(
const std::vector<node>& addedNodes);
300 void removeFromNodes(
const node n);
311 void delNode(node n);
321 edge addEdge(
const node src,
const node tgt,
322 const edge e,
bool updateEndsEdges);
330 edge addEdge(node src, node tgt);
339 void addEdges(
const std::vector<std::pair<node, node> >& edges,
340 std::vector<edge>& addedEdges);
349 void restoreEdges(
const std::vector<edge>& edgesToRestore,
350 const std::vector<std::pair<node, node> >& ends);
360 void delEdge(edge e);
378 typedef SimpleVector<edge> EdgeVector;
380 struct EdgeContainer {
382 unsigned int outDegree;
384 EdgeContainer():outDegree(0) {}
386 typedef std::vector<EdgeContainer> Nodes;
387 typedef std::vector<std::pair< node , node > > Edges;
394 unsigned int nbNodes;
395 unsigned int nbEdges;
405 static void removeFromEdgeContainer(EdgeContainer &c,
const edge e);
414 void removeFromEdges(
const edge e, node end = node());
417 #endif // GRAPHSTORAGE_H