diff -r 2f514b5c7122 -r 3eaff8d04171 src/work/deba/map_utils.h --- a/src/work/deba/map_utils.h Tue Dec 14 19:26:50 2004 +0000 +++ b/src/work/deba/map_utils.h Wed Dec 15 19:56:55 2004 +0000 @@ -35,19 +35,19 @@ /// in the inverse map. template < typename _Graph, - typename _Map, - template class _InvMap = std::Map + typename _Map > class InversableMap : protected _Map { public: + typedef _Graph Graph; - typename _Map Map; - typename _InvMap InverseMap; + typedef _Map Map; + typedef typename _Map::Key Key; + typedef typename _Map::Value Value; + typedef std::map InverseMap; - typename _Map::Key Key; - typename _Map::Value Value; - typename _Map::ConstReference ConstReference; + typedef typename _Map::ConstReference ConstReference; /// Constructor. @@ -60,11 +60,11 @@ /// It sets the map and the inverse map void set(const Key& key, const Value& val) { Value oldval = Map::operator[](key); - InverseMap::iterator it = invMap.find(oldval); - if (it != invMap.end() && it->second == key) { - invMap.erase(it); + typename InverseMap::iterator it = inv_map.find(oldval); + if (it != inv_map.end() && it->second == key) { + inv_map.erase(it); } - invMap.insert(make_pair(val, key)); + inv_map.insert(make_pair(val, key)); Map::set(key, val); } @@ -78,21 +78,89 @@ virtual void erase(const Key&) { Value val = Map::operator[](key); - InverseMap::iterator it = invMap.find(val); - if (it != invMap.end() && it->second == key) { + typename InverseMap::iterator it = inv_map.find(val); + if (it != inv_map.end() && it->second == key) { invMap.erase(it); } Map::erase(key); } const InverseMap& inverse() const { - return invMap; + return inv_map; } private: - InverseMap invMap; + InverseMap inv_map; }; + + // unique, continous, mutable + + template < + typename _Graph, + typename _Item, + typename _ItemIt, + typename _Map + > + class DescriptorMap : protected _Map { + public: + typedef _Graph Graph; + typedef _Item Item; + typedef _ItemIt ItemIt; + typedef _Map Map; + + + typedef typename _Map::Key Key; + typedef typename _Map::Value Value; + + typedef vector InverseMap; + + DescriptorMap(const Graph& _graph) : Map(_graph) { + build(); + } + + virtual void add(const Item& item) { + Map::add(item); + Map::set(item, inv_map.size()); + inv_map.push_back(item); + } + + virtual void erase(const Item& item) { + Map::set(inv_map.back(), Map::operator[](item)); + inv_map[Map::operator[](item)] = inv_map.back(); + Map::erase(item); + } + + virtual void build() { + Map::build(); + for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) { + Map::set(it, inv_map.size()); + inv_map.push_back(it); + } + } + + virtual void clear() { + inv_map.clear(); + Map::clear(); + } + + int operator[](const Item& item) const { + return Map::operator[](item); + } + + + const InverseMap inverse() const { + return inv_map; + } + + private: + vector inv_map; + }; + + // unique, immutable => IDMap + + + }