deba@378: #ifndef MAP_REGISTRY_H deba@378: #define MAP_REGISTRY_H deba@378: deba@378: #include deba@378: deba@378: deba@378: namespace hugo { deba@378: template deba@378: class MapRegistry; deba@378: } deba@378: deba@378: #include "map_base.h" deba@378: deba@378: namespace hugo { deba@378: deba@378: template deba@378: class MapRegistry { deba@378: public: deba@378: typedef G Graph; deba@378: typedef K Key; deba@378: typedef KIt KeyIt; deba@378: deba@378: typedef MapBase Map; deba@378: friend class Base; deba@378: deba@378: protected: deba@378: deba@378: typedef std::vector Container; deba@378: Container container; deba@378: deba@378: deba@378: public: deba@378: deba@571: MapRegistry() {} deba@571: deba@571: MapRegistry(const MapRegistry&) {} deba@571: deba@571: MapRegistry& operator=(const MapRegistry&) { deba@571: for (it = container.begin(); it != container.end(); ++it) { deba@571: (*it)->destroy(); deba@571: (*it)->graph = 0; deba@571: (*it)->registry = 0; deba@571: } deba@571: } deba@378: deba@378: ~MapRegistry() { deba@378: typename Container::iterator it; deba@378: for (it = container.begin(); it != container.end(); ++it) { deba@571: (*it)->destroy(); deba@378: (*it)->registry = 0; deba@571: (*it)->graph = 0; deba@378: } deba@378: } deba@378: deba@378: deba@378: public: deba@378: deba@571: void attach(Map& map) { deba@378: if (map.registry) { deba@571: map.registry->detach(map); deba@378: } deba@378: container.push_back(&map); deba@378: map.registry = this; deba@378: map.registry_index = container.size()-1; deba@571: map.init(); deba@378: } deba@378: deba@571: void detach(Map& map_base) { deba@571: map_base.destroy(); deba@378: container.back()->registry_index = map_base.registry_index; deba@378: container[map_base.registry_index] = container.back(); deba@378: container.pop_back(); deba@378: map_base.registry = 0; deba@571: map_base.graph = 0; deba@378: } deba@378: deba@378: deba@378: void add(Key& key) { deba@378: typename Container::iterator it; deba@378: for (it = container.begin(); it != container.end(); ++it) { deba@378: (*it)->add(key); deba@378: } deba@378: } deba@378: deba@378: void erase(Key& key) { deba@378: typename Container::iterator it; deba@378: for (it = container.begin(); it != container.end(); ++it) { deba@378: (*it)->erase(key); deba@378: } deba@378: } deba@378: deba@378: }; deba@378: deba@378: } deba@378: deba@378: #endif