deba@571: #ifndef VECTOR_MAP_H deba@571: #define VECTOR_MAP_H deba@571: deba@571: #include deba@571: deba@571: namespace hugo { deba@571: deba@627: template deba@698: class VectorMapFactory { deba@698: public: deba@627: deba@627: typedef typename MapRegistry::Graph Graph; deba@627: typedef typename MapRegistry::Key Key; deba@627: typedef typename MapRegistry::KeyIt KeyIt; deba@627: deba@627: typedef typename MapRegistry::MapBase MapBase; deba@698: deba@627: deba@627: template deba@627: class Map : public MapBase { deba@627: public: deba@627: typedef V Value; deba@571: deba@698: typedef std::vector Container; deba@627: Map() {} deba@627: deba@627: Map(Graph& g, MapRegistry& r) : MapBase(g, r) { deba@627: init(); deba@627: } deba@627: deba@627: deba@627: virtual ~Map() { deba@627: destroy(); deba@627: } deba@571: deba@627: deba@698: typename Container::reference operator[](const Key& key) { deba@627: int id = graph->id(key); deba@627: return container[id]; deba@627: } deba@571: deba@698: typename Container::const_reference operator[](const Key& key) const { deba@627: int id = graph->id(key); deba@627: return container[id]; deba@627: } deba@627: deba@627: void set(const Key& key, const Value& val) { deba@627: int id = graph->id(key); deba@627: container[id] = val; deba@627: } deba@627: deba@627: void add(const Key& key) { deba@627: int id = graph->id(key); deba@627: if (id >= container.size()) { deba@627: container.resize(id + 1); deba@627: } deba@627: } deba@627: deba@627: void erase(const Key& key) {} deba@571: deba@698: class const_iterator { deba@698: deba@698: private: deba@698: deba@698: }; deba@698: deba@698: class iterator { deba@698: public: deba@698: iterator() {} deba@698: deba@698: std::pair operator*() { deba@698: return std::pair(static_cast(it), map[it]); deba@698: } deba@698: deba@698: iterator& operator++() { ++it; return *this; } deba@698: iterator operator++(int) { iterator tmp(it); ++it; return tmp; } deba@698: private: deba@698: Map& map; deba@698: KeyIt it; deba@698: }; deba@698: deba@627: private: deba@627: typedef std::vector Container; deba@571: deba@627: Container container; deba@698: deba@698: deba@627: }; deba@698: deba@698: deba@698: deba@571: deba@627: }; deba@571: } deba@571: deba@571: #endif