src/hugo/vector_map_factory.h
changeset 795 cfa6c2ea48e5
parent 785 a9b0863c2265
child 798 6d1abeb62dd3
equal deleted inserted replaced
1:416bbd7e61b7 2:340d479b870d
    28   public:
    28   public:
    29 		
    29 		
    30     /// The graph type of the maps. 
    30     /// The graph type of the maps. 
    31     typedef typename MapRegistry::Graph Graph;
    31     typedef typename MapRegistry::Graph Graph;
    32     /// The key type of the maps.
    32     /// The key type of the maps.
    33     typedef typename MapRegistry::Key Key;
    33     typedef typename MapRegistry::KeyType KeyType;
    34     /// The iterator to iterate on the keys.
    34     /// The iterator to iterate on the keys.
    35     typedef typename MapRegistry::KeyIt KeyIt;
    35     typedef typename MapRegistry::KeyIt KeyIt;
    36 
    36 
    37     /// The MapBase of the Map which imlements the core regisitry function.
    37     /// The MapBase of the Map which imlements the core regisitry function.
    38     typedef typename MapRegistry::MapBase MapBase;
    38     typedef typename MapRegistry::MapBase MapBase;
   110 		
   110 		
   111       /**
   111       /**
   112        * The subscript operator. The map can be subscripted by the
   112        * The subscript operator. The map can be subscripted by the
   113        * actual keys of the graph. 
   113        * actual keys of the graph. 
   114        */
   114        */
   115       typename Container::reference operator[](const Key& key) {
   115       typename Container::reference operator[](const KeyType& key) {
   116 	int id = getGraph()->id(key);
   116 	int id = getGraph()->id(key);
   117 	return container[id];
   117 	return container[id];
   118       } 
   118       } 
   119 		
   119 		
   120       /**
   120       /**
   121        * The const subscript operator. The map can be subscripted by the
   121        * The const subscript operator. The map can be subscripted by the
   122        * actual keys of the graph. 
   122        * actual keys of the graph. 
   123        */
   123        */
   124       typename Container::const_reference operator[](const Key& key) const {
   124       typename Container::const_reference operator[](const KeyType& key) const {
   125 	int id = getGraph()->id(key);
   125 	int id = getGraph()->id(key);
   126 	return container[id];
   126 	return container[id];
   127       }
   127       }
   128 
   128 
   129       /** Setter function of the map. Equivalent with map[key] = val.
   129       /** Setter function of the map. Equivalent with map[key] = val.
   130        *  This is a compatibility feature with the not dereferable maps.
   130        *  This is a compatibility feature with the not dereferable maps.
   131        */
   131        */
   132       void set(const Key& key, const Value& val) {
   132       void set(const KeyType& key, const Value& val) {
   133 	int id = getGraph()->id(key);
   133 	int id = getGraph()->id(key);
   134 	container[id] = val;
   134 	container[id] = val;
   135       }
   135       }
   136 		
   136 		
   137       /** Add a new key to the map. It called by the map registry.
   137       /** Add a new key to the map. It called by the map registry.
   138        */
   138        */
   139       void add(const Key& key) {
   139       void add(const KeyType& key) {
   140 	int id = getGraph()->id(key);
   140 	int id = getGraph()->id(key);
   141 	if (id >= container.size()) {
   141 	if (id >= container.size()) {
   142 	  container.resize(id + 1);
   142 	  container.resize(id + 1);
   143 	}
   143 	}
   144       }
   144       }
   145 		
   145 		
   146       /** Erase a key from the map. It called by the map registry.
   146       /** Erase a key from the map. It called by the map registry.
   147        */
   147        */
   148       void erase(const Key& key) {}
   148       void erase(const KeyType& key) {}
   149 
   149 
   150       /** Clear the data structure.
   150       /** Clear the data structure.
   151        */
   151        */
   152       void clear() { 
   152       void clear() { 
   153 	container.clear();
   153 	container.clear();
   170 
   170 
   171 	/** Default constructor. 
   171 	/** Default constructor. 
   172 	 */
   172 	 */
   173 	iterator() {}
   173 	iterator() {}
   174 
   174 
   175 	typedef extended_pair<const Key&, const Key&, 
   175 	typedef extended_pair<const KeyType&, const KeyType&, 
   176 			      Value&, Value&> Reference;
   176 			      Value&, Value&> Reference;
   177 
   177 
   178 	/** Dereference operator for map.
   178 	/** Dereference operator for map.
   179 	 */	 
   179 	 */	 
   180 	Reference operator*() {
   180 	Reference operator*() {
   183 
   183 
   184 	class Pointer {
   184 	class Pointer {
   185 	  friend class iterator;
   185 	  friend class iterator;
   186 	private:
   186 	private:
   187 	  Reference data;
   187 	  Reference data;
   188 	  Pointer(const Key& key, Value& val) : data(key, val) {}
   188 	  Pointer(const KeyType& key, Value& val) : data(key, val) {}
   189 	public:
   189 	public:
   190 	  Reference* operator->() {return &data;}
   190 	  Reference* operator->() {return &data;}
   191 	};
   191 	};
   192 
   192 
   193 	/** Arrow operator for map.
   193 	/** Arrow operator for map.
   260 
   260 
   261 	/** Constructor to convert iterator to const_iterator.
   261 	/** Constructor to convert iterator to const_iterator.
   262 	 */
   262 	 */
   263 	const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
   263 	const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
   264       
   264       
   265 	typedef extended_pair<const Key&, const Key&, 
   265 	typedef extended_pair<const KeyType&, const KeyType&, 
   266 	  const Value&, const Value&> Reference;
   266 	  const Value&, const Value&> Reference;
   267 
   267 
   268 	/** Dereference operator for map.
   268 	/** Dereference operator for map.
   269 	 */	 
   269 	 */	 
   270 	Reference operator*() {
   270 	Reference operator*() {
   274 
   274 
   275 	class Pointer {
   275 	class Pointer {
   276 	  friend class const_iterator;
   276 	  friend class const_iterator;
   277 	private:
   277 	private:
   278 	  Reference data;
   278 	  Reference data;
   279 	  Pointer(const Key& key, const Value& val) : data(key, val) {}
   279 	  Pointer(const KeyType& key, const Value& val) : data(key, val) {}
   280 	public:
   280 	public:
   281 	  Reference* operator->() {return &data;}
   281 	  Reference* operator->() {return &data;}
   282 	};
   282 	};
   283 
   283 
   284 	/** Arrow operator for map.
   284 	/** Arrow operator for map.