21 #ifndef Tulip_SUPERGRAPHVIEW_H 22 #define Tulip_SUPERGRAPHVIEW_H 25 #include <tulip/GraphAbstract.h> 26 #include <tulip/GraphImpl.h> 27 #include <tulip/MutableContainer.h> 28 #include <tulip/IdManager.h> 32 struct SGraphNodeData {
33 unsigned int outDegree;
34 unsigned int inDegree;
35 SGraphNodeData() :outDegree(0), inDegree(0) {}
36 inline void outDegreeAdd(
int i) {
39 inline void inDegreeAdd(
int i) {
44 typedef SGraphNodeData* SGraphNodeDataPtr;
45 DECL_STORED_PTR(SGraphNodeDataPtr);
51 class GraphView:
public GraphAbstract {
53 inline GraphImpl* getRootImpl()
const {
54 return (GraphImpl *) getRoot();
57 friend class GraphImpl;
59 GraphView(Graph *supergraph, BooleanProperty *filter,
unsigned int id);
63 void addNodes(
unsigned int nb);
64 void addNodes(
unsigned int nb, std::vector<node>& addedNodes);
65 void addNode(
const node);
67 edge addEdge(
const node n1,
const node n2);
68 void addEdges(
const std::vector<std::pair<node, node> >& edges,
69 std::vector<edge>& addedEdges);
70 void addEdges(
const std::vector<std::pair<node, node> >& edges);
71 void addEdge(
const edge);
73 void delNode(
const tlp::node n,
bool deleteInAllGraphs =
false);
74 void delEdge(
const tlp::edge e,
bool deleteInAllGraphs =
false);
75 void setEdgeOrder(
const node n,
const std::vector<edge> &v) {
76 getRootImpl()->setEdgeOrder(n,v);
78 void swapEdgeOrder(
const node n,
const edge e1,
const edge e2) {
79 getRootImpl()->swapEdgeOrder(n, e1, e2);
82 inline bool isElement(
const node n)
const {
83 return _nodeData.get(n.id) != NULL;
85 inline bool isElement(
const edge e)
const {
86 return _edges.isElement(e);
88 edge existEdge(
const node source,
const node target,
90 inline unsigned int numberOfNodes()
const {
93 inline unsigned int numberOfEdges()
const {
97 inline unsigned int deg(
const node n)
const {
99 SGraphNodeData* nData = _nodeData.get(n.id);
100 return nData->inDegree + nData->outDegree;
102 inline unsigned int indeg(
const node n)
const {
103 assert(isElement(n));
104 return _nodeData.get(n.id)->inDegree;
106 inline unsigned int outdeg(
const node n)
const {
107 assert(isElement(n));
108 return _nodeData.get(n.id)->outDegree;
111 inline node source(
const edge e)
const {
112 return getRootImpl()->source(e);
114 inline void setSource(
const edge e,
const node newSrc) {
115 assert(isElement(e));
116 getRootImpl()->setEnds(e, newSrc, node());
118 inline node target(
const edge e)
const {
119 return getRootImpl()->target(e);
121 inline void setTarget(
const edge e,
const node newTgt) {
122 assert(isElement(e));
123 getRootImpl()->setEnds(e, node(), newTgt);
125 inline const std::pair<node, node>& ends(
const edge e)
const {
126 return getRootImpl()->ends(e);
128 inline void setEnds(
const edge e,
const node newSrc,
const node newTgt) {
129 assert(isElement(e));
130 getRootImpl()->setEnds(e, newSrc, newTgt);
132 inline node opposite(
const edge e,
const node n)
const {
133 return getRootImpl()->opposite(e, n);
135 inline void reverse(
const edge e) {
136 assert(isElement(e));
137 getRootImpl()->reverse(e);
140 inline const std::vector<node>& nodes()
const {
143 inline unsigned int nodePos(
const node n)
const {
144 return _nodes.getPos(n);
150 inline const std::vector<edge>& edges()
const {
153 inline unsigned int edgePos(
const edge e)
const {
154 return _edges.getPos(e);
160 std::vector<edge> getEdges(
const node source,
const node target,
161 bool directed =
true)
const;
162 inline const std::vector<edge>& allEdges(
const node n)
const {
163 return getRootImpl()->allEdges(n);
165 inline void sortElts() {
171 virtual void reserveNodes(
unsigned int nbNodes);
172 virtual void reserveEdges(
unsigned int nbEdges);
175 virtual void push(
bool unpopAllowed =
true,
176 std::vector<PropertyInterface*>* propertiesToPreserveOnPop= NULL);
177 virtual void pop(
bool unpopAllowed =
true);
178 virtual void popIfNoUpdates();
179 virtual void unpop();
180 virtual bool canPop();
181 virtual bool canUnpop();
182 virtual bool canPopThenUnpop();
187 virtual void restoreNode(node);
188 virtual void restoreEdge(edge, node source, node target);
191 virtual void removeNode(
const node);
192 virtual void removeEdge(
const edge);
193 void removeNode(
const node n,
const std::vector<edge>& edges);
194 void removeEdges(
const std::vector<edge>& edges);
197 MutableContainer<SGraphNodeDataPtr> _nodeData;
198 SGraphIdContainer<node> _nodes;
199 SGraphIdContainer<edge> _edges;
200 void outDegreeAdd(node n,
int i);
201 void inDegreeAdd(node n,
int i);
202 edge addEdgeInternal(edge);
203 void reverseInternal(
const edge,
const node src,
const node tgt);
204 void setEndsInternal(
const edge, node src, node tgt,
205 const node newSrc,
const node newTgt);
206 void addNodesInternal(
unsigned int nbAdded,
const std::vector<node>* nodes);
207 void addEdgesInternal(
unsigned int nbAdded,
const std::vector<edge>* edges,
208 const std::vector<std::pair<node, node> >& ends);
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.