lemon/bits/erasable_graph_extender.h
author hegyi
Wed, 04 Jan 2006 11:41:58 +0000
changeset 1872 3b7694cf0a08
parent 1627 3fd1ba6e9872
child 1909 2d806130e700
permissions -rw-r--r--
Best feature ever\! Name of tabs are different from now on\!
klao@946
     1
// -*- c++ -*-
klao@946
     2
klao@946
     3
#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
klao@946
     4
#define LEMON_ERASABLE_GRAPH_EXTENDER_H
klao@946
     5
deba@1414
     6
#include <vector>
deba@1414
     7
klao@946
     8
#include <lemon/invalid.h>
klao@946
     9
klao@946
    10
klao@946
    11
namespace lemon {
klao@946
    12
klao@946
    13
  template <typename _Base> 
klao@946
    14
  class ErasableGraphExtender : public _Base {
klao@946
    15
  public:
klao@946
    16
klao@946
    17
    typedef ErasableGraphExtender Graph;
klao@946
    18
    typedef _Base Parent;
klao@946
    19
klao@946
    20
    typedef typename Parent::Node Node;
klao@946
    21
    typedef typename Parent::Edge Edge;
klao@946
    22
klao@946
    23
    void erase(const Node& node) {
klao@946
    24
      Edge edge;
klao@946
    25
      Parent::firstOut(edge, node);
klao@946
    26
      while (edge != INVALID ) {
klao@946
    27
	erase(edge);
klao@946
    28
	Parent::firstOut(edge, node);
klao@946
    29
      } 
klao@946
    30
klao@946
    31
      Parent::firstIn(edge, node);
klao@946
    32
      while (edge != INVALID ) {
klao@946
    33
	erase(edge);
klao@946
    34
	Parent::firstIn(edge, node);
klao@946
    35
      }
klao@946
    36
deba@1039
    37
      Parent::getNotifier(Node()).erase(node);
klao@946
    38
      Parent::erase(node);
klao@946
    39
    }
klao@946
    40
    
klao@946
    41
    void erase(const Edge& edge) {
deba@1039
    42
      Parent::getNotifier(Edge()).erase(edge);
klao@946
    43
      Parent::erase(edge);
klao@946
    44
    }
klao@946
    45
klao@946
    46
  };
klao@946
    47
klao@1022
    48
  template <typename _Base> 
deba@1842
    49
  class ErasableEdgeSetExtender : public _Base {
deba@1842
    50
  public:
deba@1842
    51
deba@1842
    52
    typedef ErasableEdgeSetExtender Graph;
deba@1842
    53
    typedef _Base Parent;
deba@1842
    54
deba@1842
    55
    typedef typename Parent::Edge Edge;
deba@1842
    56
deba@1842
    57
    void erase(const Edge& edge) {
deba@1842
    58
      Parent::getNotifier(Edge()).erase(edge);
deba@1842
    59
      Parent::erase(edge);
deba@1842
    60
    }
deba@1842
    61
deba@1842
    62
  };
deba@1842
    63
deba@1842
    64
  template <typename _Base> 
klao@1022
    65
  class ErasableUndirGraphExtender : public _Base {
klao@1022
    66
  public:
klao@1022
    67
klao@1022
    68
    typedef ErasableUndirGraphExtender Graph;
klao@1022
    69
    typedef _Base Parent;
klao@1022
    70
klao@1022
    71
    typedef typename Parent::Node Node;
klao@1022
    72
    typedef typename Parent::UndirEdge UndirEdge;
klao@1022
    73
    typedef typename Parent::Edge Edge;
klao@1022
    74
klao@1022
    75
    void erase(const Node& node) {
klao@1022
    76
      Edge edge;
klao@1022
    77
      Parent::firstOut(edge, node);
klao@1022
    78
      while (edge != INVALID ) {
klao@1022
    79
	erase(edge);
klao@1022
    80
	Parent::firstOut(edge, node);
klao@1022
    81
      } 
klao@1022
    82
deba@1039
    83
      Parent::getNotifier(Node()).erase(node);
klao@1022
    84
      Parent::erase(node);
klao@1022
    85
    }
klao@1022
    86
    
klao@1022
    87
    void erase(const UndirEdge& uedge) {
deba@1414
    88
      std::vector<Edge> edges;
deba@1627
    89
      edges.push_back(Parent::direct(uedge,true));
deba@1627
    90
      edges.push_back(Parent::direct(uedge,false));
deba@1414
    91
      Parent::getNotifier(Edge()).erase(edges);
deba@1039
    92
      Parent::getNotifier(UndirEdge()).erase(uedge);
klao@1022
    93
      Parent::erase(uedge);
klao@1022
    94
    }
klao@1022
    95
klao@1022
    96
  };
klao@1022
    97
deba@1842
    98
  template <typename _Base> 
deba@1842
    99
  class ErasableUndirEdgeSetExtender : public _Base {
deba@1842
   100
  public:
deba@1842
   101
deba@1842
   102
    typedef ErasableUndirEdgeSetExtender Graph;
deba@1842
   103
    typedef _Base Parent;
deba@1842
   104
deba@1842
   105
    typedef typename Parent::Node Node;
deba@1842
   106
    typedef typename Parent::UndirEdge UndirEdge;
deba@1842
   107
    typedef typename Parent::Edge Edge;
deba@1842
   108
deba@1842
   109
    void erase(const UndirEdge& uedge) {
deba@1842
   110
      std::vector<Edge> edges;
deba@1842
   111
      edges.push_back(Parent::direct(uedge,true));
deba@1842
   112
      edges.push_back(Parent::direct(uedge,false));
deba@1842
   113
      Parent::getNotifier(Edge()).erase(edges);
deba@1842
   114
      Parent::getNotifier(UndirEdge()).erase(uedge);
deba@1842
   115
      Parent::erase(uedge);
deba@1842
   116
    }
deba@1842
   117
deba@1842
   118
  };
deba@1842
   119
klao@946
   120
}
klao@946
   121
klao@946
   122
#endif