src/work/deba/edge_map_register.h
author marci
Thu, 15 Apr 2004 14:41:20 +0000
changeset 330 7ac0d4e8a31c
permissions -rw-r--r--
In the resgraphwrapper interface, and in the constructor,
the order of FlowMap and CapacityMap is changed.
     1 #ifndef EDGE_MAP_REGISTER_H
     2 #define EDGE_MAP_REGISTER_H
     3 
     4 #include <vector>
     5 
     6 template <typename G, typename E>
     7 class EdgeMapRegister {
     8 public:
     9 	typedef G Graph;
    10 	typedef E Edge
    11 	
    12 	typedef EdgeMapBase<Graph, Edge> EdgeMapBase;
    13 
    14 protected:
    15 	typedef std::vector<EdgeMapBase*> Container; 
    16 	
    17 	Container container;
    18 	
    19 	void add(EdgeMapBase& map_base) {
    20 		if (map_base.graph) {
    21 			map_base.graph->edge_maps.erase(map_base);
    22 		}
    23 		container.push_back(&map_base);
    24 		map_base.graph_index = container.size()-1;
    25 	} 
    26 	
    27 	void erase(EdgeMapBase& map_base) {
    28 		if (map_base.graph != this) return;
    29 		container.back()->graph_index = map_base.graph_index; 
    30 		container[map_base.graph_index] = container.back();
    31 		container.pop_back();
    32 		map_base.graph = 0;
    33 	}
    34 	
    35 	void addEdge(Edge& edge) {
    36 		typename Container::iterator it;
    37 		for (it = container.begin(); it != container.end(); ++it) {
    38 			(*it)->add(edge);
    39 		}
    40 	}
    41 	
    42 	void eraseEdge(Edge& edge) {
    43 		typename Container::iterator it;
    44 		for (it = container.begin(); it != container.end(); ++it) {
    45 			(*it)->erase(edge);
    46 		}
    47 	}
    48 
    49 	friend class EdgeMapBase;
    50 };
    51 
    52 #endif