[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 | |
---|
| 15 | /// This class provides all the common features of a grapf structure, |
---|
| 16 | /// however completely without implementations or real data structures |
---|
| 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 | |
---|
| 34 | /// This \c Node is the base type of each node iterators, |
---|
| 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. |
---|
| 61 | class NodeIt : public Node { |
---|
| 62 | public: |
---|
| 63 | /// @warning The default constructor sets the iterator |
---|
| 64 | /// to an undefined value. |
---|
| 65 | NodeIt() {} //FIXME |
---|
[182] | 66 | /// Invalid constructor \& conversion. |
---|
| 67 | |
---|
[163] | 68 | /// Initialize the iterator to be invalid |
---|
[182] | 69 | /// \sa Invalid for more details. |
---|
[174] | 70 | NodeIt(Invalid) {} |
---|
[163] | 71 | /// Sets the iterator to the first node of \c G. |
---|
[182] | 72 | NodeIt(const GraphSkeleton &G) {} |
---|
| 73 | /// @warning The default constructor sets the iterator |
---|
| 74 | /// to an undefined value. |
---|
| 75 | NodeIt(const NodeIt &) {} |
---|
[163] | 76 | }; |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /// The base type of the edge iterators. |
---|
| 80 | class Edge { |
---|
| 81 | public: |
---|
| 82 | /// @warning The default constructor sets the iterator |
---|
| 83 | /// to an undefined value. |
---|
| 84 | Edge() {} //FIXME |
---|
| 85 | /// Initialize the iterator to be invalid |
---|
[174] | 86 | Edge(Invalid) {} |
---|
[182] | 87 | /// Two iterators are equal if and only if they point to the |
---|
| 88 | /// same object or both are invalid. |
---|
| 89 | bool operator==(Edge n) const { return true; } |
---|
| 90 | bool operator!=(Edge n) const { return true; } |
---|
| 91 | bool operator<(Edge n) const { return true; } |
---|
[163] | 92 | }; |
---|
| 93 | |
---|
| 94 | /// This iterator goes trought the outgoing edges of a certain graph. |
---|
| 95 | |
---|
| 96 | class OutEdgeIt : public Edge { |
---|
| 97 | public: |
---|
| 98 | /// @warning The default constructor sets the iterator |
---|
| 99 | /// to an undefined value. |
---|
| 100 | OutEdgeIt() {} |
---|
| 101 | /// Initialize the iterator to be invalid |
---|
[174] | 102 | OutEdgeIt(Invalid) {} |
---|
[163] | 103 | /// This constructor sets the iterator to first outgoing edge. |
---|
| 104 | |
---|
| 105 | /// This constructor set the iterator to the first outgoing edge of |
---|
| 106 | /// node |
---|
| 107 | ///@param n the node |
---|
| 108 | ///@param G the graph |
---|
[182] | 109 | OutEdgeIt(const GraphSkeleton & G, Node n) {} |
---|
[163] | 110 | }; |
---|
| 111 | |
---|
| 112 | class InEdgeIt : public Edge { |
---|
| 113 | public: |
---|
| 114 | /// @warning The default constructor sets the iterator |
---|
| 115 | /// to an undefined value. |
---|
| 116 | InEdgeIt() {} |
---|
| 117 | /// Initialize the iterator to be invalid |
---|
[174] | 118 | InEdgeIt(Invalid) {} |
---|
[182] | 119 | InEdgeIt(const GraphSkeleton &, Node) {} |
---|
[163] | 120 | }; |
---|
| 121 | // class SymEdgeIt : public Edge {}; |
---|
| 122 | class EdgeIt : public Edge { |
---|
| 123 | public: |
---|
| 124 | /// @warning The default constructor sets the iterator |
---|
| 125 | /// to an undefined value. |
---|
| 126 | EdgeIt() {} |
---|
| 127 | /// Initialize the iterator to be invalid |
---|
[174] | 128 | EdgeIt(Invalid) {} |
---|
[182] | 129 | EdgeIt(const GraphSkeleton &) {} |
---|
[163] | 130 | }; |
---|
| 131 | |
---|
| 132 | /// First node of the graph. |
---|
| 133 | |
---|
| 134 | /// \post \c i and the return value will be the first node. |
---|
| 135 | /// |
---|
| 136 | NodeIt &first(NodeIt &i) const { return i;} |
---|
| 137 | |
---|
| 138 | /// The first outgoing edge. |
---|
| 139 | InEdgeIt &first(InEdgeIt &i, Node n) const { return i;} |
---|
| 140 | /// The first incoming edge. |
---|
| 141 | OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;} |
---|
| 142 | // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;} |
---|
| 143 | /// The first edge of the Graph. |
---|
| 144 | EdgeIt &first(EdgeIt &i) const { return i;} |
---|
| 145 | |
---|
| 146 | // Node getNext(Node) const {} |
---|
| 147 | // InEdgeIt getNext(InEdgeIt) const {} |
---|
| 148 | // OutEdgeIt getNext(OutEdgeIt) const {} |
---|
| 149 | // //SymEdgeIt getNext(SymEdgeIt) const {} |
---|
| 150 | // EdgeIt getNext(EdgeIt) const {} |
---|
| 151 | |
---|
| 152 | /// Go to the next node. |
---|
[178] | 153 | NodeIt &next(NodeIt &i) const { return i;} |
---|
[163] | 154 | /// Go to the next incoming edge. |
---|
| 155 | InEdgeIt &next(InEdgeIt &i) const { return i;} |
---|
| 156 | /// Go to the next outgoing edge. |
---|
| 157 | OutEdgeIt &next(OutEdgeIt &i) const { return i;} |
---|
| 158 | //SymEdgeIt &next(SymEdgeIt &) const {} |
---|
| 159 | /// Go to the next edge. |
---|
| 160 | EdgeIt &next(EdgeIt &i) const { return i;} |
---|
| 161 | |
---|
| 162 | ///Gives back the head node of an edge. |
---|
| 163 | Node head(Edge) const { return INVALID; } |
---|
| 164 | ///Gives back the tail node of an edge. |
---|
| 165 | Node tail(Edge) const { return INVALID; } |
---|
[52] | 166 | |
---|
[163] | 167 | // Node aNode(InEdgeIt) const {} |
---|
| 168 | // Node aNode(OutEdgeIt) const {} |
---|
| 169 | // Node aNode(SymEdgeIt) const {} |
---|
| 170 | |
---|
| 171 | // Node bNode(InEdgeIt) const {} |
---|
| 172 | // Node bNode(OutEdgeIt) const {} |
---|
| 173 | // Node bNode(SymEdgeIt) const {} |
---|
| 174 | |
---|
| 175 | /// Checks if a node iterator is valid |
---|
[174] | 176 | bool valid(const Node) const { return true;} |
---|
[163] | 177 | /// Checks if an edge iterator is valid |
---|
[174] | 178 | bool valid(const Edge) const { return true;} |
---|
[163] | 179 | |
---|
| 180 | ///Gives back the \e id of a node. |
---|
[182] | 181 | |
---|
| 182 | ///\warning Not all graph structure provide this feature. |
---|
| 183 | /// |
---|
[174] | 184 | int id(const Node) const { return 0;} |
---|
[163] | 185 | ///Gives back the \e id of an edge. |
---|
[182] | 186 | |
---|
| 187 | ///\warning Not all graph structure provide this feature. |
---|
| 188 | /// |
---|
[174] | 189 | int id(const Edge) const { return 0;} |
---|
[163] | 190 | |
---|
| 191 | //void setInvalid(Node &) const {}; |
---|
| 192 | //void setInvalid(Edge &) const {}; |
---|
| 193 | |
---|
[182] | 194 | ///Add a new node to the graph. |
---|
| 195 | |
---|
| 196 | /// \return the new node. |
---|
[163] | 197 | Node addNode() { return INVALID;} |
---|
[182] | 198 | ///Add a new edge to the graph. |
---|
| 199 | |
---|
| 200 | ///Add a new edge to the graph with tail node \c tail |
---|
| 201 | ///and head node \c head. |
---|
| 202 | ///\return the new edge. |
---|
[163] | 203 | Edge addEdge(Node tail, Node head) { return INVALID;} |
---|
| 204 | |
---|
[182] | 205 | /// Deletes a node. |
---|
| 206 | |
---|
| 207 | ///\warning Not all graph structure provide this feature. |
---|
| 208 | /// |
---|
[163] | 209 | void erase(Node n) {} |
---|
[182] | 210 | /// Deletes an edge. |
---|
| 211 | |
---|
| 212 | ///\warning Not all graph structure provide this feature. |
---|
| 213 | /// |
---|
[163] | 214 | void erase(Edge e) {} |
---|
| 215 | |
---|
[182] | 216 | /// Reset the graph. |
---|
| 217 | |
---|
| 218 | /// This function deletes all edges and nodes of the graph. |
---|
| 219 | /// It also frees the memory allocated to store them. |
---|
[163] | 220 | void clear() {} |
---|
| 221 | |
---|
[179] | 222 | int nodeNum() const { return 0;} |
---|
| 223 | int edgeNum() const { return 0;} |
---|
[163] | 224 | |
---|
[182] | 225 | GraphSkeleton() {} |
---|
| 226 | GraphSkeleton(const GraphSkeleton &G) {} |
---|
[163] | 227 | |
---|
| 228 | |
---|
| 229 | |
---|
[182] | 230 | ///Read/write map of the nodes to type \c T. |
---|
| 231 | |
---|
| 232 | /// \todo We may need copy constructor |
---|
| 233 | /// \todo We may need conversion from other nodetype |
---|
| 234 | /// \todo We may need operator= |
---|
| 235 | |
---|
[163] | 236 | template<class T> class NodeMap |
---|
| 237 | { |
---|
| 238 | public: |
---|
| 239 | typedef T ValueType; |
---|
| 240 | typedef Node KeyType; |
---|
| 241 | |
---|
[182] | 242 | NodeMap(const GraphSkeleton &G) {} |
---|
| 243 | NodeMap(const GraphSkeleton &G, T t) {} |
---|
[163] | 244 | |
---|
[182] | 245 | template<typename TT> NodeMap(const NodeMap<TT> &m) {} |
---|
| 246 | |
---|
| 247 | /// Sets the value of a node. |
---|
| 248 | |
---|
| 249 | /// Sets the value associated with node \c i to the value \c t. |
---|
| 250 | /// |
---|
[163] | 251 | void set(Node i, T t) {} |
---|
[182] | 252 | /// Gets the value of a node. |
---|
| 253 | T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary |
---|
| 254 | T &operator[](Node i) {return *(T*)0;} |
---|
| 255 | const T &operator[](Node i) const {return *(T*)0;} |
---|
[163] | 256 | |
---|
[182] | 257 | /// Updates the map if the graph has been changed |
---|
| 258 | |
---|
| 259 | /// \todo Do we need this? |
---|
| 260 | /// |
---|
[163] | 261 | void update() {} |
---|
| 262 | void update(T a) {} //FIXME: Is it necessary |
---|
| 263 | }; |
---|
| 264 | |
---|
[182] | 265 | ///Read/write map of the edges to type \c T. |
---|
| 266 | |
---|
| 267 | ///Read/write map of the edges to type \c T. |
---|
| 268 | ///It behaves exactly the same way as \ref NodeMap. |
---|
[163] | 269 | template<class T> class EdgeMap |
---|
| 270 | { |
---|
| 271 | public: |
---|
| 272 | typedef T ValueType; |
---|
| 273 | typedef Edge KeyType; |
---|
| 274 | |
---|
[182] | 275 | EdgeMap(const GraphSkeleton &G) {} |
---|
| 276 | EdgeMap(const GraphSkeleton &G, T t) {} |
---|
[163] | 277 | |
---|
| 278 | void set(Edge i, T t) {} |
---|
[182] | 279 | T get(Edge i) const {return *(T*)0;} |
---|
| 280 | T &operator[](Edge i) {return *(T*)0;} |
---|
[163] | 281 | |
---|
| 282 | void update() {} |
---|
| 283 | void update(T a) {} //FIXME: Is it necessary |
---|
| 284 | }; |
---|
[147] | 285 | }; |
---|
[52] | 286 | |
---|
[163] | 287 | // @} |
---|
[147] | 288 | |
---|
[174] | 289 | } //namespace hugo |
---|
[52] | 290 | |
---|
[145] | 291 | |
---|
| 292 | |
---|
[182] | 293 | // class EmptyBipGraph : public Graph Skeleton |
---|
[147] | 294 | // { |
---|
[163] | 295 | // class ANode {}; |
---|
| 296 | // class BNode {}; |
---|
[145] | 297 | |
---|
[163] | 298 | // ANode &next(ANode &) {} |
---|
| 299 | // BNode &next(BNode &) {} |
---|
[145] | 300 | |
---|
[163] | 301 | // ANode &getFirst(ANode &) const {} |
---|
| 302 | // BNode &getFirst(BNode &) const {} |
---|
[145] | 303 | |
---|
[147] | 304 | // enum NodeClass { A = 0, B = 1 }; |
---|
[163] | 305 | // NodeClass getClass(Node n) {} |
---|
[147] | 306 | |
---|
| 307 | // } |
---|
[174] | 308 | |
---|
[183] | 309 | #endif // HUGO_EMPTYGRAPH_H |
---|