author | alpar |
Tue, 11 May 2004 19:38:00 +0000 | |
changeset 614 | 75cf1d52eee5 |
parent 571 | 9632ea8be6ca |
child 627 | 6cc21a9c9fda |
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@595 | 6 |
using namespace std; |
deba@595 | 7 |
|
deba@378 | 8 |
|
deba@378 | 9 |
namespace hugo { |
deba@378 | 10 |
template <typename G, typename K, typename KIt> |
deba@378 | 11 |
class MapRegistry; |
deba@378 | 12 |
} |
deba@378 | 13 |
|
deba@378 | 14 |
#include "map_base.h" |
deba@378 | 15 |
|
deba@378 | 16 |
namespace hugo { |
deba@378 | 17 |
|
deba@378 | 18 |
template <typename G, typename K, typename KIt> |
deba@378 | 19 |
class MapRegistry { |
deba@378 | 20 |
public: |
deba@378 | 21 |
typedef G Graph; |
deba@378 | 22 |
typedef K Key; |
deba@378 | 23 |
typedef KIt KeyIt; |
deba@378 | 24 |
|
deba@378 | 25 |
typedef MapBase<Graph, Key, KIt> Map; |
deba@378 | 26 |
friend class Base; |
deba@378 | 27 |
|
deba@378 | 28 |
protected: |
deba@378 | 29 |
|
deba@378 | 30 |
typedef std::vector<Map*> Container; |
deba@378 | 31 |
Container container; |
deba@378 | 32 |
|
deba@378 | 33 |
|
deba@378 | 34 |
public: |
deba@378 | 35 |
|
deba@571 | 36 |
MapRegistry() {} |
deba@571 | 37 |
|
deba@571 | 38 |
MapRegistry(const MapRegistry&) {} |
deba@571 | 39 |
|
deba@571 | 40 |
MapRegistry& operator=(const MapRegistry&) { |
deba@571 | 41 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@571 | 42 |
(*it)->destroy(); |
deba@571 | 43 |
(*it)->graph = 0; |
deba@571 | 44 |
(*it)->registry = 0; |
deba@571 | 45 |
} |
deba@571 | 46 |
} |
deba@378 | 47 |
|
deba@378 | 48 |
~MapRegistry() { |
deba@378 | 49 |
typename Container::iterator it; |
deba@378 | 50 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@571 | 51 |
(*it)->destroy(); |
deba@378 | 52 |
(*it)->registry = 0; |
deba@571 | 53 |
(*it)->graph = 0; |
deba@378 | 54 |
} |
deba@378 | 55 |
} |
deba@378 | 56 |
|
deba@378 | 57 |
|
deba@378 | 58 |
public: |
deba@378 | 59 |
|
deba@571 | 60 |
void attach(Map& map) { |
deba@378 | 61 |
if (map.registry) { |
deba@571 | 62 |
map.registry->detach(map); |
deba@378 | 63 |
} |
deba@378 | 64 |
container.push_back(&map); |
deba@378 | 65 |
map.registry = this; |
deba@378 | 66 |
map.registry_index = container.size()-1; |
deba@378 | 67 |
} |
deba@378 | 68 |
|
deba@595 | 69 |
void detach(Map& map) { |
deba@595 | 70 |
container.back()->registry_index = map.registry_index; |
deba@595 | 71 |
container[map.registry_index] = container.back(); |
deba@378 | 72 |
container.pop_back(); |
deba@595 | 73 |
map.registry = 0; |
deba@595 | 74 |
map.graph = 0; |
deba@378 | 75 |
} |
deba@378 | 76 |
|
deba@378 | 77 |
|
deba@595 | 78 |
virtual 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@595 | 85 |
virtual 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 |