src/work/deba/vector_map_factory.h
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/deba/vector_map_factory.h	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,332 +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 "extended_pair.h"
    1.11 -
    1.12 -namespace lemon {
    1.13 -
    1.14 -  /** The VectorMapFactory template class is a factory class
    1.15 -   *  to create maps for the edge and nodes. This map factory
    1.16 -   *  use the std::vector to implement the container function.
    1.17 -   *
    1.18 -   *  The template parameter is the MapRegistry that the maps
    1.19 -   *  will belong to.
    1.20 -   */
    1.21 -	
    1.22 -  template <typename MapRegistry>
    1.23 -  class VectorMapFactory {
    1.24 -  public:
    1.25 -		
    1.26 -    /// The graph type of the maps. 
    1.27 -    typedef typename MapRegistry::Graph Graph;
    1.28 -    /// The key type of the maps.
    1.29 -    typedef typename MapRegistry::Key Key;
    1.30 -    /// The iterator to iterate on the keys.
    1.31 -    typedef typename MapRegistry::KeyIt KeyIt;
    1.32 -
    1.33 -    /// The MapBase of the Map which imlements the core regisitry function.
    1.34 -    typedef typename MapRegistry::MapBase MapBase;
    1.35 -
    1.36 -		
    1.37 -    /** The template Map type.
    1.38 -     */
    1.39 -    template <typename V> 
    1.40 -    class Map : public MapBase {
    1.41 -    public:
    1.42 -
    1.43 -      /// The value type of the map.
    1.44 -      typedef V Value;
    1.45 -
    1.46 -      typedef std::vector<Value> Container;	
    1.47 -
    1.48 -      /** Default constructor for the map.
    1.49 -       */
    1.50 -      Map() {}
    1.51 -		
    1.52 -      /** Graph and Registry initialized map constructor.
    1.53 -       */
    1.54 -      Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
    1.55 -	init();
    1.56 -      }
    1.57 -
    1.58 -      /** Constructor to use default value to initialize the map. 
    1.59 -       */
    1.60 -      Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
    1.61 -	for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
    1.62 -          int id = getGraph->id(it);
    1.63 -	  if (id >= container.size) {
    1.64 -	    container.resize(id + 1);
    1.65 -	  }
    1.66 -	  set(it, v);
    1.67 -        }
    1.68 -      }
    1.69 -
    1.70 -      /** Constructor to copy a map of an other map type.
    1.71 -       */
    1.72 -      template <typename CMap> Map(const CMap& copy) : MapBase(copy) {
    1.73 -	if (getGraph()) {
    1.74 -	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
    1.75 -	    int id = getGraph->id(it);
    1.76 -	    if (id >= container.size) {
    1.77 -	      container.resize(id + 1);
    1.78 -	    }
    1.79 -	    set(it, copy[it]);
    1.80 -	  }
    1.81 -	}
    1.82 -      }
    1.83 -
    1.84 -      /** Assign operator to copy a map an other map type.
    1.85 -       */
    1.86 -      template <typename CMap> Map& operator=(const CMap& copy) {
    1.87 -	if (getGraph()) {
    1.88 -	  destroy();
    1.89 -	} 
    1.90 -	this->MapBase::operator=(copy);
    1.91 -	if (getGraph()) {
    1.92 -	  for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
    1.93 -	    int id = getGraph->id(it);
    1.94 -	    if (id >= container.size) {
    1.95 -	      container.resize(id + 1);
    1.96 -	    }
    1.97 -	    set(it, copy[it]);
    1.98 -	  }
    1.99 -	}
   1.100 -      }
   1.101 -
   1.102 -      /** The destructor of the map.
   1.103 -       */
   1.104 -      virtual ~Map() {
   1.105 -      }
   1.106 -		
   1.107 -      /**
   1.108 -       * The subscript operator. The map can be subscripted by the
   1.109 -       * actual keys of the graph. 
   1.110 -       */
   1.111 -      typename Container::reference operator[](const Key& key) {
   1.112 -	int id = getGraph()->id(key);
   1.113 -	return container[id];
   1.114 -      } 
   1.115 -		
   1.116 -      /**
   1.117 -       * The const subscript operator. The map can be subscripted by the
   1.118 -       * actual keys of the graph. 
   1.119 -       */
   1.120 -      typename Container::const_reference operator[](const Key& key) const {
   1.121 -	int id = getGraph()->id(key);
   1.122 -	return container[id];
   1.123 -      }
   1.124 -
   1.125 -      /** Setter function of the map. Equivalent with map[key] = val.
   1.126 -       *  This is a compatibility feature with the not dereferable maps.
   1.127 -       */
   1.128 -      void set(const Key& key, const Value& val) {
   1.129 -	int id = getGraph()->id(key);
   1.130 -	container[id] = val;
   1.131 -      }
   1.132 -		
   1.133 -      /** Add a new key to the map. It called by the map registry.
   1.134 -       */
   1.135 -      void add(const Key& key) {
   1.136 -	int id = getGraph()->id(key);
   1.137 -	if (id >= container.size()) {
   1.138 -	  container.resize(id + 1);
   1.139 -	}
   1.140 -      }
   1.141 -		
   1.142 -      /** Erease a key from the map. It called by the map registry.
   1.143 -       */
   1.144 -      void erase(const Key& key) {}
   1.145 -
   1.146 -      /** Compatible iterator with the stl maps' iterators.
   1.147 -       *  It iterates on pairs of a key and a value.
   1.148 -       */
   1.149 -      class iterator {
   1.150 -	friend class Map;
   1.151 -	friend class const_iterator;
   1.152 -      private:
   1.153 -
   1.154 -	/** Private constructor to initalize the the iterators returned
   1.155 -	 *  by the begin() and end().
   1.156 -	 */
   1.157 -	iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {}
   1.158 -
   1.159 -      public:
   1.160 -
   1.161 -	/** Default constructor. 
   1.162 -	 */
   1.163 -	iterator() {}
   1.164 -
   1.165 -	typedef extended_pair<const Key&, const Key&, 
   1.166 -			      Value&, Value&> Reference;
   1.167 -
   1.168 -	/** Dereference operator for map.
   1.169 -	 */	 
   1.170 -	Reference operator*() {
   1.171 -	  return Reference(it, (*map)[it]);
   1.172 -	}
   1.173 -
   1.174 -	class Pointer {
   1.175 -	  friend class iterator;
   1.176 -	private:
   1.177 -	  Reference data;
   1.178 -	  Pointer(const Key& key, Value& val) : data(key, val) {}
   1.179 -	public:
   1.180 -	  Reference* operator->() {return &data;}
   1.181 -	};
   1.182 -
   1.183 -	/** Arrow operator for map.
   1.184 -	 */	 
   1.185 -	Pointer operator->() {
   1.186 -	  return Pointer(it, ((*map)[it])); 
   1.187 -	}
   1.188 -
   1.189 -	/** The pre increment operator of the map.
   1.190 -	 */
   1.191 -	iterator& operator++() { 
   1.192 -	  map->getGraph()->next(it); 
   1.193 -	  return *this; 
   1.194 -	}
   1.195 -
   1.196 -	/** The post increment operator of the map.
   1.197 -	 */
   1.198 -	iterator operator++(int) { 
   1.199 -	  iterator tmp(it); 
   1.200 -	  map.getGraph()->next(it); 
   1.201 -	  return tmp; 
   1.202 -	}
   1.203 -
   1.204 -	/** The equality operator of the map.
   1.205 -	 */
   1.206 -	bool operator==(const_iterator p_it) {
   1.207 -	  return p_it.it == it;
   1.208 -	}
   1.209 -	
   1.210 -	/** The not-equality operator of the map.
   1.211 -	 */
   1.212 -	bool operator!=(const_iterator p_it) {
   1.213 -	  return !(*this == p_it);
   1.214 -	}
   1.215 -
   1.216 -	
   1.217 -      private:
   1.218 -	Map* map;
   1.219 -	KeyIt it;
   1.220 -      };
   1.221 -
   1.222 -      /** Returns the begin iterator of the map.
   1.223 -       */
   1.224 -      iterator begin() {
   1.225 -	return iterator(*this, KeyIt(*getGraph()));
   1.226 -      }
   1.227 -
   1.228 -      /** Returns the end iterator of the map.
   1.229 -       */
   1.230 -      iterator end() {
   1.231 -	return iterator(*this, INVALID);
   1.232 -      }
   1.233 -
   1.234 -      class const_iterator {
   1.235 -	friend class Map;
   1.236 -	friend class iterator;
   1.237 -      private:
   1.238 -
   1.239 -	/** Private constructor to initalize the the iterators returned
   1.240 -	 *  by the begin() and end().
   1.241 -	 */
   1.242 -	const_iterator (const Map& pmap, const KeyIt& pit) 
   1.243 -	  : map(&pmap), it(pit) {}
   1.244 -
   1.245 -      public:
   1.246 -
   1.247 -	/** Default constructor. 
   1.248 -	 */
   1.249 -	const_iterator() {}
   1.250 -
   1.251 -	/** Constructor to convert iterator to const_iterator.
   1.252 -	 */
   1.253 -	const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
   1.254 -      
   1.255 -	typedef extended_pair<const Key&, const Key&, 
   1.256 -	  const Value&, const Value&> Reference;
   1.257 -
   1.258 -	/** Dereference operator for map.
   1.259 -	 */	 
   1.260 -	Reference operator*() {
   1.261 -	  return Reference(it, (*map)[it]);
   1.262 -	}
   1.263 -
   1.264 -
   1.265 -	class Pointer {
   1.266 -	  friend class const_iterator;
   1.267 -	private:
   1.268 -	  Reference data;
   1.269 -	  Pointer(const Key& key, const Value& val) : data(key, val) {}
   1.270 -	public:
   1.271 -	  Reference* operator->() {return &data;}
   1.272 -	};
   1.273 -
   1.274 -	/** Arrow operator for map.
   1.275 -	 */	 
   1.276 -	Pointer operator->() {
   1.277 -	  return Pointer(it, ((*map)[it])); 
   1.278 -	}
   1.279 -
   1.280 -	/** The pre increment operator of the map.
   1.281 -	 */
   1.282 -	const_iterator& operator++() { 
   1.283 -	  map->getGraph()->next(it); 
   1.284 -	  return *this; 
   1.285 -	}
   1.286 -
   1.287 -	/** The post increment operator of the map.
   1.288 -	 */
   1.289 -	const_iterator operator++(int) { 
   1.290 -	  const_iterator tmp(it); 
   1.291 -	  map->getGraph()->next(it); 
   1.292 -	  return tmp; 
   1.293 -	}
   1.294 -
   1.295 -	/** The equality operator of the map.
   1.296 -	 */
   1.297 -	bool operator==(const_iterator p_it) {
   1.298 -	  return p_it.it == it;
   1.299 -	}
   1.300 -	
   1.301 -	/** The not-equality operator of the map.
   1.302 -	 */
   1.303 -	bool operator!=(const_iterator p_it) {
   1.304 -	  return !(*this == p_it);
   1.305 -	}
   1.306 -	
   1.307 -
   1.308 -      private:
   1.309 -	const Map* map;
   1.310 -	KeyIt it;
   1.311 -      };
   1.312 -
   1.313 -      /** Returns the begin const_iterator of the map.
   1.314 -       */
   1.315 -      const_iterator begin() const {
   1.316 -	return const_iterator(*this, KeyIt(*getGraph()));
   1.317 -      }
   1.318 -
   1.319 -      /** Returns the end const_iterator of the map.
   1.320 -       */
   1.321 -      const_iterator end() const {
   1.322 -	return const_iterator(*this, INVALID);
   1.323 -      }
   1.324 -
   1.325 -      private:
   1.326 -		
   1.327 -      Container container;
   1.328 -
   1.329 -    };
   1.330 -		
   1.331 -  };
   1.332 -
   1.333 -}
   1.334 -
   1.335 -#endif