[174] | 1 | // -*- c++ -*- |
---|
[183] | 2 | #ifndef HUGO_EMPTYGRAPH_H |
---|
| 3 | #define HUGO_EMPTYGRAPH_H |
---|
[52] | 4 | |
---|
[163] | 5 | #include <invalid.h> |
---|
[145] | 6 | |
---|
[163] | 7 | /// The namespace of HugoLib |
---|
| 8 | namespace hugo { |
---|
| 9 | |
---|
[182] | 10 | // @defgroup empty_graph The GraphSkeleton class |
---|
[163] | 11 | // @{ |
---|
| 12 | |
---|
| 13 | /// An empty graph class. |
---|
| 14 | |
---|
[186] | 15 | /// This class provides all the common features of a graph structure, |
---|
| 16 | /// however completely without implementations and real data structures |
---|
[163] | 17 | /// behind the interface. |
---|
| 18 | /// All graph algorithms should compile with this class, but it will not |
---|
| 19 | /// run properly, of course. |
---|
| 20 | /// |
---|
| 21 | /// It can be used for checking the interface compatibility, |
---|
| 22 | /// or it can serve as a skeleton of a new graph structure. |
---|
[165] | 23 | /// |
---|
| 24 | /// Also, you will find here the full documentation of a certain graph |
---|
| 25 | /// feature, the documentation of a real graph imlementation |
---|
| 26 | /// like @ref ListGraph or |
---|
| 27 | /// @ref SmartGraph will just refer to this structure. |
---|
[182] | 28 | class GraphSkeleton |
---|
[163] | 29 | { |
---|
[147] | 30 | public: |
---|
| 31 | |
---|
[163] | 32 | /// The base type of the node iterators. |
---|
[182] | 33 | |
---|
[186] | 34 | /// This is the base type of each node iterators, |
---|
[182] | 35 | /// thus each kind of node iterator will convert to this. |
---|
[163] | 36 | class Node { |
---|
| 37 | public: |
---|
| 38 | /// @warning The default constructor sets the iterator |
---|
| 39 | /// to an undefined value. |
---|
| 40 | Node() {} //FIXME |
---|
[182] | 41 | /// Invalid constructor \& conversion. |
---|
| 42 | |
---|
| 43 | /// This constructor initializes the iterator to be invalid. |
---|
| 44 | /// \sa Invalid for more details. |
---|
| 45 | |
---|
[174] | 46 | Node(Invalid) {} |
---|
[182] | 47 | //Node(const Node &) {} |
---|
| 48 | |
---|
| 49 | /// Two iterators are equal if and only if they point to the |
---|
| 50 | /// same object or both are invalid. |
---|
| 51 | bool operator==(Node n) const { return true; } |
---|
| 52 | |
---|
| 53 | /// \sa \ref operator==(Node n) |
---|
| 54 | /// |
---|
| 55 | bool operator!=(Node n) const { return true; } |
---|
| 56 | |
---|
| 57 | bool operator<(Node n) const { return true; } |
---|
[163] | 58 | }; |
---|
[147] | 59 | |
---|
[163] | 60 | /// This iterator goes through each node. |
---|
[186] | 61 | |
---|
| 62 | /// This iterator goes through each node. |
---|
| 63 | /// Its usage is quite simple, for example you can count the number |
---|
| 64 | /// of nodes in graph \c G of type \c Graph like this: |
---|
| 65 | /// \code |
---|
| 66 | ///int count=0; |
---|
| 67 | ///for(Graph::NodeIt n(G);G.valid(n);G.next(n)) count++; |
---|
| 68 | /// \endcode |
---|
[163] | 69 | class NodeIt : public Node { |
---|
| 70 | public: |
---|
| 71 | /// @warning The default constructor sets the iterator |
---|
| 72 | /// to an undefined value. |
---|
| 73 | NodeIt() {} //FIXME |
---|
[182] | 74 | /// Invalid constructor \& conversion. |
---|
| 75 | |
---|
[163] | 76 | /// Initialize the iterator to be invalid |
---|
[182] | 77 | /// \sa Invalid for more details. |
---|
[174] | 78 | NodeIt(Invalid) {} |
---|
[163] | 79 | /// Sets the iterator to the first node of \c G. |
---|
[182] | 80 | NodeIt(const GraphSkeleton &G) {} |
---|
| 81 | /// @warning The default constructor sets the iterator |
---|
| 82 | /// to an undefined value. |
---|
| 83 | NodeIt(const NodeIt &) {} |
---|
[163] | 84 | }; |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | /// The base type of the edge iterators. |
---|
| 88 | class Edge { |
---|
| 89 | public: |
---|
| 90 | /// @warning The default constructor sets the iterator |
---|
| 91 | /// to an undefined value. |
---|
| 92 | Edge() {} //FIXME |
---|
| 93 | /// Initialize the iterator to be invalid |
---|
[174] | 94 | Edge(Invalid) {} |
---|
[182] | 95 | /// Two iterators are equal if and only if they point to the |
---|
| 96 | /// same object or both are invalid. |
---|
| 97 | bool operator==(Edge n) const { return true; } |
---|
| 98 | bool operator!=(Edge n) const { return true; } |
---|
| 99 | bool operator<(Edge n) const { return true; } |
---|
[163] | 100 | }; |
---|
| 101 | |
---|
[186] | 102 | /// This iterator goes trought the outgoing edges of a node. |
---|
| 103 | |
---|
| 104 | /// This iterator goes trought the \e outgoing edges of a certain node |
---|
| 105 | /// of a graph. |
---|
| 106 | /// Its usage is quite simple, for example you can count the number |
---|
| 107 | /// of outgoing edges of a node \c n |
---|
| 108 | /// in graph \c G of type \c Graph as follows. |
---|
| 109 | /// \code |
---|
| 110 | ///int count=0; |
---|
| 111 | ///for(Graph::OutEdgeIt e(G,n);G.valid(e);G.next(e)) count++; |
---|
| 112 | /// \endcode |
---|
[163] | 113 | |
---|
| 114 | class OutEdgeIt : public Edge { |
---|
| 115 | public: |
---|
| 116 | /// @warning The default constructor sets the iterator |
---|
| 117 | /// to an undefined value. |
---|
| 118 | OutEdgeIt() {} |
---|
| 119 | /// Initialize the iterator to be invalid |
---|
[174] | 120 | OutEdgeIt(Invalid) {} |
---|
[163] | 121 | /// This constructor sets the iterator to first outgoing edge. |
---|
| 122 | |
---|
| 123 | /// This constructor set the iterator to the first outgoing edge of |
---|
| 124 | /// node |
---|
| 125 | ///@param n the node |
---|
| 126 | ///@param G the graph |
---|
[182] | 127 | OutEdgeIt(const GraphSkeleton & G, Node n) {} |
---|
[163] | 128 | }; |
---|
| 129 | |
---|
[186] | 130 | /// This iterator goes trought the incoming edges of a node. |
---|
| 131 | |
---|
| 132 | /// This iterator goes trought the \e incoming edges of a certain node |
---|
| 133 | /// of a graph. |
---|
| 134 | /// Its usage is quite simple, for example you can count the number |
---|
| 135 | /// of outgoing edges of a node \c n |
---|
| 136 | /// in graph \c G of type \c Graph as follows. |
---|
| 137 | /// \code |
---|
| 138 | ///int count=0; |
---|
| 139 | ///for(Graph::InEdgeIt e(G,n);G.valid(e);G.next(e)) count++; |
---|
| 140 | /// \endcode |
---|
| 141 | |
---|
[163] | 142 | class InEdgeIt : public Edge { |
---|
| 143 | public: |
---|
| 144 | /// @warning The default constructor sets the iterator |
---|
| 145 | /// to an undefined value. |
---|
| 146 | InEdgeIt() {} |
---|
| 147 | /// Initialize the iterator to be invalid |
---|
[174] | 148 | InEdgeIt(Invalid) {} |
---|
[182] | 149 | InEdgeIt(const GraphSkeleton &, Node) {} |
---|
[163] | 150 | }; |
---|
| 151 | // class SymEdgeIt : public Edge {}; |
---|
[186] | 152 | |
---|
| 153 | /// This iterator goes through each edge. |
---|
| 154 | |
---|
| 155 | /// This iterator goes through each edge of a graph. |
---|
| 156 | /// Its usage is quite simple, for example you can count the number |
---|
| 157 | /// of edges in a graph \c G of type \c Graph as follows: |
---|
| 158 | /// \code |
---|
| 159 | ///int count=0; |
---|
| 160 | ///for(Graph::EdgeIt e(G);G.valid(e);G.next(e)) count++; |
---|
| 161 | /// \endcode |
---|
[163] | 162 | class EdgeIt : public Edge { |
---|
| 163 | public: |
---|
| 164 | /// @warning The default constructor sets the iterator |
---|
| 165 | /// to an undefined value. |
---|
| 166 | EdgeIt() {} |
---|
| 167 | /// Initialize the iterator to be invalid |
---|
[174] | 168 | EdgeIt(Invalid) {} |
---|
[182] | 169 | EdgeIt(const GraphSkeleton &) {} |
---|
[163] | 170 | }; |
---|
| 171 | |
---|
| 172 | /// First node of the graph. |
---|
| 173 | |
---|
| 174 | /// \post \c i and the return value will be the first node. |
---|
| 175 | /// |
---|
| 176 | NodeIt &first(NodeIt &i) const { return i;} |
---|
| 177 | |
---|
| 178 | /// The first outgoing edge. |
---|
| 179 | InEdgeIt &first(InEdgeIt &i, Node n) const { return i;} |
---|
| 180 | /// The first incoming edge. |
---|
| 181 | OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;} |
---|
| 182 | // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;} |
---|
| 183 | /// The first edge of the Graph. |
---|
| 184 | EdgeIt &first(EdgeIt &i) const { return i;} |
---|
| 185 | |
---|
| 186 | // Node getNext(Node) const {} |
---|
| 187 | // InEdgeIt getNext(InEdgeIt) const {} |
---|
| 188 | // OutEdgeIt getNext(OutEdgeIt) const {} |
---|
| 189 | // //SymEdgeIt getNext(SymEdgeIt) const {} |
---|
| 190 | // EdgeIt getNext(EdgeIt) const {} |
---|
| 191 | |
---|
| 192 | /// Go to the next node. |
---|
[178] | 193 | NodeIt &next(NodeIt &i) const { return i;} |
---|
[163] | 194 | /// Go to the next incoming edge. |
---|
| 195 | InEdgeIt &next(InEdgeIt &i) const { return i;} |
---|
| 196 | /// Go to the next outgoing edge. |
---|
| 197 | OutEdgeIt &next(OutEdgeIt &i) const { return i;} |
---|
| 198 | //SymEdgeIt &next(SymEdgeIt &) const {} |
---|
| 199 | /// Go to the next edge. |
---|
| 200 | EdgeIt &next(EdgeIt &i) const { return i;} |
---|
| 201 | |
---|
| 202 | ///Gives back the head node of an edge. |
---|
| 203 | Node head(Edge) const { return INVALID; } |
---|
| 204 | ///Gives back the tail node of an edge. |
---|
| 205 | Node tail(Edge) const { return INVALID; } |
---|
[52] | 206 | |
---|
[163] | 207 | // Node aNode(InEdgeIt) const {} |
---|
| 208 | // Node aNode(OutEdgeIt) const {} |
---|
| 209 | // Node aNode(SymEdgeIt) const {} |
---|
| 210 | |
---|
| 211 | // Node bNode(InEdgeIt) const {} |
---|
| 212 | // Node bNode(OutEdgeIt) const {} |
---|
| 213 | // Node bNode(SymEdgeIt) const {} |
---|
| 214 | |
---|
| 215 | /// Checks if a node iterator is valid |
---|
[186] | 216 | |
---|
| 217 | ///\todo Maybe, it would be better if iterator converted to |
---|
| 218 | ///bool directly, as Jacint prefers. |
---|
[174] | 219 | bool valid(const Node) const { return true;} |
---|
[163] | 220 | /// Checks if an edge iterator is valid |
---|
[186] | 221 | |
---|
| 222 | ///\todo Maybe, it would be better if iterator converted to |
---|
| 223 | ///bool directly, as Jacint prefers. |
---|
[174] | 224 | bool valid(const Edge) const { return true;} |
---|
[163] | 225 | |
---|
| 226 | ///Gives back the \e id of a node. |
---|
[182] | 227 | |
---|
| 228 | ///\warning Not all graph structure provide this feature. |
---|
| 229 | /// |
---|
[174] | 230 | int id(const Node) const { return 0;} |
---|
[163] | 231 | ///Gives back the \e id of an edge. |
---|
[182] | 232 | |
---|
| 233 | ///\warning Not all graph structure provide this feature. |
---|
| 234 | /// |
---|
[174] | 235 | int id(const Edge) const { return 0;} |
---|
[163] | 236 | |
---|
| 237 | //void setInvalid(Node &) const {}; |
---|
| 238 | //void setInvalid(Edge &) const {}; |
---|
| 239 | |
---|
[182] | 240 | ///Add a new node to the graph. |
---|
| 241 | |
---|
| 242 | /// \return the new node. |
---|
[186] | 243 | /// |
---|
[163] | 244 | Node addNode() { return INVALID;} |
---|
[182] | 245 | ///Add a new edge to the graph. |
---|
| 246 | |
---|
| 247 | ///Add a new edge to the graph with tail node \c tail |
---|
| 248 | ///and head node \c head. |
---|
| 249 | ///\return the new edge. |
---|
[163] | 250 | Edge addEdge(Node tail, Node head) { return INVALID;} |
---|
| 251 | |
---|
[182] | 252 | /// Deletes a node. |
---|
| 253 | |
---|
| 254 | ///\warning Not all graph structure provide this feature. |
---|
| 255 | /// |
---|
[163] | 256 | void erase(Node n) {} |
---|
[182] | 257 | /// Deletes an edge. |
---|
| 258 | |
---|
| 259 | ///\warning Not all graph structure provide this feature. |
---|
| 260 | /// |
---|
[163] | 261 | void erase(Edge e) {} |
---|
| 262 | |
---|
[182] | 263 | /// Reset the graph. |
---|
| 264 | |
---|
| 265 | /// This function deletes all edges and nodes of the graph. |
---|
| 266 | /// It also frees the memory allocated to store them. |
---|
[163] | 267 | void clear() {} |
---|
| 268 | |
---|
[179] | 269 | int nodeNum() const { return 0;} |
---|
| 270 | int edgeNum() const { return 0;} |
---|
[163] | 271 | |
---|
[182] | 272 | GraphSkeleton() {} |
---|
| 273 | GraphSkeleton(const GraphSkeleton &G) {} |
---|
[163] | 274 | |
---|
| 275 | |
---|
| 276 | |
---|
[186] | 277 | ///Read/write/reference map of the nodes to type \c T. |
---|
[182] | 278 | |
---|
[186] | 279 | ///Read/write/reference map of the nodes to type \c T. |
---|
| 280 | /// \sa MemoryMapSkeleton |
---|
[182] | 281 | /// \todo We may need copy constructor |
---|
| 282 | /// \todo We may need conversion from other nodetype |
---|
| 283 | /// \todo We may need operator= |
---|
| 284 | |
---|
[163] | 285 | template<class T> class NodeMap |
---|
| 286 | { |
---|
| 287 | public: |
---|
| 288 | typedef T ValueType; |
---|
| 289 | typedef Node KeyType; |
---|
| 290 | |
---|
[182] | 291 | NodeMap(const GraphSkeleton &G) {} |
---|
| 292 | NodeMap(const GraphSkeleton &G, T t) {} |
---|
[163] | 293 | |
---|
[182] | 294 | template<typename TT> NodeMap(const NodeMap<TT> &m) {} |
---|
| 295 | |
---|
| 296 | /// Sets the value of a node. |
---|
| 297 | |
---|
| 298 | /// Sets the value associated with node \c i to the value \c t. |
---|
| 299 | /// |
---|
[163] | 300 | void set(Node i, T t) {} |
---|
[182] | 301 | /// Gets the value of a node. |
---|
| 302 | T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary |
---|
| 303 | T &operator[](Node i) {return *(T*)0;} |
---|
| 304 | const T &operator[](Node i) const {return *(T*)0;} |
---|
[163] | 305 | |
---|
[182] | 306 | /// Updates the map if the graph has been changed |
---|
| 307 | |
---|
| 308 | /// \todo Do we need this? |
---|
| 309 | /// |
---|
[163] | 310 | void update() {} |
---|
| 311 | void update(T a) {} //FIXME: Is it necessary |
---|
| 312 | }; |
---|
| 313 | |
---|
[186] | 314 | ///Read/write/reference map of the edges to type \c T. |
---|
[182] | 315 | |
---|
[186] | 316 | ///Read/write/reference map of the edges to type \c T. |
---|
| 317 | ///It behaves exactly in the same way as \ref NodeMap. |
---|
| 318 | /// \sa NodeMap |
---|
| 319 | /// \sa MemoryMapSkeleton |
---|
| 320 | /// \todo We may need copy constructor |
---|
| 321 | /// \todo We may need conversion from other edgetype |
---|
| 322 | /// \todo We may need operator= |
---|
[163] | 323 | template<class T> class EdgeMap |
---|
| 324 | { |
---|
| 325 | public: |
---|
| 326 | typedef T ValueType; |
---|
| 327 | typedef Edge KeyType; |
---|
| 328 | |
---|
[182] | 329 | EdgeMap(const GraphSkeleton &G) {} |
---|
| 330 | EdgeMap(const GraphSkeleton &G, T t) {} |
---|
[163] | 331 | |
---|
| 332 | void set(Edge i, T t) {} |
---|
[182] | 333 | T get(Edge i) const {return *(T*)0;} |
---|
| 334 | T &operator[](Edge i) {return *(T*)0;} |
---|
[163] | 335 | |
---|
| 336 | void update() {} |
---|
| 337 | void update(T a) {} //FIXME: Is it necessary |
---|
| 338 | }; |
---|
[147] | 339 | }; |
---|
[52] | 340 | |
---|
[163] | 341 | // @} |
---|
[147] | 342 | |
---|
[174] | 343 | } //namespace hugo |
---|
[52] | 344 | |
---|
[145] | 345 | |
---|
| 346 | |
---|
[182] | 347 | // class EmptyBipGraph : public Graph Skeleton |
---|
[147] | 348 | // { |
---|
[163] | 349 | // class ANode {}; |
---|
| 350 | // class BNode {}; |
---|
[145] | 351 | |
---|
[163] | 352 | // ANode &next(ANode &) {} |
---|
| 353 | // BNode &next(BNode &) {} |
---|
[145] | 354 | |
---|
[163] | 355 | // ANode &getFirst(ANode &) const {} |
---|
| 356 | // BNode &getFirst(BNode &) const {} |
---|
[145] | 357 | |
---|
[147] | 358 | // enum NodeClass { A = 0, B = 1 }; |
---|
[163] | 359 | // NodeClass getClass(Node n) {} |
---|
[147] | 360 | |
---|
| 361 | // } |
---|
[174] | 362 | |
---|
[183] | 363 | #endif // HUGO_EMPTYGRAPH_H |
---|