Rev | Line | |
---|
[378] | 1 | #ifndef MAP_REGISTRY_H |
---|
| 2 | #define MAP_REGISTRY_H |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | namespace hugo { |
---|
| 8 | template <typename G, typename K, typename KIt> |
---|
| 9 | class MapRegistry; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | #include "map_base.h" |
---|
| 13 | |
---|
| 14 | namespace hugo { |
---|
| 15 | |
---|
| 16 | template <typename G, typename K, typename KIt> |
---|
| 17 | class MapRegistry { |
---|
| 18 | public: |
---|
| 19 | typedef G Graph; |
---|
| 20 | typedef K Key; |
---|
| 21 | typedef KIt KeyIt; |
---|
| 22 | |
---|
| 23 | typedef MapBase<Graph, Key, KIt> Map; |
---|
| 24 | friend class Base; |
---|
| 25 | |
---|
| 26 | protected: |
---|
| 27 | |
---|
| 28 | typedef std::vector<Map*> Container; |
---|
| 29 | Container container; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | public: |
---|
| 33 | |
---|
[571] | 34 | MapRegistry() {} |
---|
| 35 | |
---|
| 36 | MapRegistry(const MapRegistry&) {} |
---|
| 37 | |
---|
| 38 | MapRegistry& operator=(const MapRegistry&) { |
---|
| 39 | for (it = container.begin(); it != container.end(); ++it) { |
---|
| 40 | (*it)->destroy(); |
---|
| 41 | (*it)->graph = 0; |
---|
| 42 | (*it)->registry = 0; |
---|
| 43 | } |
---|
| 44 | } |
---|
[378] | 45 | |
---|
| 46 | ~MapRegistry() { |
---|
| 47 | typename Container::iterator it; |
---|
| 48 | for (it = container.begin(); it != container.end(); ++it) { |
---|
[571] | 49 | (*it)->destroy(); |
---|
[378] | 50 | (*it)->registry = 0; |
---|
[571] | 51 | (*it)->graph = 0; |
---|
[378] | 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | public: |
---|
| 57 | |
---|
[571] | 58 | void attach(Map& map) { |
---|
[378] | 59 | if (map.registry) { |
---|
[571] | 60 | map.registry->detach(map); |
---|
[378] | 61 | } |
---|
| 62 | container.push_back(&map); |
---|
| 63 | map.registry = this; |
---|
| 64 | map.registry_index = container.size()-1; |
---|
[571] | 65 | map.init(); |
---|
[378] | 66 | } |
---|
| 67 | |
---|
[571] | 68 | void detach(Map& map_base) { |
---|
| 69 | map_base.destroy(); |
---|
[378] | 70 | container.back()->registry_index = map_base.registry_index; |
---|
| 71 | container[map_base.registry_index] = container.back(); |
---|
| 72 | container.pop_back(); |
---|
| 73 | map_base.registry = 0; |
---|
[571] | 74 | map_base.graph = 0; |
---|
[378] | 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | void add(Key& key) { |
---|
| 79 | typename Container::iterator it; |
---|
| 80 | for (it = container.begin(); it != container.end(); ++it) { |
---|
| 81 | (*it)->add(key); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void erase(Key& key) { |
---|
| 86 | typename Container::iterator it; |
---|
| 87 | for (it = container.begin(); it != container.end(); ++it) { |
---|
| 88 | (*it)->erase(key); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.