lemon/bits/extendable_graph_extender.h
author alpar
Thu, 26 Jan 2006 06:44:22 +0000
changeset 1908 e225719bde6b
parent 1820 22099ef840d7
child 1909 2d806130e700
permissions -rw-r--r--
Better doc.
klao@946
     1
// -*- c++ -*-
klao@946
     2
klao@946
     3
#ifndef LEMON_EXTENDABLE_GRAPH_EXTENDER_H
klao@946
     4
#define LEMON_EXTENDABLE_GRAPH_EXTENDER_H
klao@946
     5
klao@946
     6
namespace lemon {
klao@946
     7
klao@946
     8
  template <typename _Base> 
klao@946
     9
  class ExtendableGraphExtender : public _Base {
klao@946
    10
  public:
klao@946
    11
klao@946
    12
    typedef ExtendableGraphExtender Graph;
klao@946
    13
    typedef _Base Parent;
klao@946
    14
klao@946
    15
    typedef typename Parent::Node Node;
klao@946
    16
    typedef typename Parent::Edge Edge;
klao@946
    17
klao@946
    18
    Node addNode() {
klao@946
    19
      Node node = Parent::addNode();
deba@1039
    20
      Parent::getNotifier(Node()).add(node);
klao@946
    21
      return node;
klao@946
    22
    }
klao@946
    23
    
klao@946
    24
    Edge addEdge(const Node& from, const Node& to) {
klao@946
    25
      Edge edge = Parent::addEdge(from, to);
deba@1039
    26
      Parent::getNotifier(Edge()).add(edge);
klao@946
    27
      return edge;
klao@946
    28
    }
klao@946
    29
klao@946
    30
  };
klao@946
    31
klao@1022
    32
  template <typename _Base> 
deba@1842
    33
  class ExtendableEdgeSetExtender : public _Base {
deba@1842
    34
  public:
deba@1842
    35
deba@1842
    36
    typedef ExtendableEdgeSetExtender Graph;
deba@1842
    37
    typedef _Base Parent;
deba@1842
    38
deba@1842
    39
    typedef typename Parent::Edge Edge;
deba@1842
    40
    typedef typename Parent::Node Node;
deba@1842
    41
deba@1842
    42
    Edge addEdge(const Node& from, const Node& to) {
deba@1842
    43
      Edge edge = Parent::addEdge(from, to);
deba@1842
    44
      Parent::getNotifier(Edge()).add(edge);
deba@1842
    45
      return edge;
deba@1842
    46
    }
deba@1842
    47
deba@1842
    48
  };
deba@1842
    49
deba@1842
    50
  template <typename _Base> 
klao@1022
    51
  class ExtendableUndirGraphExtender : public _Base {
klao@1022
    52
  public:
klao@1022
    53
klao@1022
    54
    typedef ExtendableUndirGraphExtender Graph;
klao@1022
    55
    typedef _Base Parent;
klao@1022
    56
klao@1022
    57
    typedef typename Parent::Node Node;
klao@1022
    58
    typedef typename Parent::Edge Edge;
klao@1022
    59
    typedef typename Parent::UndirEdge UndirEdge;
klao@1022
    60
klao@1022
    61
    Node addNode() {
klao@1022
    62
      Node node = Parent::addNode();
deba@1039
    63
      Parent::getNotifier(Node()).add(node);
klao@1022
    64
      return node;
klao@1022
    65
    }
klao@1022
    66
klao@1022
    67
    UndirEdge addEdge(const Node& from, const Node& to) {
klao@1022
    68
      UndirEdge uedge = Parent::addEdge(from, to);
deba@1039
    69
      Parent::getNotifier(UndirEdge()).add(uedge);
klao@1022
    70
deba@1414
    71
      std::vector<Edge> edges;
deba@1627
    72
      edges.push_back(Parent::direct(uedge, true));
deba@1627
    73
      edges.push_back(Parent::direct(uedge, false));
deba@1414
    74
      Parent::getNotifier(Edge()).add(edges);
klao@1022
    75
klao@1022
    76
      return uedge;
klao@1022
    77
    }
klao@1022
    78
klao@1022
    79
  };
klao@1022
    80
deba@1842
    81
  template <typename _Base> 
deba@1842
    82
  class ExtendableUndirEdgeSetExtender : public _Base {
deba@1842
    83
  public:
deba@1842
    84
deba@1842
    85
    typedef ExtendableUndirEdgeSetExtender Graph;
deba@1842
    86
    typedef _Base Parent;
deba@1842
    87
deba@1842
    88
    typedef typename Parent::Node Node;
deba@1842
    89
    typedef typename Parent::Edge Edge;
deba@1842
    90
    typedef typename Parent::UndirEdge UndirEdge;
deba@1842
    91
deba@1842
    92
    UndirEdge addEdge(const Node& from, const Node& to) {
deba@1842
    93
      UndirEdge uedge = Parent::addEdge(from, to);
deba@1842
    94
      Parent::getNotifier(UndirEdge()).add(uedge);
deba@1842
    95
deba@1842
    96
      std::vector<Edge> edges;
deba@1842
    97
      edges.push_back(Parent::direct(uedge, true));
deba@1842
    98
      edges.push_back(Parent::direct(uedge, false));
deba@1842
    99
      Parent::getNotifier(Edge()).add(edges);
deba@1842
   100
deba@1842
   101
      return uedge;
deba@1842
   102
    }
deba@1842
   103
deba@1842
   104
  };
deba@1842
   105
deba@1820
   106
deba@1820
   107
  template <typename _Base>
deba@1820
   108
  class ExtendableUndirBipartiteGraphExtender : public _Base {
deba@1820
   109
  public:
deba@1820
   110
deba@1820
   111
    typedef _Base Parent;
deba@1820
   112
    typedef ExtendableUndirBipartiteGraphExtender Graph;
deba@1820
   113
  
deba@1820
   114
    typedef typename Parent::Node Node;
deba@1820
   115
    typedef typename Parent::LowerNode LowerNode;
deba@1820
   116
    typedef typename Parent::UpperNode UpperNode;
deba@1820
   117
    typedef typename Parent::Edge Edge;
deba@1820
   118
    typedef typename Parent::UndirEdge UndirEdge;
deba@1820
   119
  
deba@1820
   120
    Node addUpperNode() {
deba@1820
   121
      Node node = Parent::addUpperNode();
deba@1820
   122
      Parent::getNotifier(UpperNode()).add(node);
deba@1820
   123
      Parent::getNotifier(Node()).add(node);
deba@1820
   124
      return node;
deba@1820
   125
    }
deba@1820
   126
deba@1820
   127
    Node addLowerNode() {
deba@1820
   128
      Node node = Parent::addLowerNode();
deba@1820
   129
      Parent::getNotifier(LowerNode()).add(node);
deba@1820
   130
      Parent::getNotifier(Node()).add(node);
deba@1820
   131
      return node;
deba@1820
   132
    }
deba@1820
   133
  
deba@1820
   134
    UndirEdge addEdge(const Node& source, const Node& target) {
deba@1820
   135
      UndirEdge undiredge = Parent::addEdge(source, target);
deba@1820
   136
      Parent::getNotifier(UndirEdge()).add(undiredge);
deba@1820
   137
    
deba@1820
   138
      std::vector<Edge> edges;
deba@1820
   139
      edges.push_back(Parent::direct(undiredge, true));
deba@1820
   140
      edges.push_back(Parent::direct(undiredge, false));
deba@1820
   141
      Parent::getNotifier(Edge()).add(edges);
deba@1820
   142
    
deba@1820
   143
      return undiredge;
deba@1820
   144
    }
deba@1820
   145
deba@1820
   146
  };
deba@1820
   147
klao@946
   148
}
klao@946
   149
klao@946
   150
#endif