author | marci |
Wed, 21 Apr 2004 14:59:43 +0000 | |
changeset 359 | 8cc53a6b1e61 |
parent 337 | 6e1b7efa577f |
child 377 | 33fe0ee01dc5 |
permissions | -rw-r--r-- |
deba@337 | 1 |
#ifndef EDGE_MAP_REGISTRY_H |
deba@337 | 2 |
#define EDGE_MAP_REGISTRY_H |
deba@337 | 3 |
|
deba@337 | 4 |
#include <vector> |
deba@337 | 5 |
|
deba@340 | 6 |
#include "edge_map_base.h" |
deba@340 | 7 |
|
deba@337 | 8 |
template <typename G, typename E> |
deba@337 | 9 |
class EdgeMapRegistry { |
deba@337 | 10 |
public: |
deba@337 | 11 |
typedef G Graph; |
deba@337 | 12 |
typedef E Edge |
deba@337 | 13 |
|
deba@340 | 14 |
typedef EdgeMapBase<Graph, Edge> MapBase; |
deba@337 | 15 |
|
deba@337 | 16 |
protected: |
deba@337 | 17 |
typedef std::vector<EdgeMapBase*> Container; |
deba@337 | 18 |
|
deba@337 | 19 |
Container container; |
deba@337 | 20 |
|
deba@340 | 21 |
void add(MapBase& map_base) { |
deba@337 | 22 |
if (map_base.graph) { |
deba@337 | 23 |
map_base.graph->edge_maps.erase(map_base); |
deba@337 | 24 |
} |
deba@337 | 25 |
container.push_back(&map_base); |
deba@337 | 26 |
map_base.graph = this; |
deba@337 | 27 |
map_base.graph_index = container.size()-1; |
deba@337 | 28 |
} |
deba@337 | 29 |
|
deba@340 | 30 |
void erase(MapBase& map_base) { |
deba@337 | 31 |
if (map_base.graph != this) return; |
deba@337 | 32 |
container.back()->graph_index = map_base.graph_index; |
deba@337 | 33 |
container[map_base.graph_index] = container.back(); |
deba@337 | 34 |
container.pop_back(); |
deba@337 | 35 |
map_base.graph = 0; |
deba@337 | 36 |
} |
deba@337 | 37 |
|
deba@340 | 38 |
void add(Edge& edge) { |
deba@337 | 39 |
typename Container::iterator it; |
deba@337 | 40 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@337 | 41 |
(*it)->add(edge); |
deba@337 | 42 |
} |
deba@337 | 43 |
} |
deba@337 | 44 |
|
deba@340 | 45 |
void erase(Edge& edge) { |
deba@337 | 46 |
typename Container::iterator it; |
deba@337 | 47 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@337 | 48 |
(*it)->erase(edge); |
deba@337 | 49 |
} |
deba@337 | 50 |
} |
deba@337 | 51 |
|
deba@340 | 52 |
friend class MapBase; |
deba@337 | 53 |
}; |
deba@337 | 54 |
|
deba@337 | 55 |
#endif |