Rev | Line | |
---|
[337] | 1 | #ifndef EDGE_MAP_REGISTRY_H |
---|
| 2 | #define EDGE_MAP_REGISTRY_H |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
| 5 | |
---|
[377] | 6 | template <typename G, typename K> |
---|
| 7 | class EdgeMapRegistry; |
---|
| 8 | |
---|
[340] | 9 | #include "edge_map_base.h" |
---|
| 10 | |
---|
[377] | 11 | template <typename G, typename K> |
---|
[337] | 12 | class EdgeMapRegistry { |
---|
| 13 | public: |
---|
| 14 | typedef G Graph; |
---|
[377] | 15 | typedef K Edge; |
---|
[337] | 16 | |
---|
[340] | 17 | typedef EdgeMapBase<Graph, Edge> MapBase; |
---|
[377] | 18 | friend class MapBase; |
---|
[337] | 19 | |
---|
| 20 | protected: |
---|
[377] | 21 | |
---|
| 22 | Graph* graph; |
---|
| 23 | |
---|
| 24 | typedef std::vector<MapBase*> Container; |
---|
[337] | 25 | |
---|
| 26 | Container container; |
---|
[377] | 27 | |
---|
| 28 | public: |
---|
| 29 | |
---|
| 30 | EdgeMapRegistry(Graph g) : graph(&g) {} |
---|
| 31 | |
---|
[340] | 32 | void add(MapBase& map_base) { |
---|
[337] | 33 | if (map_base.graph) { |
---|
| 34 | map_base.graph->edge_maps.erase(map_base); |
---|
| 35 | } |
---|
| 36 | container.push_back(&map_base); |
---|
[377] | 37 | map_base.graph = graph; |
---|
[337] | 38 | map_base.graph_index = container.size()-1; |
---|
| 39 | } |
---|
| 40 | |
---|
[340] | 41 | void erase(MapBase& map_base) { |
---|
[337] | 42 | container.back()->graph_index = map_base.graph_index; |
---|
| 43 | container[map_base.graph_index] = container.back(); |
---|
| 44 | container.pop_back(); |
---|
| 45 | map_base.graph = 0; |
---|
| 46 | } |
---|
[377] | 47 | |
---|
[337] | 48 | |
---|
[340] | 49 | void add(Edge& edge) { |
---|
[337] | 50 | typename Container::iterator it; |
---|
| 51 | for (it = container.begin(); it != container.end(); ++it) { |
---|
| 52 | (*it)->add(edge); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
[340] | 56 | void erase(Edge& edge) { |
---|
[337] | 57 | typename Container::iterator it; |
---|
| 58 | for (it = container.begin(); it != container.end(); ++it) { |
---|
| 59 | (*it)->erase(edge); |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.