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