src/hugo/vector_map.h
changeset 893 89d5c283a485
parent 844 9bf990cb066d
child 897 ef09eee53b09
equal deleted inserted replaced
2:eea5f7431087 3:c601d2eae044
    30    * edge/node.
    30    * edge/node.
    31    */
    31    */
    32 	
    32 	
    33   template <typename MapRegistry, typename Value>
    33   template <typename MapRegistry, typename Value>
    34   class VectorMap : public MapRegistry::MapBase {
    34   class VectorMap : public MapRegistry::MapBase {
       
    35     template <typename MR, typename T> friend class VectorMap;
    35   public:
    36   public:
    36 		
    37 		
    37     /// The graph type of the maps. 
    38     /// The graph type of the maps. 
    38     typedef typename MapRegistry::Graph Graph;
    39     typedef typename MapRegistry::Graph Graph;
    39     /// The key type of the maps.
    40     /// The key type of the maps.
    80     /** Constructor to use default value to initialize the map. 
    81     /** Constructor to use default value to initialize the map. 
    81      */
    82      */
    82     VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
    83     VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
    83       : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
    84       : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
    84 
    85 
    85     /** Constructor to copy a map of an other map type.
    86     /** Assign operator to copy a map of an other map type.
    86      */
    87      */
    87     template <typename CMap> VectorMap(const CMap& copy) : MapBase(copy) {
    88     template <typename TT>
    88       if (MapBase::getGraph()) {
    89     VectorMap(const VectorMap<MapRegistry, TT>& c) 
    89 	container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
    90       : MapBase(c), container(c.container.size()) {
    90 	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    91       for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    91 	  set(it, copy[it]);
    92 	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    92 	}
    93 	container[id] = c.container[id];
    93       }
    94       }
    94     }
    95     }
    95 
    96 
    96     /** Assign operator to copy a map an other map type.
    97     /** Assign operator to copy a map of an other map type.
    97      */
    98      */
    98     template <typename CMap> VectorMap& operator=(const CMap& copy) {
    99     template <typename TT>
    99       container.clear();
   100     VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
   100       this->MapBase::operator=(copy);
   101       container.resize(c.container.size());
   101       if (MapBase::getGraph()) {
   102       MapBase::operator=(c);
   102 	container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
   103       for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   103 	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   104 	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   104 	  set(it, copy[it]);
   105 	container[id] = c.container[id];
   105 	}
       
   106       }
   106       }
   107       return *this;
   107       return *this;
   108     }
   108     }
   109 
       
   110     /** The destructor of the map.
       
   111      */
       
   112     virtual ~VectorMap() {
       
   113     }
       
   114 		
       
   115     /**
   109     /**
   116      * The subscript operator. The map can be subscripted by the
   110      * The subscript operator. The map can be subscripted by the
   117      * actual keys of the graph. 
   111      * actual keys of the graph. 
   118      */
   112      */
   119     ReferenceType operator[](const KeyType& key) {
   113     ReferenceType operator[](const KeyType& key) {