1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/deba/map_registry.h Thu Apr 22 20:36:21 2004 +0000
1.3 @@ -0,0 +1,94 @@
1.4 +#ifndef MAP_REGISTRY_H
1.5 +#define MAP_REGISTRY_H
1.6 +
1.7 +#include <vector>
1.8 +
1.9 +
1.10 +namespace hugo {
1.11 + template <typename G, typename K, typename KIt>
1.12 + class MapRegistry;
1.13 +}
1.14 +
1.15 +#include "map_base.h"
1.16 +
1.17 +namespace hugo {
1.18 +
1.19 + template <typename G, typename K, typename KIt>
1.20 + class MapRegistry {
1.21 + public:
1.22 + typedef G Graph;
1.23 + typedef K Key;
1.24 + typedef KIt KeyIt;
1.25 +
1.26 + typedef MapBase<Graph, Key, KIt> Map;
1.27 + friend class Base;
1.28 +
1.29 + protected:
1.30 +
1.31 + typedef std::vector<Map*> Container;
1.32 + Container container;
1.33 +
1.34 + Graph* graph;
1.35 +
1.36 +
1.37 + public:
1.38 +
1.39 + MapRegistry(Graph& g) : container(0), graph(&g) {}
1.40 +
1.41 + ~MapRegistry() {
1.42 + typename Container::iterator it;
1.43 + for (it = container.begin(); it != container.end(); ++it) {
1.44 + (*it)->destroy(*graph);
1.45 + (*it)->registry = 0;
1.46 + }
1.47 + }
1.48 +
1.49 + private:
1.50 + MapRegistry(const MapRegistry& ) {}
1.51 + MapRegistry& operator=(const MapRegistry& ) {}
1.52 +
1.53 + public:
1.54 +
1.55 + void add(Map& map) {
1.56 + if (map.registry) {
1.57 + map.registry->erase(map);
1.58 + }
1.59 + container.push_back(&map);
1.60 + map.registry = this;
1.61 + map.registry_index = container.size()-1;
1.62 + map.init(*graph);
1.63 + }
1.64 +
1.65 + void erase(Map& map_base) {
1.66 + map_base.destroy(*graph);
1.67 + container.back()->registry_index = map_base.registry_index;
1.68 + container[map_base.registry_index] = container.back();
1.69 + container.pop_back();
1.70 + map_base.registry = 0;
1.71 + }
1.72 +
1.73 +
1.74 + void add(Key& key) {
1.75 + typename Container::iterator it;
1.76 + for (it = container.begin(); it != container.end(); ++it) {
1.77 + (*it)->add(key);
1.78 + }
1.79 + }
1.80 +
1.81 + void erase(Key& key) {
1.82 + typename Container::iterator it;
1.83 + for (it = container.begin(); it != container.end(); ++it) {
1.84 + (*it)->erase(key);
1.85 + }
1.86 + }
1.87 +
1.88 + Graph& getGraph() {
1.89 + return *graph;
1.90 + }
1.91 +
1.92 +
1.93 + };
1.94 +
1.95 +}
1.96 +
1.97 +#endif