src/work/alpar/emptygraph.h
author alpar
Wed, 10 Mar 2004 17:47:54 +0000
changeset 164 970b265696b0
parent 157 ee17030e5f47
child 165 9b078bc3ce13
permissions -rw-r--r--
New graph interface
alpar@52
     1
// -*-mode: c++; -*-
alpar@52
     2
alpar@163
     3
#include <invalid.h>
alpar@145
     4
alpar@163
     5
/// The namespace of HugoLib
alpar@163
     6
namespace hugo {
alpar@163
     7
alpar@163
     8
  // @defgroup empty_graph The EmptyGraph class
alpar@163
     9
  // @{
alpar@163
    10
alpar@163
    11
  /// An empty graph class.
alpar@163
    12
  
alpar@163
    13
  /// This class provides all the common features of a grapf structure,
alpar@163
    14
  /// however completely without implementations or real data structures
alpar@163
    15
  /// behind the interface.
alpar@163
    16
  /// All graph algorithms should compile with this class, but it will not
alpar@163
    17
  /// run properly, of course.
alpar@163
    18
  ///
alpar@163
    19
  /// It can be used for checking the interface compatibility,
alpar@163
    20
  /// or it can serve as a skeleton of a new graph structure.
alpar@163
    21
alpar@163
    22
  class EmptyGraph
alpar@163
    23
  {
alpar@147
    24
  public:
alpar@147
    25
    
alpar@163
    26
    /// The base type of the node iterators.
alpar@163
    27
    class Node {
alpar@163
    28
    public:
alpar@163
    29
      /// @warning The default constructor sets the iterator
alpar@163
    30
      /// to an undefined value.
alpar@163
    31
      Node() {}   //FIXME
alpar@163
    32
      /// Initialize the iterator to be invalid
alpar@163
    33
      Node(Invalid) {};
alpar@163
    34
      //Node(const Node &) {} 
alpar@163
    35
      bool operator==(Node n) const { return true; } //FIXME
alpar@163
    36
      bool operator!=(Node n) const { return true; } //FIXME
alpar@163
    37
    };
alpar@147
    38
    
alpar@163
    39
    /// This iterator goes through each node.
alpar@163
    40
    class NodeIt : public Node {
alpar@163
    41
    public:
alpar@163
    42
      /// @warning The default constructor sets the iterator
alpar@163
    43
      /// to an undefined value.
alpar@163
    44
      NodeIt() {} //FIXME
alpar@163
    45
      /// Initialize the iterator to be invalid
alpar@163
    46
      NodeIt(Invalid) {};
alpar@163
    47
      /// Sets the iterator to the first node of \c G.
alpar@163
    48
      NodeIt(const EmptyGraph &G) {}
alpar@163
    49
      NodeIt(const NodeIt &) {} //FIXME
alpar@163
    50
    };
alpar@163
    51
    
alpar@163
    52
    
alpar@163
    53
    /// The base type of the edge iterators.
alpar@163
    54
    class Edge {
alpar@163
    55
    public:
alpar@163
    56
      /// @warning The default constructor sets the iterator
alpar@163
    57
      /// to an undefined value.
alpar@163
    58
      Edge() {}   //FIXME
alpar@163
    59
      /// Initialize the iterator to be invalid
alpar@163
    60
      Edge(Invalid) {};
alpar@163
    61
      //Edge(const Edge &) {} 
alpar@163
    62
      bool operator==(Edge n) const { return true; } //FIXME
alpar@163
    63
      bool operator!=(Edge n) const { return true; } //FIXME    
alpar@163
    64
    };
alpar@163
    65
    
alpar@163
    66
    /// This iterator goes trought the outgoing edges of a certain graph.
alpar@163
    67
    
alpar@163
    68
    class OutEdgeIt : public Edge {
alpar@163
    69
    public:
alpar@163
    70
      /// @warning The default constructor sets the iterator
alpar@163
    71
      /// to an undefined value.
alpar@163
    72
      OutEdgeIt() {}
alpar@163
    73
      /// Initialize the iterator to be invalid
alpar@163
    74
      OutEdgeIt(Invalid) {};
alpar@163
    75
      /// This constructor sets the iterator to first outgoing edge.
alpar@163
    76
    
alpar@163
    77
      /// This constructor set the iterator to the first outgoing edge of
alpar@163
    78
      /// node
alpar@163
    79
      ///@param n the node
alpar@163
    80
      ///@param G the graph
alpar@163
    81
      OutEdgeIt(const EmptyGraph & G, Node n) {}
alpar@163
    82
    };
alpar@163
    83
alpar@163
    84
    class InEdgeIt : public Edge {
alpar@163
    85
    public:
alpar@163
    86
      /// @warning The default constructor sets the iterator
alpar@163
    87
      /// to an undefined value.
alpar@163
    88
      InEdgeIt() {}
alpar@163
    89
      /// Initialize the iterator to be invalid
alpar@163
    90
      InEdgeIt(Invalid) {};
alpar@163
    91
      InEdgeIt(const EmptyGraph &, Node) {}    
alpar@163
    92
    };
alpar@163
    93
    //  class SymEdgeIt : public Edge {};
alpar@163
    94
    class EdgeIt : public Edge {
alpar@163
    95
    public:
alpar@163
    96
      /// @warning The default constructor sets the iterator
alpar@163
    97
      /// to an undefined value.
alpar@163
    98
      EdgeIt() {}
alpar@163
    99
      /// Initialize the iterator to be invalid
alpar@163
   100
      EdgeIt(Invalid) {};
alpar@163
   101
      EdgeIt(const EmptyGraph &) {}
alpar@163
   102
    };
alpar@163
   103
alpar@163
   104
    /// First node of the graph.
alpar@163
   105
alpar@163
   106
    /// \post \c i and the return value will be the first node.
alpar@163
   107
    ///
alpar@163
   108
    NodeIt &first(NodeIt &i) const { return i;}
alpar@163
   109
alpar@163
   110
    /// The first outgoing edge.
alpar@163
   111
    InEdgeIt &first(InEdgeIt &i, Node n) const { return i;}
alpar@163
   112
    /// The first incoming edge.
alpar@163
   113
    OutEdgeIt &first(OutEdgeIt &i, Node n) const { return i;}
alpar@163
   114
    //  SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
alpar@163
   115
    /// The first edge of the Graph.
alpar@163
   116
    EdgeIt &first(EdgeIt &i) const { return i;}
alpar@163
   117
alpar@163
   118
//     Node getNext(Node) const {}
alpar@163
   119
//     InEdgeIt getNext(InEdgeIt) const {}
alpar@163
   120
//     OutEdgeIt getNext(OutEdgeIt) const {}
alpar@163
   121
//     //SymEdgeIt getNext(SymEdgeIt) const {}
alpar@163
   122
//     EdgeIt getNext(EdgeIt) const {}
alpar@163
   123
alpar@163
   124
    /// Go to the next node.
alpar@163
   125
    Node &next(Node &i) const { return i;}
alpar@163
   126
    /// Go to the next incoming edge.
alpar@163
   127
    InEdgeIt &next(InEdgeIt &i) const { return i;}
alpar@163
   128
    /// Go to the next outgoing edge.
alpar@163
   129
    OutEdgeIt &next(OutEdgeIt &i) const { return i;}
alpar@163
   130
    //SymEdgeIt &next(SymEdgeIt &) const {}
alpar@163
   131
    /// Go to the next edge.
alpar@163
   132
    EdgeIt &next(EdgeIt &i) const { return i;}
alpar@163
   133
alpar@163
   134
    ///Gives back the head node of an edge.
alpar@163
   135
    Node head(Edge) const { return INVALID; }
alpar@163
   136
    ///Gives back the tail node of an edge.
alpar@163
   137
    Node tail(Edge) const { return INVALID; }
alpar@52
   138
  
alpar@163
   139
    //   Node aNode(InEdgeIt) const {}
alpar@163
   140
    //   Node aNode(OutEdgeIt) const {}
alpar@163
   141
    //   Node aNode(SymEdgeIt) const {}
alpar@163
   142
alpar@163
   143
    //   Node bNode(InEdgeIt) const {}
alpar@163
   144
    //   Node bNode(OutEdgeIt) const {}
alpar@163
   145
    //   Node bNode(SymEdgeIt) const {}
alpar@163
   146
alpar@163
   147
    /// Checks if a node iterator is valid
alpar@163
   148
    bool valid(const Node) const { return true;};
alpar@163
   149
    /// Checks if an edge iterator is valid
alpar@163
   150
    bool valid(const Edge) const { return true;};
alpar@163
   151
alpar@163
   152
    ///Gives back the \e id of a node.
alpar@163
   153
    int id(const Node) const { return 0;};
alpar@163
   154
    ///Gives back the \e id of an edge.
alpar@163
   155
    int id(const Edge) const { return 0;};
alpar@163
   156
alpar@163
   157
    //void setInvalid(Node &) const {};
alpar@163
   158
    //void setInvalid(Edge &) const {};
alpar@163
   159
  
alpar@163
   160
    Node addNode() { return INVALID;}
alpar@163
   161
    Edge addEdge(Node tail, Node head) { return INVALID;}
alpar@163
   162
    
alpar@163
   163
    void erase(Node n) {}
alpar@163
   164
    void erase(Edge e) {}
alpar@163
   165
alpar@163
   166
    void clear() {}
alpar@163
   167
alpar@163
   168
    int nodeNum() { return 0;}
alpar@163
   169
    int edgeNum() { return 0;}
alpar@163
   170
alpar@163
   171
    EmptyGraph() {};
alpar@163
   172
    EmptyGraph(const EmptyGraph &G) {};
alpar@163
   173
  
alpar@163
   174
  
alpar@163
   175
alpar@163
   176
    ///Read/write map from the nodes to type \c T.
alpar@163
   177
    template<class T> class NodeMap
alpar@163
   178
    {
alpar@163
   179
    public:
alpar@163
   180
      typedef T ValueType;
alpar@163
   181
      typedef Node KeyType;
alpar@163
   182
alpar@163
   183
      NodeMap(const EmptyGraph &G) {}
alpar@163
   184
      NodeMap(const EmptyGraph &G, T t) {}
alpar@163
   185
alpar@163
   186
      void set(Node i, T t) {}
alpar@163
   187
      T get(Node i) const {return *(T*)NULL;}  //FIXME: Is it necessary
alpar@163
   188
      T &operator[](Node i) {return *(T*)NULL;}
alpar@163
   189
      const T &operator[](Node i) const {return *(T*)NULL;}
alpar@163
   190
alpar@163
   191
      void update() {}
alpar@163
   192
      void update(T a) {}   //FIXME: Is it necessary
alpar@163
   193
    };
alpar@163
   194
alpar@163
   195
    ///Read/write map from the edges to type \c T.
alpar@163
   196
    template<class T> class EdgeMap
alpar@163
   197
    {
alpar@163
   198
    public:
alpar@163
   199
      typedef T ValueType;
alpar@163
   200
      typedef Edge KeyType;
alpar@163
   201
alpar@163
   202
      EdgeMap(const EmptyGraph &G) {}
alpar@163
   203
      EdgeMap(const EmptyGraph &G, T t) {}
alpar@163
   204
    
alpar@163
   205
      void set(Edge i, T t) {}
alpar@163
   206
      T get(Edge i) const {return *(T*)NULL;}
alpar@163
   207
      T &operator[](Edge i) {return *(T*)NULL;}
alpar@163
   208
    
alpar@163
   209
      void update() {}
alpar@163
   210
      void update(T a) {}   //FIXME: Is it necessary
alpar@163
   211
    };
alpar@147
   212
  };
alpar@52
   213
alpar@163
   214
  // @}
alpar@147
   215
alpar@163
   216
};
alpar@52
   217
alpar@145
   218
alpar@145
   219
alpar@147
   220
// class EmptyBipGraph : public EmptyGraph
alpar@147
   221
// {
alpar@163
   222
//   class ANode {};
alpar@163
   223
//   class BNode {};
alpar@145
   224
alpar@163
   225
//   ANode &next(ANode &) {}
alpar@163
   226
//   BNode &next(BNode &) {}
alpar@145
   227
alpar@163
   228
//   ANode &getFirst(ANode &) const {}
alpar@163
   229
//   BNode &getFirst(BNode &) const {}
alpar@145
   230
alpar@147
   231
//   enum NodeClass { A = 0, B = 1 };
alpar@163
   232
//   NodeClass getClass(Node n) {}
alpar@147
   233
alpar@147
   234
// }