author | jacint |
Wed, 05 May 2004 17:24:06 +0000 | |
changeset 535 | bd79aa43f299 |
child 571 | 9632ea8be6ca |
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 |
Graph* graph; |
deba@378 | 32 |
|
deba@378 | 33 |
|
deba@378 | 34 |
public: |
deba@378 | 35 |
|
deba@378 | 36 |
MapRegistry(Graph& g) : container(0), graph(&g) {} |
deba@378 | 37 |
|
deba@378 | 38 |
~MapRegistry() { |
deba@378 | 39 |
typename Container::iterator it; |
deba@378 | 40 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@378 | 41 |
(*it)->destroy(*graph); |
deba@378 | 42 |
(*it)->registry = 0; |
deba@378 | 43 |
} |
deba@378 | 44 |
} |
deba@378 | 45 |
|
deba@378 | 46 |
private: |
deba@378 | 47 |
MapRegistry(const MapRegistry& ) {} |
deba@378 | 48 |
MapRegistry& operator=(const MapRegistry& ) {} |
deba@378 | 49 |
|
deba@378 | 50 |
public: |
deba@378 | 51 |
|
deba@378 | 52 |
void add(Map& map) { |
deba@378 | 53 |
if (map.registry) { |
deba@378 | 54 |
map.registry->erase(map); |
deba@378 | 55 |
} |
deba@378 | 56 |
container.push_back(&map); |
deba@378 | 57 |
map.registry = this; |
deba@378 | 58 |
map.registry_index = container.size()-1; |
deba@378 | 59 |
map.init(*graph); |
deba@378 | 60 |
} |
deba@378 | 61 |
|
deba@378 | 62 |
void erase(Map& map_base) { |
deba@378 | 63 |
map_base.destroy(*graph); |
deba@378 | 64 |
container.back()->registry_index = map_base.registry_index; |
deba@378 | 65 |
container[map_base.registry_index] = container.back(); |
deba@378 | 66 |
container.pop_back(); |
deba@378 | 67 |
map_base.registry = 0; |
deba@378 | 68 |
} |
deba@378 | 69 |
|
deba@378 | 70 |
|
deba@378 | 71 |
void add(Key& key) { |
deba@378 | 72 |
typename Container::iterator it; |
deba@378 | 73 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@378 | 74 |
(*it)->add(key); |
deba@378 | 75 |
} |
deba@378 | 76 |
} |
deba@378 | 77 |
|
deba@378 | 78 |
void erase(Key& key) { |
deba@378 | 79 |
typename Container::iterator it; |
deba@378 | 80 |
for (it = container.begin(); it != container.end(); ++it) { |
deba@378 | 81 |
(*it)->erase(key); |
deba@378 | 82 |
} |
deba@378 | 83 |
} |
deba@378 | 84 |
|
deba@378 | 85 |
Graph& getGraph() { |
deba@378 | 86 |
return *graph; |
deba@378 | 87 |
} |
deba@378 | 88 |
|
deba@378 | 89 |
|
deba@378 | 90 |
}; |
deba@378 | 91 |
|
deba@378 | 92 |
} |
deba@378 | 93 |
|
deba@378 | 94 |
#endif |