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