src/work/deba/edge_map_register.h
author alpar
Sat, 17 Apr 2004 13:15:53 +0000
changeset 348 b63ea19e502e
permissions -rw-r--r--
A bool Edge Map with iterators that goes through the true or the false edges.
deba@262
     1
#ifndef EDGE_MAP_REGISTER_H
deba@262
     2
#define EDGE_MAP_REGISTER_H
deba@262
     3
deba@262
     4
#include <vector>
deba@262
     5
deba@262
     6
template <typename G, typename E>
deba@262
     7
class EdgeMapRegister {
deba@262
     8
public:
deba@262
     9
	typedef G Graph;
deba@262
    10
	typedef E Edge
deba@262
    11
	
deba@262
    12
	typedef EdgeMapBase<Graph, Edge> EdgeMapBase;
deba@262
    13
deba@262
    14
protected:
deba@262
    15
	typedef std::vector<EdgeMapBase*> Container; 
deba@262
    16
	
deba@262
    17
	Container container;
deba@262
    18
	
deba@262
    19
	void add(EdgeMapBase& map_base) {
deba@262
    20
		if (map_base.graph) {
deba@262
    21
			map_base.graph->edge_maps.erase(map_base);
deba@262
    22
		}
deba@262
    23
		container.push_back(&map_base);
deba@262
    24
		map_base.graph_index = container.size()-1;
deba@262
    25
	} 
deba@262
    26
	
deba@262
    27
	void erase(EdgeMapBase& map_base) {
deba@262
    28
		if (map_base.graph != this) return;
deba@262
    29
		container.back()->graph_index = map_base.graph_index; 
deba@262
    30
		container[map_base.graph_index] = container.back();
deba@262
    31
		container.pop_back();
deba@262
    32
		map_base.graph = 0;
deba@262
    33
	}
deba@262
    34
	
deba@262
    35
	void addEdge(Edge& edge) {
deba@262
    36
		typename Container::iterator it;
deba@262
    37
		for (it = container.begin(); it != container.end(); ++it) {
deba@262
    38
			(*it)->add(edge);
deba@262
    39
		}
deba@262
    40
	}
deba@262
    41
	
deba@262
    42
	void eraseEdge(Edge& edge) {
deba@262
    43
		typename Container::iterator it;
deba@262
    44
		for (it = container.begin(); it != container.end(); ++it) {
deba@262
    45
			(*it)->erase(edge);
deba@262
    46
		}
deba@262
    47
	}
deba@262
    48
deba@262
    49
	friend class EdgeMapBase;
deba@262
    50
};
deba@262
    51
deba@262
    52
#endif