lemon/bits/erasable_graph_extender.h
author alpar
Mon, 20 Feb 2006 06:44:07 +0000
changeset 1974 191223f4b639
parent 1909 2d806130e700
permissions -rw-r--r--
Public data members of xy became documented
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
    20 #define LEMON_ERASABLE_GRAPH_EXTENDER_H
    21 
    22 #include <vector>
    23 
    24 #include <lemon/invalid.h>
    25 
    26 
    27 namespace lemon {
    28 
    29   template <typename _Base> 
    30   class ErasableGraphExtender : public _Base {
    31   public:
    32 
    33     typedef ErasableGraphExtender Graph;
    34     typedef _Base Parent;
    35 
    36     typedef typename Parent::Node Node;
    37     typedef typename Parent::Edge Edge;
    38 
    39     void erase(const Node& node) {
    40       Edge edge;
    41       Parent::firstOut(edge, node);
    42       while (edge != INVALID ) {
    43 	erase(edge);
    44 	Parent::firstOut(edge, node);
    45       } 
    46 
    47       Parent::firstIn(edge, node);
    48       while (edge != INVALID ) {
    49 	erase(edge);
    50 	Parent::firstIn(edge, node);
    51       }
    52 
    53       Parent::getNotifier(Node()).erase(node);
    54       Parent::erase(node);
    55     }
    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 ErasableEdgeSetExtender : public _Base {
    66   public:
    67 
    68     typedef ErasableEdgeSetExtender Graph;
    69     typedef _Base Parent;
    70 
    71     typedef typename Parent::Edge Edge;
    72 
    73     void erase(const Edge& edge) {
    74       Parent::getNotifier(Edge()).erase(edge);
    75       Parent::erase(edge);
    76     }
    77 
    78   };
    79 
    80   template <typename _Base> 
    81   class ErasableUGraphExtender : public _Base {
    82   public:
    83 
    84     typedef ErasableUGraphExtender Graph;
    85     typedef _Base Parent;
    86 
    87     typedef typename Parent::Node Node;
    88     typedef typename Parent::UEdge UEdge;
    89     typedef typename Parent::Edge Edge;
    90 
    91     void erase(const Node& node) {
    92       Edge edge;
    93       Parent::firstOut(edge, node);
    94       while (edge != INVALID ) {
    95 	erase(edge);
    96 	Parent::firstOut(edge, node);
    97       } 
    98 
    99       Parent::getNotifier(Node()).erase(node);
   100       Parent::erase(node);
   101     }
   102     
   103     void erase(const UEdge& uedge) {
   104       std::vector<Edge> edges;
   105       edges.push_back(Parent::direct(uedge,true));
   106       edges.push_back(Parent::direct(uedge,false));
   107       Parent::getNotifier(Edge()).erase(edges);
   108       Parent::getNotifier(UEdge()).erase(uedge);
   109       Parent::erase(uedge);
   110     }
   111 
   112   };
   113 
   114   template <typename _Base> 
   115   class ErasableUEdgeSetExtender : public _Base {
   116   public:
   117 
   118     typedef ErasableUEdgeSetExtender Graph;
   119     typedef _Base Parent;
   120 
   121     typedef typename Parent::Node Node;
   122     typedef typename Parent::UEdge UEdge;
   123     typedef typename Parent::Edge Edge;
   124 
   125     void erase(const UEdge& uedge) {
   126       std::vector<Edge> edges;
   127       edges.push_back(Parent::direct(uedge,true));
   128       edges.push_back(Parent::direct(uedge,false));
   129       Parent::getNotifier(Edge()).erase(edges);
   130       Parent::getNotifier(UEdge()).erase(uedge);
   131       Parent::erase(uedge);
   132     }
   133 
   134   };
   135 
   136 }
   137 
   138 #endif