Check StaticGraphSkeleton, as well.
6 ///\brief Declaration of GraphConcept.
8 #include <hugo/invalid.h>
12 /// @defgroup empty_graph The GraphConcept class
15 /// An empty graph class.
17 /// This class provides all the common features of a graph structure,
18 /// however completely without implementations and real data structures
19 /// behind the interface.
20 /// All graph algorithms should compile with this class, but it will not
21 /// run properly, of course.
23 /// It can be used for checking the interface compatibility,
24 /// or it can serve as a skeleton of a new graph structure.
26 /// Also, you will find here the full documentation of a certain graph
27 /// feature, the documentation of a real graph imlementation
28 /// like @ref ListGraph or
29 /// @ref SmartGraph will just refer to this structure.
33 /// Defalult constructor.
36 /// \brief Copy consructor.
38 /// \todo It is not clear, what we expect from a copy constructor.
39 /// E.g. How to assign the nodes/edges to each other? What about maps?
40 GraphConcept(const GraphConcept&) { }
42 /// \brief The base type of the node iterators.
44 /// This is the base type of each node iterators,
45 /// thus each kind of node iterator will convert to this.
46 /// Sometimes it is said to be a trivial iterator.
49 /// @warning The default constructor sets the iterator
50 /// to an undefined value.
53 // /// Copy constructor.
54 // Node(const Node&) { }
56 /// \brief Invalid constructor \& conversion.
58 /// This constructor initializes the iterator to be invalid.
59 /// \sa Invalid for more details.
60 Node(const Invalid&) { }
62 /// Two iterators are equal if and only if they point to the
63 /// same object or both are invalid.
64 bool operator==(Node n) const { return true; }
66 /// \sa \ref operator==(Node n)
68 bool operator!=(Node n) const { return true; }
70 bool operator<(Node n) const { return true; }
73 /// The base type of the edge iterators.
76 /// @warning The default constructor sets the iterator
77 /// to an undefined value.
80 // /// Copy constructor.
81 // Edge(const Edge&) { }
83 /// Initialize the iterator to be invalid
84 Edge(const Invalid&) { }
85 /// Two iterators are equal if and only if they point to the
86 /// same object or both are invalid.
87 bool operator==(Edge n) const { return true; }
88 bool operator!=(Edge n) const { return true; }
89 bool operator<(Edge n) const { return true; }
92 // class SymEdgeIt : public Edge {};
95 // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
97 // Node getNext(Node) const {}
98 // InEdgeIt getNext(InEdgeIt) const {}
99 // OutEdgeIt getNext(OutEdgeIt) const {}
100 // //SymEdgeIt getNext(SymEdgeIt) const {}
101 // EdgeIt getNext(EdgeIt) const {}
103 //SymEdgeIt &next(SymEdgeIt &) const {}
106 /// Gives back the head node of an edge.
107 Node head(const Edge&) const { return INVALID; }
108 /// Gives back the tail node of an edge.
109 Node tail(const Edge&) const { return INVALID; }
111 // Node aNode(SymEdgeIt) const {}
112 // Node bNode(SymEdgeIt) const {}
114 /// \brief Checks if a node iterator is valid
116 /// \todo Maybe, it would be better if iterator converted to
117 /// bool directly, as Jacint prefers.
118 bool valid(const Node&) const { return true; }
119 /// \brief Checks if an edge iterator is valid
121 /// \todo Maybe, it would be better if iterator converted to
122 /// bool directly, as Jacint prefers.
123 bool valid(const Edge&) const { return true; }
125 /// \brief Gives back the \e id of a node.
127 /// \warning Not all graph structures provide this feature.
129 int id(const Node&) const { return 0; }
130 /// \brief Gives back the \e id of an edge.
132 /// \warning Not all graph structures provide this feature.
134 int id(const Edge&) const { return 0; }
136 //void setInvalid(Node &) const {};
137 //void setInvalid(Edge &) const {};
139 /// \brief Add a new node to the graph.
141 /// \return the new node.
142 Node addNode() { return INVALID; }
143 /// \brief Add a new edge to the graph.
145 /// Add a new edge to the graph with tail node \c tail
146 /// and head node \c head.
147 /// \return the new edge.
148 Edge addEdge(const Node& tail, const Node& head) { return INVALID; }
150 /// \brief Resets the graph.
152 /// This function deletes all edges and nodes of the graph.
153 /// It also frees the memory allocated to store them.
154 /// \todo What happens with the maps?
157 /// Read/write/reference map of the nodes to type \c T.
159 /// Read/write/reference map of the nodes to type \c T.
160 /// \sa MemoryMapConcept
161 /// \todo We may need copy constructor
162 /// \todo We may need conversion from other nodetype
163 /// \todo We may need operator=
164 /// \warning Making maps that can handle bool type (NodeMap<bool>)
165 /// needs extra attention!
167 template<class T> class NodeMap
171 typedef Node KeyType;
173 NodeMap(const GraphConcept& g) { }
174 NodeMap(const GraphConcept& g, T t) { }
176 template<typename TT> NodeMap(const NodeMap<TT>& m) { }
178 /// Sets the value of a node.
180 /// Sets the value associated with node \c i to the value \c t.
182 void set(Node i, T t) {}
183 /// Gets the value of a node.
184 T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary
185 T &operator[](Node i) {return *(T*)0;}
186 const T &operator[](Node i) const {return *(T*)0;}
188 /// Updates the map if the graph has been changed
190 /// \todo Do we need this?
193 //void update(T a) { } //FIXME: Is it necessary
196 ///Read/write/reference map of the edges to type \c T.
198 /// Read/write/reference map of the edges to type \c T.
199 /// It behaves exactly in the same way as \ref NodeMap.
201 /// \sa MemoryMapConcept
202 /// \todo We may need copy constructor
203 /// \todo We may need conversion from other edgetype
204 /// \todo We may need operator=
205 template<class T> class EdgeMap
209 typedef Edge KeyType;
211 EdgeMap(const GraphConcept& g) {}
212 EdgeMap(const GraphConcept& g, T t) {}
214 void set(Edge i, T t) {}
215 T get(Edge i) const {return *(T*)0;}
216 T &operator[](Edge i) {return *(T*)0;}
219 //void update(T a) { } //FIXME: Is it necessary
224 /// \brief Node-iterable graph concept.
226 /// A graph class which provides functions to
227 /// iterate on its nodes.
228 class NodeIterableGraphConcept : virtual public GraphConcept
232 /// \brief This iterator goes trough the nodes of the graph.
234 /// This iterator goes trough the \e nodes of the graph.
235 /// Its usage is quite simple, for example you can count the number
236 /// of nodes in graph \c g of type \c Graph as follows.
239 /// for(Graph::NodeIt n(g); g.valid(n); g.next(n)) ++count;
241 class NodeIt : public Node {
243 /// @warning The default constructor sets the iterator.
244 /// to an undefined value.
246 // /// Copy constructor
247 //NodeIt(const NodeIt& n) { }
248 /// Initialize the iterator to be invalid.
249 NodeIt(const Invalid&) { }
250 /// \brief This constructor sets the iterator to first node.
252 /// This constructor set the iterator to the first
253 /// node of the graph \c g.
255 ///@param g the graph
256 NodeIt(const GraphConcept& g) { }
260 NodeIt &first(NodeIt &i) const { return i; }
262 /// Go to the next node.
263 NodeIt &next(NodeIt &i) const { return i; }
267 /// \brief Edge-iterable graph concept.
269 /// A graph class which provides functions to
270 /// iterate on its edges.
271 class EdgeIterableGraphConcept : virtual public GraphConcept
275 /// \brief This iterator goes trough the edges of the graph.
277 /// This iterator goes trough the \e edges of the graph.
278 /// Its usage is quite simple, for example you can count the number
279 /// of edges in graph \c g of type \c Graph as follows.
282 /// for(Graph::EdgeIt e(g); g.valid(e); g.next(e)) ++count;
284 class EdgeIt : public Edge {
286 /// @warning The default constructor sets the iterator.
287 /// to an undefined value.
289 // /// Copy constructor
290 // EdgeIt(const EdgeIt&) { }
291 /// Initialize the iterator to be invalid.
292 EdgeIt(const Invalid&) { }
293 /// \brief This constructor sets the iterator to first edge.
295 /// This constructor set the iterator to the first
296 /// edge of the graph \c g.
298 ///@param g the graph
299 EdgeIt(const GraphConcept& g) { }
303 EdgeIt &first(EdgeIt &i) const { return i; }
305 /// Go to the next edge.
306 EdgeIt &next(EdgeIt &i) const { return i; }
310 /// \brief Out-edge-iterable graph concept.
312 /// A graph class which provides functions to
313 /// iterate on out-edges of any node.
314 class OutEdgeIterableGraphConcept : virtual public GraphConcept
318 /// \brief This iterator goes trough the outgoing edges of a node.
320 /// This iterator goes trough the \e outgoing edges of a certain node
322 /// Its usage is quite simple, for example you can count the number
323 /// of outgoing edges of a node \c n
324 /// in graph \c g of type \c Graph as follows.
327 /// for(Graph::OutEdgeIt e(g, n); g.valid(e); g.next(e)) ++count;
329 class OutEdgeIt : public Edge {
331 /// @warning The default constructor sets the iterator.
332 /// to an undefined value.
334 /// Initialize the iterator to be invalid.
335 OutEdgeIt(const Invalid&) { }
336 /// \brief This constructor sets the iterator to first outgoing edge.
338 /// This constructor set the iterator to the first outgoing edge of
341 ///@param g the graph
342 OutEdgeIt(const GraphConcept& g, const Node& n) { }
345 /// The first outgoing edge.
346 OutEdgeIt &first(OutEdgeIt &i, const Node& n) const { return i; }
348 /// Go to the next outgoing edge.
349 OutEdgeIt &next(OutEdgeIt &i) const { return i; }
351 Node aNode(const OutEdgeIt&) const { return Node(); }
352 Node bNode(const OutEdgeIt&) const { return Node(); }
356 /// \brief In-edge-iterable graph concept.
358 /// A Graph class which provides a function to
359 /// iterate on in-edges of any node.
360 class InEdgeIterableGraphConcept : virtual public GraphConcept
364 /// \brief This iterator goes trough the incoming edges of a node.
366 /// This iterator goes trough the \e incoming edges of a certain node
368 /// Its usage is quite simple, for example you can count the number
369 /// of incoming edges of a node \c n
370 /// in graph \c g of type \c Graph as follows.
373 /// for(Graph::InEdgeIt e(g, n); g.valid(e); g.next(e)) ++count;
375 class InEdgeIt : public Edge {
377 /// @warning The default constructor sets the iterator
378 /// to an undefined value.
380 /// Initialize the iterator to be invalid
381 InEdgeIt(const Invalid&) { }
382 /// \brief This constructor sets the iterator to first incomig edge.
384 /// This constructor set the iterator to the first incomig edge of
387 ///@param g the graph
388 InEdgeIt(const GraphConcept& g, const Node& n) { }
391 /// The first incoming edge.
392 InEdgeIt &first(InEdgeIt &i, const Node& n) const { return i; }
394 /// Go to the next incoming edge.
395 InEdgeIt &next(InEdgeIt &i) const { return i; }
397 Node aNode(const InEdgeIt&) const { return Node(); }
398 Node bNode(const InEdgeIt&) const { return Node(); }
402 /// \brief Node-eraseable graph concept.
404 /// A graph class which provides a function to
405 /// delete any of its nodes.
406 class NodeEraseableGraphConcept : virtual public GraphConcept
410 void erase(const Node& n) { }
414 /// \brief Edge-eraseable graph concept.
416 /// A graph class which provides a function to delete any
418 class EdgeEraseableGraphConcept : virtual public GraphConcept
422 void erase(const Edge& n) { }
426 /// \brief An empty graph class which provides a function to
427 /// get the number of its nodes.
429 /// This graph class provides a function for getting the number of its
431 /// Clearly, for physical graph structures it can be expected to have such a
432 /// function. For wrappers or graphs which are given in an implicit way,
433 /// the implementation can be circumstantial, that is why this composes a
434 /// separate concept.
435 class NodeCountingGraphConcept : virtual public GraphConcept
438 /// Returns the number of nodes.
439 int nodeNum() const { return 0; }
443 /// \brief An empty graph class which provides a function to
444 /// get the number of its edges.
446 /// This graph class provides a function for getting the number of its
448 /// Clearly, for physical graph structures it can be expected to have such a
449 /// function. For wrappers or graphs which are given in an implicit way,
450 /// the implementation can be circumstantial, that is why this composes a
451 /// separate concept.
452 class EdgeCountingGraphConcept : virtual public GraphConcept
455 /// Returns the number of edges.
456 int edgeNum() const { return 0; }
459 class FullFeatureGraphConcept : virtual public NodeIterableGraphConcept,
460 virtual public EdgeIterableGraphConcept,
461 virtual public OutEdgeIterableGraphConcept,
462 virtual public InEdgeIterableGraphConcept,
463 virtual public NodeCountingGraphConcept {
465 FullFeatureGraphConcept() { }
466 using EdgeIterableGraphConcept::next;
467 using NodeIterableGraphConcept::next;
468 using OutEdgeIterableGraphConcept::next;
469 using InEdgeIterableGraphConcept::next;
478 // class EmptyBipGraph : public Graph Concept
483 // ANode &next(ANode &) {}
484 // BNode &next(BNode &) {}
486 // ANode &getFirst(ANode &) const {}
487 // BNode &getFirst(BNode &) const {}
489 // enum NodeClass { A = 0, B = 1 };
490 // NodeClass getClass(Node n) {}
494 #endif // HUGO_GRAPH_H