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