lemon/bits/erasable_graph_extender.h
author alpar
Mon, 29 Aug 2005 18:21:02 +0000
changeset 1663 f6741cfab647
parent 1435 8e85e6bbefdf
child 1842 8abf74160dc4
permissions -rw-r--r--
Serious bugfix.
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> 
klao@1022
    49
  class ErasableUndirGraphExtender : public _Base {
klao@1022
    50
  public:
klao@1022
    51
klao@1022
    52
    typedef ErasableUndirGraphExtender Graph;
klao@1022
    53
    typedef _Base Parent;
klao@1022
    54
klao@1022
    55
    typedef typename Parent::Node Node;
klao@1022
    56
    typedef typename Parent::UndirEdge UndirEdge;
klao@1022
    57
    typedef typename Parent::Edge Edge;
klao@1022
    58
klao@1022
    59
    void erase(const Node& node) {
klao@1022
    60
      Edge edge;
klao@1022
    61
      Parent::firstOut(edge, node);
klao@1022
    62
      while (edge != INVALID ) {
klao@1022
    63
	erase(edge);
klao@1022
    64
	Parent::firstOut(edge, node);
klao@1022
    65
      } 
klao@1022
    66
deba@1039
    67
      Parent::getNotifier(Node()).erase(node);
klao@1022
    68
      Parent::erase(node);
klao@1022
    69
    }
klao@1022
    70
    
klao@1022
    71
    void erase(const UndirEdge& uedge) {
deba@1414
    72
      std::vector<Edge> edges;
deba@1627
    73
      edges.push_back(Parent::direct(uedge,true));
deba@1627
    74
      edges.push_back(Parent::direct(uedge,false));
deba@1414
    75
      Parent::getNotifier(Edge()).erase(edges);
deba@1039
    76
      Parent::getNotifier(UndirEdge()).erase(uedge);
klao@1022
    77
      Parent::erase(uedge);
klao@1022
    78
    }
klao@1022
    79
klao@1022
    80
  };
klao@1022
    81
klao@946
    82
}
klao@946
    83
klao@946
    84
#endif