src/hugo/vector_map_factory.h
changeset 822 88226d9fe821
parent 821 283a7fe3a00e
child 823 afba7fbbb239
     1.1 --- a/src/hugo/vector_map_factory.h	Wed Sep 08 11:58:06 2004 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,373 +0,0 @@
     1.4 -// -*- c++ -*-
     1.5 -#ifndef VECTOR_MAP_H
     1.6 -#define VECTOR_MAP_H
     1.7 -
     1.8 -#include <vector>
     1.9 -
    1.10 -#include <hugo/extended_pair.h>
    1.11 -
    1.12 -///\ingroup graphmapfactory
    1.13 -///\file
    1.14 -///\brief Vector based graph maps.
    1.15 -
    1.16 -namespace hugo {
    1.17 -  
    1.18 -  /// \addtogroup graphmapfactory
    1.19 -  /// @{
    1.20 -  
    1.21 -  /** The VectorMapFactory template class is a factory class
    1.22 -   *  to create maps for the edge and nodes. This map factory
    1.23 -   *  uses the std::vector to implement the container function.
    1.24 -   *
    1.25 -   *  The template parameter is the MapRegistry that the maps
    1.26 -   *  will belong to.
    1.27 -   * 
    1.28 -   * \todo It should use a faster initialization using the maxNodeId() or
    1.29 -   * maxEdgeId() function of the graph istead of iterating through each
    1.30 -   * edge/node.
    1.31 -   */
    1.32 -	
    1.33 -  template <typename MapRegistry>
    1.34 -  class VectorMapFactory {
    1.35 -  public:
    1.36 -		
    1.37 -    /// The graph type of the maps. 
    1.38 -    typedef typename MapRegistry::Graph Graph;
    1.39 -    /// The key type of the maps.
    1.40 -    typedef typename MapRegistry::KeyType KeyType;
    1.41 -    /// The iterator to iterate on the keys.
    1.42 -    typedef typename MapRegistry::KeyIt KeyIt;
    1.43 -
    1.44 -    /// The MapBase of the Map which imlements the core regisitry function.
    1.45 -    typedef typename MapRegistry::MapBase MapBase;
    1.46 -
    1.47 -		
    1.48 -    /** The template Map type.
    1.49 -     */
    1.50 -    template <typename V> 
    1.51 -    class Map : public MapBase {
    1.52 -
    1.53 -      typedef std::vector<V> Container;	
    1.54 -
    1.55 -    public:
    1.56 -
    1.57 -      /// The value type of the map.
    1.58 -      typedef V ValueType;
    1.59 -
    1.60 -      /// The value type of the map.
    1.61 -      typedef V Value;
    1.62 -      /// The reference type of the map;
    1.63 -      typedef typename Container::reference Reference;
    1.64 -      /// The pointer type of the map;
    1.65 -      typedef typename Container::pointer Pointer;
    1.66 -
    1.67 -      /// The const value type of the map.
    1.68 -      typedef const Value ConstValue;
    1.69 -      /// The const reference type of the map;
    1.70 -      typedef typename Container::const_reference ConstReference;
    1.71 -      /// The pointer type of the map;
    1.72 -      typedef typename Container::const_pointer ConstPointer;
    1.73 -
    1.74 -      /** Default constructor for the map.
    1.75 -       */
    1.76 -      Map() {}
    1.77 -		
    1.78 -      /** Graph and Registry initialized map constructor.
    1.79 -       */
    1.80 -      Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
    1.81 -	init();
    1.82 -      }
    1.83 -
    1.84 -      /** Constructor to use default value to initialize the map. 
    1.85 -       */
    1.86 -      Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
    1.87 -	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    1.88 -          int id = getGraph()->id(it);
    1.89 -	  if (id >= (int)container.size()) {
    1.90 -	    container.resize(id + 1);
    1.91 -	  }
    1.92 -	  set(it, v);
    1.93 -        }
    1.94 -      }
    1.95 -
    1.96 -      /** Constructor to copy a map of an other map type.
    1.97 -       */
    1.98 -      template <typename CMap> Map(const CMap& copy) : MapBase(copy) {
    1.99 -	if (getGraph()) {
   1.100 -	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
   1.101 -	    int id = getGraph()->id(it);
   1.102 -	    if (id >= (int)container.size()) {
   1.103 -	      container.resize(id + 1);
   1.104 -	    }
   1.105 -	    set(it, copy[it]);
   1.106 -	  }
   1.107 -	}
   1.108 -      }
   1.109 -
   1.110 -      /** Assign operator to copy a map an other map type.
   1.111 -       */
   1.112 -      template <typename CMap> Map& operator=(const CMap& copy) {
   1.113 -	if (getGraph()) {
   1.114 -	  destroy();
   1.115 -	} 
   1.116 -	this->MapBase::operator=(copy);
   1.117 -	if (getGraph()) {
   1.118 -	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
   1.119 -	    int id = getGraph()->id(it);
   1.120 -	    if (id >= (int)container.size()) {
   1.121 -	      container.resize(id + 1);
   1.122 -	    }
   1.123 -	    set(it, copy[it]);
   1.124 -	  }
   1.125 -	}
   1.126 -	return *this;
   1.127 -      }
   1.128 -
   1.129 -      /** The destructor of the map.
   1.130 -       */
   1.131 -      virtual ~Map() {
   1.132 -      }
   1.133 -		
   1.134 -      /**
   1.135 -       * The subscript operator. The map can be subscripted by the
   1.136 -       * actual keys of the graph. 
   1.137 -       */
   1.138 -      Reference operator[](const KeyType& key) {
   1.139 -	int id = getGraph()->id(key);
   1.140 -	return container[id];
   1.141 -      } 
   1.142 -		
   1.143 -      /**
   1.144 -       * The const subscript operator. The map can be subscripted by the
   1.145 -       * actual keys of the graph. 
   1.146 -       */
   1.147 -      ConstReference operator[](const KeyType& key) const {
   1.148 -	int id = getGraph()->id(key);
   1.149 -	return container[id];
   1.150 -      }
   1.151 -
   1.152 -      /** Setter function of the map. Equivalent with map[key] = val.
   1.153 -       *  This is a compatibility feature with the not dereferable maps.
   1.154 -       */
   1.155 -      void set(const KeyType& key, const Value& val) {
   1.156 -	int id = getGraph()->id(key);
   1.157 -	container[id] = val;
   1.158 -      }
   1.159 -		
   1.160 -      /** Add a new key to the map. It called by the map registry.
   1.161 -       */
   1.162 -      void add(const KeyType& key) {
   1.163 -	int id = getGraph()->id(key);
   1.164 -	if (id >= (int)container.size()) {
   1.165 -	  container.resize(id + 1);
   1.166 -	}
   1.167 -      }
   1.168 -		
   1.169 -      /** Erase a key from the map. It called by the map registry.
   1.170 -       */
   1.171 -      void erase(const KeyType& key) {}
   1.172 -
   1.173 -      /** Clear the data structure.
   1.174 -       */
   1.175 -      void clear() { 
   1.176 -	container.clear();
   1.177 -      }
   1.178 -
   1.179 -      class iterator;
   1.180 -      class const_iterator;
   1.181 -
   1.182 -      /** Compatible iterator with the stl maps' iterators.
   1.183 -       *  It iterates on pairs of a key and a value.
   1.184 -       */
   1.185 -      class iterator {
   1.186 -	friend class Map;
   1.187 -	friend class const_iterator;
   1.188 -      private:
   1.189 -
   1.190 -	/** Private constructor to initalize the the iterators returned
   1.191 -	 *  by the begin() and end().
   1.192 -	 */
   1.193 -	iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {}
   1.194 -
   1.195 -      public:
   1.196 -
   1.197 -	/** Default constructor. 
   1.198 -	 */
   1.199 -	iterator() {}
   1.200 -
   1.201 -	typedef extended_pair<const KeyType&, const KeyType&, 
   1.202 -			      Map::Reference, Map::Reference> Reference;
   1.203 -
   1.204 -	/** Dereference operator for map.
   1.205 -	 */	 
   1.206 -	Reference operator*() {
   1.207 -	  return Reference(it, (*map)[it]);
   1.208 -	}
   1.209 -
   1.210 -	class Pointer {
   1.211 -	  friend class iterator;
   1.212 -	private:
   1.213 -	  Reference data;
   1.214 -	  Pointer(const KeyType& key, Map::Reference val) : data(key, val) {}
   1.215 -	public:
   1.216 -	  Reference* operator->() {return &data;}
   1.217 -	};
   1.218 -
   1.219 -	/** Arrow operator for map.
   1.220 -	 */	 
   1.221 -	Pointer operator->() {
   1.222 -	  return Pointer(it, ((*map)[it])); 
   1.223 -	}
   1.224 -
   1.225 -	/** The pre increment operator of the map.
   1.226 -	 */
   1.227 -	iterator& operator++() { 
   1.228 -	  ++it; 
   1.229 -	  return *this; 
   1.230 -	}
   1.231 -
   1.232 -	/** The post increment operator of the map.
   1.233 -	 */
   1.234 -	iterator operator++(int) { 
   1.235 -	  iterator tmp(it); 
   1.236 -	  ++it; 
   1.237 -	  return tmp; 
   1.238 -	}
   1.239 -
   1.240 -	/** The equality operator of the map.
   1.241 -	 */
   1.242 -	bool operator==(const_iterator p_it) {
   1.243 -	  return p_it.it == it;
   1.244 -	}
   1.245 -	
   1.246 -	/** The not-equality operator of the map.
   1.247 -	 */
   1.248 -	bool operator!=(const_iterator p_it) {
   1.249 -	  return !(*this == p_it);
   1.250 -	}
   1.251 -
   1.252 -	
   1.253 -      private:
   1.254 -	Map* map;
   1.255 -	KeyIt it;
   1.256 -      };
   1.257 -
   1.258 -      /** Returns the begin iterator of the map.
   1.259 -       */
   1.260 -      iterator begin() {
   1.261 -	return iterator(*this, KeyIt(*getGraph()));
   1.262 -      }
   1.263 -
   1.264 -      /** Returns the end iterator of the map.
   1.265 -       */
   1.266 -      iterator end() {
   1.267 -	return iterator(*this, INVALID);
   1.268 -      }
   1.269 -
   1.270 -      class const_iterator {
   1.271 -	friend class Map;
   1.272 -	friend class iterator;
   1.273 -      private:
   1.274 -
   1.275 -	/** Private constructor to initalize the the iterators returned
   1.276 -	 *  by the begin() and end().
   1.277 -	 */
   1.278 -	const_iterator (const Map& pmap, const KeyIt& pit) 
   1.279 -	  : map(&pmap), it(pit) {}
   1.280 -
   1.281 -      public:
   1.282 -
   1.283 -	/** Default constructor. 
   1.284 -	 */
   1.285 -	const_iterator() {}
   1.286 -
   1.287 -	/** Constructor to convert iterator to const_iterator.
   1.288 -	 */
   1.289 -	const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
   1.290 -      
   1.291 -	typedef extended_pair<const KeyType&, const KeyType&, 
   1.292 -	  Map::ConstReference, Map::ConstReference> Reference;
   1.293 -
   1.294 -	/** Dereference operator for map.
   1.295 -	 */	 
   1.296 -	Reference operator*() {
   1.297 -	  return Reference(it, (*map)[it]);
   1.298 -	}
   1.299 -
   1.300 -
   1.301 -	class Pointer {
   1.302 -	  friend class const_iterator;
   1.303 -	private:
   1.304 -	  Reference data;
   1.305 -	  Pointer(const KeyType& key, Map::ConstReference val) 
   1.306 -	    : data(key, val) {}
   1.307 -	public:
   1.308 -	  Reference* operator->() {return &data;}
   1.309 -	};
   1.310 -
   1.311 -	/** Arrow operator for map.
   1.312 -	 */	 
   1.313 -	Pointer operator->() {
   1.314 -	  return Pointer(it, ((*map)[it])); 
   1.315 -	}
   1.316 -
   1.317 -	/** The pre increment operator of the map.
   1.318 -	 */
   1.319 -	const_iterator& operator++() { 
   1.320 -	  ++it; 
   1.321 -	  return *this; 
   1.322 -	}
   1.323 -
   1.324 -	/** The post increment operator of the map.
   1.325 -	 */
   1.326 -	const_iterator operator++(int) { 
   1.327 -	  const_iterator tmp(it); 
   1.328 -	  ++it; 
   1.329 -	  return tmp; 
   1.330 -	}
   1.331 -
   1.332 -	/** The equality operator of the map.
   1.333 -	 */
   1.334 -	bool operator==(const_iterator p_it) {
   1.335 -	  return p_it.it == it;
   1.336 -	}
   1.337 -	
   1.338 -	/** The not-equality operator of the map.
   1.339 -	 */
   1.340 -	bool operator!=(const_iterator p_it) {
   1.341 -	  return !(*this == p_it);
   1.342 -	}
   1.343 -	
   1.344 -
   1.345 -      private:
   1.346 -	const Map* map;
   1.347 -	KeyIt it;
   1.348 -      };
   1.349 -
   1.350 -      /** Returns the begin const_iterator of the map.
   1.351 -       */
   1.352 -      const_iterator begin() const {
   1.353 -	return const_iterator(*this, KeyIt(*getGraph()));
   1.354 -      }
   1.355 -
   1.356 -      /** Returns the end const_iterator of the map.
   1.357 -       */
   1.358 -      const_iterator end() const {
   1.359 -	return const_iterator(*this, INVALID);
   1.360 -      }
   1.361 -
   1.362 -      private:
   1.363 -		
   1.364 -      Container container;
   1.365 -
   1.366 -    };
   1.367 -		
   1.368 -  };
   1.369 -
   1.370 -  
   1.371 -  /// @}
   1.372 -  
   1.373 -
   1.374 -}
   1.375 -
   1.376 -#endif