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;
167 bool getEdges(
const node source,
const node target,
bool directed,
168 std::vector<edge>& edges,
bool onlyFirst =
false)
const;
175 Iterator<node>* getInOutNodes(node n)
const;
181 Iterator<node>* getInNodes(node n)
const;
187 Iterator<node>* getOutNodes(node n)
const;
192 unsigned int deg(node n)
const;
197 unsigned int outdeg(node n)
const;
202 unsigned int indeg(node n)
const;
207 unsigned int numberOfEdges()
const;
212 unsigned int numberOfNodes()
const;
217 const std::pair<node, node>& ends(
const edge e)
const;
222 node source(edge e)
const;
227 node target(edge e)
const;
232 node opposite(edge e, node n)
const;
239 void setEnds(
const edge e,
const node newSrc,
const node newTgt);
247 void setSource(
const edge e,
const node n);
255 void setTarget(
const edge e,
const node n);
260 void reverse(
const edge e);
265 void setEdgeOrder(
const node n,
const std::vector<edge> &v );
271 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2);
279 node addNode(node n);
297 void addNodes(
unsigned int nb, std::vector<node>& addedNodes);
305 void restoreNodes(
const std::vector<node>& addedNodes);
313 void removeFromNodes(
const node n);
324 void delNode(node n);
334 edge addEdge(
const node src,
const node tgt,
335 const edge e,
bool updateEndsEdges);
343 edge addEdge(node src, node tgt);
352 void addEdges(
const std::vector<std::pair<node, node> >& edges,
353 std::vector<edge>& addedEdges);
362 void restoreEdges(
const std::vector<edge>& edgesToRestore,
363 const std::vector<std::pair<node, node> >& ends);
373 void delEdge(edge e);
391 typedef SimpleVector<edge> EdgeVector;
393 struct EdgeContainer {
395 unsigned int outDegree;
397 EdgeContainer():outDegree(0) {}
399 typedef std::vector<EdgeContainer> Nodes;
400 typedef std::vector<std::pair< node , node > > Edges;
407 unsigned int nbNodes;
408 unsigned int nbEdges;
418 static void removeFromEdgeContainer(EdgeContainer &c,
const edge e);
427 void removeFromEdges(
const edge e, node end = node());
430 #endif // GRAPHSTORAGE_H