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