erasable_graph_extender.h

00001 /* -*- C++ -*-
00002  *
00003  * This file is a part of LEMON, a generic C++ optimization library
00004  *
00005  * Copyright (C) 2003-2006
00006  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00007  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00008  *
00009  * Permission to use, modify and distribute this software is granted
00010  * provided that this copyright notice appears in all copies. For
00011  * precise terms see the accompanying LICENSE file.
00012  *
00013  * This software is provided "AS IS" with no warranty of any kind,
00014  * express or implied, and with no claim as to its suitability for any
00015  * purpose.
00016  *
00017  */
00018 
00019 #ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
00020 #define LEMON_ERASABLE_GRAPH_EXTENDER_H
00021 
00022 #include <vector>
00023 
00024 #include <lemon/invalid.h>
00025 
00026 
00027 namespace lemon {
00028 
00029   template <typename _Base> 
00030   class ErasableGraphExtender : public _Base {
00031   public:
00032 
00033     typedef ErasableGraphExtender Graph;
00034     typedef _Base Parent;
00035 
00036     typedef typename Parent::Node Node;
00037     typedef typename Parent::Edge Edge;
00038 
00039     void erase(const Node& node) {
00040       Edge edge;
00041       Parent::firstOut(edge, node);
00042       while (edge != INVALID ) {
00043         erase(edge);
00044         Parent::firstOut(edge, node);
00045       } 
00046 
00047       Parent::firstIn(edge, node);
00048       while (edge != INVALID ) {
00049         erase(edge);
00050         Parent::firstIn(edge, node);
00051       }
00052 
00053       Parent::getNotifier(Node()).erase(node);
00054       Parent::erase(node);
00055     }
00056     
00057     void erase(const Edge& edge) {
00058       Parent::getNotifier(Edge()).erase(edge);
00059       Parent::erase(edge);
00060     }
00061 
00062   };
00063 
00064   template <typename _Base> 
00065   class ErasableEdgeSetExtender : public _Base {
00066   public:
00067 
00068     typedef ErasableEdgeSetExtender Graph;
00069     typedef _Base Parent;
00070 
00071     typedef typename Parent::Edge Edge;
00072 
00073     void erase(const Edge& edge) {
00074       Parent::getNotifier(Edge()).erase(edge);
00075       Parent::erase(edge);
00076     }
00077 
00078   };
00079 
00080   template <typename _Base> 
00081   class ErasableUGraphExtender : public _Base {
00082   public:
00083 
00084     typedef ErasableUGraphExtender Graph;
00085     typedef _Base Parent;
00086 
00087     typedef typename Parent::Node Node;
00088     typedef typename Parent::UEdge UEdge;
00089     typedef typename Parent::Edge Edge;
00090 
00091     void erase(const Node& node) {
00092       Edge edge;
00093       Parent::firstOut(edge, node);
00094       while (edge != INVALID ) {
00095         erase(edge);
00096         Parent::firstOut(edge, node);
00097       } 
00098 
00099       Parent::getNotifier(Node()).erase(node);
00100       Parent::erase(node);
00101     }
00102     
00103     void erase(const UEdge& uedge) {
00104       std::vector<Edge> edges;
00105       edges.push_back(Parent::direct(uedge,true));
00106       edges.push_back(Parent::direct(uedge,false));
00107       Parent::getNotifier(Edge()).erase(edges);
00108       Parent::getNotifier(UEdge()).erase(uedge);
00109       Parent::erase(uedge);
00110     }
00111 
00112   };
00113 
00114   template <typename _Base> 
00115   class ErasableUEdgeSetExtender : public _Base {
00116   public:
00117 
00118     typedef ErasableUEdgeSetExtender Graph;
00119     typedef _Base Parent;
00120 
00121     typedef typename Parent::Node Node;
00122     typedef typename Parent::UEdge UEdge;
00123     typedef typename Parent::Edge Edge;
00124 
00125     void erase(const UEdge& uedge) {
00126       std::vector<Edge> edges;
00127       edges.push_back(Parent::direct(uedge,true));
00128       edges.push_back(Parent::direct(uedge,false));
00129       Parent::getNotifier(Edge()).erase(edges);
00130       Parent::getNotifier(UEdge()).erase(uedge);
00131       Parent::erase(uedge);
00132     }
00133 
00134   };
00135 
00136 }
00137 
00138 #endif

Generated on Fri Feb 3 18:35:46 2006 for LEMON by  doxygen 1.4.6