src/hugo/sym_map_factory.h
author marci
Thu, 02 Sep 2004 11:20:49 +0000
changeset 784 a48964a87141
child 786 d7b3b13b9df6
permissions -rw-r--r--
dimacs.h
deba@782
     1
// -*- c++ -*-
deba@782
     2
#ifndef SYM_MAP_FACTORY_H
deba@782
     3
#define SYM_MAP_FACTORY_H
deba@782
     4
deba@782
     5
namespace hugo {
deba@782
     6
deba@782
     7
  template <typename Graph, typename Edge, typename EdgeIt>
deba@782
     8
  class SymEdgeIt : public EdgeIt {
deba@782
     9
  public:
deba@782
    10
deba@782
    11
    SymEdgeIt() 
deba@782
    12
      : EdgeIt() {}
deba@782
    13
deba@782
    14
    SymEdgeIt(const Graph& graph) 
deba@782
    15
      : EdgeIt(graph) {}
deba@782
    16
deba@782
    17
    SymEdgeIt(Invalid invalid) 
deba@782
    18
      : EdgeIt(invalid) {}
deba@782
    19
deba@782
    20
    SymEdgeIt(const Graph& graph, Edge edge)
deba@782
    21
      : EdgeIt(graph, edge) {}
deba@782
    22
deba@782
    23
    SymEdgeIt& operator++() {
deba@782
    24
      EdgeIt::operator++();
deba@782
    25
      while ( n != -1 && (n & 1)) {
deba@782
    26
	EdgeIt::operator++();
deba@782
    27
      }
deba@782
    28
      return *this;
deba@782
    29
    }
deba@782
    30
  };
deba@782
    31
deba@782
    32
  template <typename MapRegistry, template <typename> class MapFactory>
deba@782
    33
  class SymMapFactory {
deba@782
    34
deba@782
    35
  public:
deba@782
    36
		
deba@782
    37
    typedef typename MapRegistry::Graph Graph;
deba@782
    38
    typedef typename MapRegistry::Key Key;
deba@782
    39
    typedef typename MapRegistry::KeyIt KeyIt;
deba@782
    40
deba@782
    41
    typedef typename MapRegistry::MapBase MapBase;
deba@782
    42
deba@782
    43
    template <typename V>
deba@782
    44
    class Map : public MapFactory<MapRegistry>::template Map<V> {
deba@782
    45
deba@782
    46
      typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl;
deba@782
    47
    public:
deba@782
    48
deba@782
    49
      typedef V Value;
deba@782
    50
deba@782
    51
      Map() : MapImpl() {}
deba@782
    52
deba@782
    53
      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
deba@782
    54
deba@782
    55
      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
deba@782
    56
deba@782
    57
      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
deba@782
    58
deba@782
    59
      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
deba@782
    60
deba@782
    61
      Map& operator=(const Map& copy) {
deba@782
    62
	MapImpl::operator=(static_cast<const MapImpl&>(copy));
deba@782
    63
	return *this;
deba@782
    64
      }
deba@782
    65
deba@782
    66
      template <typename CMap> Map& operator=(const CMap& copy) {
deba@782
    67
	MapImpl::operator=(copy);
deba@782
    68
	return *this;
deba@782
    69
      }
deba@782
    70
   
deba@782
    71
      Value& operator[](const Key& key) {
deba@782
    72
	int id = MapBase::getGraph()->id(key);	
deba@782
    73
	return MapImpl::operator[](id >> 1);
deba@782
    74
      } 
deba@782
    75
		
deba@782
    76
      const Value& operator[](const Key& key) const {
deba@782
    77
	int id = MapBase::getGraph()->id(key);
deba@782
    78
	return MapImpl::operator[](id >> 1);
deba@782
    79
      }
deba@782
    80
	
deba@782
    81
      const Value& get(const Key& key) const {
deba@782
    82
	int id = MapBase::getGraph()->id(key);
deba@782
    83
	return MapImpl::operator[](id >> 1);
deba@782
    84
      } 
deba@782
    85
		
deba@782
    86
      void set(const Key& key, const Value& val) {
deba@782
    87
	int id = MapBase::getGraph()->id(key);
deba@782
    88
	MapImpl::operator[](id >> 1) = val;
deba@782
    89
      }
deba@782
    90
		
deba@782
    91
      void add(const Key& key) {
deba@782
    92
	int id = MapBase::getGraph()->id(key);
deba@782
    93
	if (id & 1) return;
deba@782
    94
	MapImpl::add(key);
deba@782
    95
      }
deba@782
    96
		
deba@782
    97
      void erase(const Key& key) {
deba@782
    98
	int id = MapBase::getGraph()->id(key);
deba@782
    99
	if (id & 1) return;
deba@782
   100
	MapImpl::add(key);
deba@782
   101
      }
deba@782
   102
deba@782
   103
deba@782
   104
    };  
deba@782
   105
  };
deba@782
   106
}
deba@782
   107
#endif