src/lemon/erasable_graph_extender.h
author alpar
Thu, 31 Mar 2005 14:04:13 +0000
changeset 1284 b941d044f87b
parent 1022 567f392d1d2e
permissions -rw-r--r--
SmartGraph can also split() a node!
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
klao@946
     6
#include <lemon/invalid.h>
klao@946
     7
klao@946
     8
klao@946
     9
namespace lemon {
klao@946
    10
klao@946
    11
  template <typename _Base> 
klao@946
    12
  class ErasableGraphExtender : public _Base {
klao@946
    13
  public:
klao@946
    14
klao@946
    15
    typedef ErasableGraphExtender Graph;
klao@946
    16
    typedef _Base Parent;
klao@946
    17
klao@946
    18
    typedef typename Parent::Node Node;
klao@946
    19
    typedef typename Parent::Edge Edge;
klao@946
    20
klao@946
    21
    void erase(const Node& node) {
klao@946
    22
      Edge edge;
klao@946
    23
      Parent::firstOut(edge, node);
klao@946
    24
      while (edge != INVALID ) {
klao@946
    25
	erase(edge);
klao@946
    26
	Parent::firstOut(edge, node);
klao@946
    27
      } 
klao@946
    28
klao@946
    29
      Parent::firstIn(edge, node);
klao@946
    30
      while (edge != INVALID ) {
klao@946
    31
	erase(edge);
klao@946
    32
	Parent::firstIn(edge, node);
klao@946
    33
      }
klao@946
    34
deba@1039
    35
      Parent::getNotifier(Node()).erase(node);
klao@946
    36
      Parent::erase(node);
klao@946
    37
    }
klao@946
    38
    
klao@946
    39
    void erase(const Edge& edge) {
deba@1039
    40
      Parent::getNotifier(Edge()).erase(edge);
klao@946
    41
      Parent::erase(edge);
klao@946
    42
    }
klao@946
    43
klao@946
    44
  };
klao@946
    45
klao@1022
    46
  template <typename _Base> 
klao@1022
    47
  class ErasableUndirGraphExtender : public _Base {
klao@1022
    48
  public:
klao@1022
    49
klao@1022
    50
    typedef ErasableUndirGraphExtender Graph;
klao@1022
    51
    typedef _Base Parent;
klao@1022
    52
klao@1022
    53
    typedef typename Parent::Node Node;
klao@1022
    54
    typedef typename Parent::UndirEdge UndirEdge;
klao@1022
    55
    typedef typename Parent::Edge Edge;
klao@1022
    56
klao@1022
    57
    void erase(const Node& node) {
klao@1022
    58
      Edge edge;
klao@1022
    59
      Parent::firstOut(edge, node);
klao@1022
    60
      while (edge != INVALID ) {
klao@1022
    61
	erase(edge);
klao@1022
    62
	Parent::firstOut(edge, node);
klao@1022
    63
      } 
klao@1022
    64
deba@1039
    65
      Parent::getNotifier(Node()).erase(node);
klao@1022
    66
      Parent::erase(node);
klao@1022
    67
    }
klao@1022
    68
    
klao@1022
    69
    void erase(const UndirEdge& uedge) {
deba@1039
    70
      Parent::getNotifier(Edge()).erase(Edge(uedge,true));
deba@1039
    71
      Parent::getNotifier(Edge()).erase(Edge(uedge,false));
deba@1039
    72
      Parent::getNotifier(UndirEdge()).erase(uedge);
klao@1022
    73
      Parent::erase(uedge);
klao@1022
    74
    }
klao@1022
    75
klao@1022
    76
  };
klao@1022
    77
klao@946
    78
}
klao@946
    79
klao@946
    80
#endif