diff -r d56fad02dc55 -r 9bf990cb066d src/hugo/vector_map.h --- a/src/hugo/vector_map.h Mon Sep 13 18:00:26 2004 +0000 +++ b/src/hugo/vector_map.h Mon Sep 13 20:05:13 2004 +0000 @@ -5,6 +5,7 @@ #include #include +#include ///\ingroup graphmaps ///\file @@ -73,32 +74,20 @@ /** Graph and Registry initialized map constructor. */ - VectorMap(const Graph& g, MapRegistry& r) : MapBase(g, r) { - init(); - } + VectorMap(const Graph& g, MapRegistry& r) + : MapBase(g, r), container(KeyInfo::maxId(g)+1) {} /** Constructor to use default value to initialize the map. */ VectorMap(const Graph& g, MapRegistry& r, const Value& v) - : MapBase(g, r) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } - set(it, v); - } - } + : MapBase(g, r), container(KeyInfo::maxId(g)+1, v) {} /** Constructor to copy a map of an other map type. */ template VectorMap(const CMap& copy) : MapBase(copy) { - if (getGraph()) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } + if (MapBase::getGraph()) { + container.resize(KeyInfo::maxId(*MapBase::getGraph())+1); + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { set(it, copy[it]); } } @@ -107,16 +96,11 @@ /** Assign operator to copy a map an other map type. */ template VectorMap& operator=(const CMap& copy) { - if (getGraph()) { - destroy(); - } + container.clear(); this->MapBase::operator=(copy); - if (getGraph()) { - for (KeyIt it(*getGraph()); it != INVALID; ++it) { - int id = getGraph()->id(it); - if (id >= (int)container.size()) { - container.resize(id + 1); - } + if (MapBase::getGraph()) { + container.resize(KeyInfo::maxId(*MapBase::getGraph())+1); + for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { set(it, copy[it]); } } @@ -133,7 +117,7 @@ * actual keys of the graph. */ ReferenceType operator[](const KeyType& key) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return container[id]; } @@ -142,7 +126,7 @@ * actual keys of the graph. */ ConstReferenceType operator[](const KeyType& key) const { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); return container[id]; } @@ -150,14 +134,14 @@ * This is a compatibility feature with the not dereferable maps. */ void set(const KeyType& key, const ValueType& val) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); container[id] = val; } /** Add a new key to the map. It called by the map registry. */ void add(const KeyType& key) { - int id = getGraph()->id(key); + int id = KeyInfo::id(*MapBase::getGraph(), key); if (id >= (int)container.size()) { container.resize(id + 1); } @@ -231,7 +215,18 @@ Container container; - + public: + // STL compatibility typedefs. + typedef Iterator iterator; + typedef ConstIterator const_iterator; + typedef typename Iterator::PairValueType value_type; + typedef typename Iterator::KeyType key_type; + typedef typename Iterator::ValueType data_type; + typedef typename Iterator::PairReferenceType reference; + typedef typename Iterator::PairPointerType pointer; + typedef typename ConstIterator::PairReferenceType const_reference; + typedef typename ConstIterator::PairPointerType const_pointer; + typedef int difference_type; }; /// @}