2 #ifndef HUGO_SKELETON_GRAPH_H
3 #define HUGO_SKELETON_GRAPH_H
7 ///\brief Declaration of Graph.
9 #include <hugo/invalid.h>
10 #include <hugo/skeletons/maps.h>
15 /// \addtogroup skeletons
18 /// An empty static graph class.
20 /// This class provides all the common features of a graph structure,
21 /// however completely without implementations and real data structures
22 /// behind the interface.
23 /// All graph algorithms should compile with this class, but it will not
24 /// run properly, of course.
26 /// It can be used for checking the interface compatibility,
27 /// or it can serve as a skeleton of a new graph structure.
29 /// Also, you will find here the full documentation of a certain graph
30 /// feature, the documentation of a real graph imlementation
31 /// like @ref ListGraph or
32 /// @ref SmartGraph will just refer to this structure.
36 /// Defalult constructor.
38 /// Defalult constructor.
43 // ///\todo It is not clear, what we expect from a copy constructor.
44 // ///E.g. How to assign the nodes/edges to each other? What about maps?
45 // StaticGraph(const StaticGraph& g) { }
47 /// The base type of node iterators,
48 /// or in other words, the trivial node iterator.
50 /// This is the base type of each node iterator,
51 /// thus each kind of node iterator converts to this.
52 /// More precisely each kind of node iterator should be inherited
53 /// from the trivial node iterator.
56 /// Default constructor
58 /// @warning The default constructor sets the iterator
59 /// to an undefined value.
67 /// Invalid constructor \& conversion.
69 /// This constructor initializes the iterator to be invalid.
70 /// \sa Invalid for more details.
74 /// Two iterators are equal if and only if they point to the
75 /// same object or both are invalid.
76 bool operator==(Node) const { return true; }
78 /// Inequality operator
80 /// \sa \ref operator==(Node n)
82 bool operator!=(Node) const { return true; }
84 ///Comparison operator.
86 ///This is a strict ordering between the nodes.
88 ///This ordering can be different from the order in which NodeIt
89 ///goes through the nodes.
90 ///\todo Possibly we don't need it.
91 bool operator<(Node) const { return true; }
94 /// This iterator goes through each node.
96 /// This iterator goes through each node.
97 /// Its usage is quite simple, for example you can count the number
98 /// of nodes in graph \c g of type \c Graph like this:
101 /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
103 class NodeIt : public Node {
105 /// Default constructor
107 /// @warning The default constructor sets the iterator
108 /// to an undefined value.
110 /// Copy constructor.
112 /// Copy constructor.
114 NodeIt(const NodeIt&) { }
115 /// Invalid constructor \& conversion.
117 /// Initialize the iterator to be invalid.
118 /// \sa Invalid for more details.
120 /// Sets the iterator to the first node.
122 /// Sets the iterator to the first node of \c g.
124 NodeIt(const StaticGraph& g) { }
125 /// Node -> NodeIt conversion.
127 /// Sets the iterator to the node of \c g pointed by the trivial
129 /// This feature necessitates that each time we
130 /// iterate the edge-set, the iteration order is the same.
131 NodeIt(const StaticGraph& g, const Node& n) { }
134 /// Assign the iterator to the next node.
136 NodeIt& operator++() { return *this; }
140 /// The base type of the edge iterators.
142 /// The base type of the edge iterators.
146 /// Default constructor
148 /// @warning The default constructor sets the iterator
149 /// to an undefined value.
151 /// Copy constructor.
153 /// Copy constructor.
155 Edge(const Edge&) { }
156 /// Initialize the iterator to be invalid.
158 /// Initialize the iterator to be invalid.
161 /// Equality operator
163 /// Two iterators are equal if and only if they point to the
164 /// same object or both are invalid.
165 bool operator==(Edge) const { return true; }
166 /// Inequality operator
168 /// \sa \ref operator==(Node n)
170 bool operator!=(Edge) const { return true; }
171 ///Comparison operator.
173 ///This is a strict ordering between the nodes.
175 ///This ordering can be different from the order in which NodeIt
176 ///goes through the nodes.
177 ///\todo Possibly we don't need it.
178 bool operator<(Edge) const { return true; }
181 /// This iterator goes trough the outgoing edges of a node.
183 /// This iterator goes trough the \e outgoing edges of a certain node
185 /// Its usage is quite simple, for example you can count the number
186 /// of outgoing edges of a node \c n
187 /// in graph \c g of type \c Graph as follows.
190 /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
193 class OutEdgeIt : public Edge {
195 /// Default constructor
197 /// @warning The default constructor sets the iterator
198 /// to an undefined value.
200 /// Copy constructor.
202 /// Copy constructor.
204 OutEdgeIt(const OutEdgeIt&) { }
205 /// Initialize the iterator to be invalid.
207 /// Initialize the iterator to be invalid.
209 OutEdgeIt(Invalid) { }
210 /// This constructor sets the iterator to first outgoing edge.
212 /// This constructor set the iterator to the first outgoing edge of
215 ///@param g the graph
216 OutEdgeIt(const StaticGraph& g, const Node& n) { }
217 /// Edge -> OutEdgeIt conversion
219 /// Sets the iterator to the value of the trivial iterator \c e.
220 /// This feature necessitates that each time we
221 /// iterate the edge-set, the iteration order is the same.
222 OutEdgeIt(const StaticGraph& g, const Edge& e) { }
223 ///Next outgoing edge
225 /// Assign the iterator to the next
226 /// outgoing edge of the corresponding node.
227 OutEdgeIt& operator++() { return *this; }
230 /// This iterator goes trough the incoming edges of a node.
232 /// This iterator goes trough the \e incoming edges of a certain node
234 /// Its usage is quite simple, for example you can count the number
235 /// of outgoing edges of a node \c n
236 /// in graph \c g of type \c Graph as follows.
239 /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
242 class InEdgeIt : public Edge {
244 /// Default constructor
246 /// @warning The default constructor sets the iterator
247 /// to an undefined value.
249 /// Copy constructor.
251 /// Copy constructor.
253 InEdgeIt(const InEdgeIt&) { }
254 /// Initialize the iterator to be invalid.
256 /// Initialize the iterator to be invalid.
258 InEdgeIt(Invalid) { }
259 /// This constructor sets the iterator to first incoming edge.
261 /// This constructor set the iterator to the first incoming edge of
264 ///@param g the graph
265 InEdgeIt(const StaticGraph& g, const Node& n) { }
266 /// Edge -> InEdgeIt conversion
268 /// Sets the iterator to the value of the trivial iterator \c e.
269 /// This feature necessitates that each time we
270 /// iterate the edge-set, the iteration order is the same.
271 InEdgeIt(const StaticGraph& g, const Edge& n) { }
272 /// Next incoming edge
274 /// Assign the iterator to the next inedge of the corresponding node.
276 InEdgeIt& operator++() { return *this; }
278 /// This iterator goes through each edge.
280 /// This iterator goes through each edge of a graph.
281 /// Its usage is quite simple, for example you can count the number
282 /// of edges in a graph \c g of type \c Graph as follows:
285 /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
287 class EdgeIt : public Edge {
289 /// Default constructor
291 /// @warning The default constructor sets the iterator
292 /// to an undefined value.
294 /// Copy constructor.
296 /// Copy constructor.
298 EdgeIt(const EdgeIt&) { }
299 /// Initialize the iterator to be invalid.
301 /// Initialize the iterator to be invalid.
304 /// This constructor sets the iterator to first edge.
306 /// This constructor set the iterator to the first edge of
308 ///@param g the graph
309 EdgeIt(const StaticGraph& g) { }
310 /// Edge -> EdgeIt conversion
312 /// Sets the iterator to the value of the trivial iterator \c e.
313 /// This feature necessitates that each time we
314 /// iterate the edge-set, the iteration order is the same.
315 EdgeIt(const StaticGraph&, const Edge&) { }
318 /// Assign the iterator to the next
319 /// edge of the corresponding node.
320 EdgeIt& operator++() { return *this; }
323 /// First node of the graph.
325 /// \retval i the first node.
326 /// \return the first node.
328 NodeIt& first(NodeIt& i) const { return i; }
330 /// The first incoming edge.
332 /// The first incoming edge.
334 InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
335 /// The first outgoing edge.
337 /// The first outgoing edge.
339 OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
340 /// The first edge of the Graph.
342 /// The first edge of the Graph.
344 EdgeIt& first(EdgeIt& i) const { return i; }
346 ///Gives back the head node of an edge.
348 ///Gives back the head node of an edge.
350 Node head(Edge) const { return INVALID; }
351 ///Gives back the tail node of an edge.
353 ///Gives back the tail node of an edge.
355 Node tail(Edge) const { return INVALID; }
357 ///Gives back the \e id of a node.
359 ///\warning Not all graph structures provide this feature.
361 ///\todo Should each graph provide \c id?
362 int id(const Node&) const { return 0; }
363 ///Gives back the \e id of an edge.
365 ///\warning Not all graph structures provide this feature.
367 ///\todo Should each graph provide \c id?
368 int id(const Edge&) const { return 0; }
372 ///\todo Should it be in the concept?
374 int nodeNum() const { return 0; }
377 ///\todo Should it be in the concept?
379 int edgeNum() const { return 0; }
382 ///Reference map of the nodes to type \c T.
384 /// \ingroup skeletons
385 ///Reference map of the nodes to type \c T.
387 /// \warning Making maps that can handle bool type (NodeMap<bool>)
388 /// needs some extra attention!
389 template<class T> class NodeMap : public ReferenceMap< Node, T >
394 NodeMap(const StaticGraph&) { }
396 NodeMap(const StaticGraph&, T) { }
399 template<typename TT> NodeMap(const NodeMap<TT>&) { }
400 ///Assignment operator
401 template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
405 ///Reference map of the edges to type \c T.
407 /// \ingroup skeletons
408 ///Reference map of the edges to type \c T.
410 /// \warning Making maps that can handle bool type (EdgeMap<bool>)
411 /// needs some extra attention!
412 template<class T> class EdgeMap
413 : public ReferenceMap<Edge,T>
418 EdgeMap(const StaticGraph&) { }
420 EdgeMap(const StaticGraph&, T) { }
423 template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
424 ///Assignment operator
425 template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
432 /// An empty non-static graph class.
434 /// This class provides everything that \ref StaticGraph
435 /// with additional functionality which enables to build a
436 /// graph from scratch.
437 class ExtendableGraph : public StaticGraph
440 /// Defalult constructor.
442 /// Defalult constructor.
444 ExtendableGraph() { }
445 ///Add a new node to the graph.
447 /// \return the new node.
449 Node addNode() { return INVALID; }
450 ///Add a new edge to the graph.
452 ///Add a new edge to the graph with tail node \c t
453 ///and head node \c h.
454 ///\return the new edge.
455 Edge addEdge(Node h, Node t) { return INVALID; }
457 /// Resets the graph.
459 /// This function deletes all edges and nodes of the graph.
460 /// It also frees the memory allocated to store them.
461 /// \todo It might belong to \ref ErasableGraph.
465 /// An empty erasable graph class.
467 /// This class is an extension of \ref ExtendableGraph. It also makes it
468 /// possible to erase edges or nodes.
469 class ErasableGraph : public ExtendableGraph
472 /// Defalult constructor.
474 /// Defalult constructor.
479 /// Deletes node \c n node.
481 void erase(Node n) { }
484 /// Deletes edge \c e edge.
486 void erase(Edge e) { }
490 } //namespace skeleton
495 #endif // HUGO_SKELETON_GRAPH_H