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(
const size_t nb);
82 void reserveEdges(
const size_t nb);
89 void reserveAdj(
const node n,
const size_t nb);
96 void reserveAdj(
const size_t nb);
101 void restoreAdj(
const 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(
const node n)
const;
143 void getInOutEdges(
const node n, std::vector<edge>& edges,
144 bool loopsOnlyOnce =
false)
const;
150 Iterator<edge>* getOutEdges(
const node n)
const;
156 Iterator<edge>* getInEdges(
const 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(
const node n)
const;
181 Iterator<node>* getInNodes(
const node n)
const;
187 Iterator<node>* getOutNodes(
const node n)
const;
192 unsigned int deg(
const node n)
const;
197 unsigned int outdeg(
const node n)
const;
202 unsigned int indeg(
const 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(
const edge e)
const;
227 node target(
const edge e)
const;
232 node opposite(
const edge e,
const 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(
const node n);
297 void addNodes(
unsigned int nb, std::vector<node>* addedNodes = NULL);
305 void restoreNodes(
const std::vector<node>& addedNodes);
313 void removeFromNodes(
const node n);
324 void delNode(
const node n);
334 edge addEdge(
const node src,
const node tgt,
335 const edge e,
bool updateEndsEdges);
343 edge addEdge(
const node src,
const node tgt);
352 void addEdges(
const std::vector<std::pair<node, node> >& edges,
353 std::vector<edge>* addedEdges = NULL);
362 void restoreEdges(
const std::vector<edge>& edgesToRestore,
363 const std::vector<std::pair<node, node> >& ends);
373 void delEdge(
const 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