src/work/deba/vector_map_factory.h
author jacint
Thu, 13 May 2004 10:29:13 +0000
changeset 629 6620dfc606af
parent 595 e10b5e9419ef
child 698 625de6f1e766
permissions -rw-r--r--
max_flow interface changes
deba@571
     1
#ifndef VECTOR_MAP_H
deba@571
     2
#define VECTOR_MAP_H
deba@571
     3
deba@571
     4
#include <vector>
deba@571
     5
deba@627
     6
#include "map_registry.h"
deba@571
     7
deba@571
     8
namespace hugo {
deba@571
     9
	
deba@627
    10
  template <typename MapRegistry>
deba@627
    11
  class VectorMapFactory {
deba@627
    12
  public:
deba@627
    13
		
deba@627
    14
    typedef typename MapRegistry::Graph Graph;
deba@627
    15
    typedef typename MapRegistry::Key Key;
deba@627
    16
    typedef typename MapRegistry::KeyIt KeyIt;
deba@627
    17
deba@627
    18
    typedef typename MapRegistry::MapBase MapBase;
deba@627
    19
		
deba@627
    20
    template <typename V> 
deba@627
    21
      class Map : public MapBase {
deba@627
    22
      public:
deba@627
    23
      typedef V Value;
deba@571
    24
	
deba@627
    25
      Map() {}
deba@627
    26
			
deba@627
    27
      Map(Graph& g, MapRegistry& r) : MapBase(g, r) {
deba@627
    28
	init();
deba@627
    29
      }
deba@627
    30
			
deba@627
    31
						
deba@627
    32
      virtual ~Map() {
deba@627
    33
	destroy();
deba@627
    34
      }
deba@571
    35
	
deba@627
    36
	
deba@627
    37
      Value& operator[](const Key& key) {
deba@627
    38
	int id = graph->id(key);
deba@627
    39
	return container[id];
deba@627
    40
      } 
deba@571
    41
		
deba@627
    42
      const Value& operator[](const Key& key) const {
deba@627
    43
	int id = graph->id(key);
deba@627
    44
	return container[id];
deba@627
    45
      }
deba@627
    46
	
deba@627
    47
      const Value& get(const Key& key) const {
deba@627
    48
	int id = graph->id(key);
deba@627
    49
	return container[id];
deba@627
    50
      } 
deba@571
    51
		
deba@627
    52
      void set(const Key& key, const Value& val) {
deba@627
    53
	int id = graph->id(key);
deba@627
    54
	container[id] = val;
deba@627
    55
      }
deba@627
    56
		
deba@627
    57
      void add(const Key& key) {
deba@627
    58
	int id = graph->id(key);
deba@627
    59
	if (id >= container.size()) {
deba@627
    60
	  container.resize(id + 1);
deba@627
    61
	}
deba@627
    62
      }
deba@627
    63
		
deba@627
    64
      void erase(const Key& key) {}
deba@571
    65
	
deba@627
    66
      private:
deba@627
    67
      typedef std::vector<Value> Container;
deba@571
    68
		
deba@627
    69
      Container container;
deba@627
    70
    };
deba@571
    71
		
deba@627
    72
  };
deba@571
    73
}
deba@571
    74
deba@571
    75
#endif