Line | |
---|
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 | |
---|
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 | } |
---|
45 | |
---|
46 | ~MapRegistry() { |
---|
47 | typename Container::iterator it; |
---|
48 | for (it = container.begin(); it != container.end(); ++it) { |
---|
49 | (*it)->destroy(); |
---|
50 | (*it)->registry = 0; |
---|
51 | (*it)->graph = 0; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | public: |
---|
57 | |
---|
58 | void attach(Map& map) { |
---|
59 | if (map.registry) { |
---|
60 | map.registry->detach(map); |
---|
61 | } |
---|
62 | container.push_back(&map); |
---|
63 | map.registry = this; |
---|
64 | map.registry_index = container.size()-1; |
---|
65 | map.init(); |
---|
66 | } |
---|
67 | |
---|
68 | void detach(Map& map_base) { |
---|
69 | map_base.destroy(); |
---|
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; |
---|
74 | map_base.graph = 0; |
---|
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.