src/hugo/sym_map_factory.h
author deba
Wed, 08 Sep 2004 12:06:45 +0000
changeset 822 88226d9fe821
parent 786 d7b3b13b9df6
permissions -rw-r--r--
The MapFactories have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.
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@798
    15
      : EdgeIt(graph) {
deba@798
    16
      while ( n != -1 && (n & 1)) {
deba@798
    17
	EdgeIt::operator++();
deba@798
    18
      }
deba@798
    19
    }
deba@782
    20
deba@782
    21
    SymEdgeIt(Invalid invalid) 
deba@782
    22
      : EdgeIt(invalid) {}
deba@782
    23
deba@782
    24
    SymEdgeIt(const Graph& graph, Edge edge)
deba@782
    25
      : EdgeIt(graph, edge) {}
deba@782
    26
deba@782
    27
    SymEdgeIt& operator++() {
deba@782
    28
      EdgeIt::operator++();
deba@782
    29
      while ( n != -1 && (n & 1)) {
deba@782
    30
	EdgeIt::operator++();
deba@782
    31
      }
deba@782
    32
      return *this;
deba@782
    33
    }
deba@782
    34
  };
deba@782
    35
deba@782
    36
  template <typename MapRegistry, template <typename> class MapFactory>
deba@782
    37
  class SymMapFactory {
deba@782
    38
deba@782
    39
  public:
deba@782
    40
		
deba@782
    41
    typedef typename MapRegistry::Graph Graph;
alpar@786
    42
    typedef typename MapRegistry::KeyType KeyType;
deba@782
    43
    typedef typename MapRegistry::KeyIt KeyIt;
deba@782
    44
deba@782
    45
    typedef typename MapRegistry::MapBase MapBase;
deba@782
    46
deba@782
    47
    template <typename V>
deba@782
    48
    class Map : public MapFactory<MapRegistry>::template Map<V> {
deba@782
    49
deba@782
    50
      typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl;
deba@782
    51
    public:
deba@782
    52
deba@782
    53
      typedef V Value;
deba@782
    54
deba@782
    55
      Map() : MapImpl() {}
deba@782
    56
deba@782
    57
      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
deba@782
    58
deba@798
    59
      Map(const Graph& g, MapRegistry& r, const Value& v) 
deba@798
    60
	: MapImpl(g, r, v) {}
deba@782
    61
deba@782
    62
      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
deba@782
    63
deba@782
    64
      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
deba@782
    65
deba@782
    66
      Map& operator=(const Map& copy) {
deba@782
    67
	MapImpl::operator=(static_cast<const MapImpl&>(copy));
deba@782
    68
	return *this;
deba@782
    69
      }
deba@782
    70
deba@782
    71
      template <typename CMap> Map& operator=(const CMap& copy) {
deba@782
    72
	MapImpl::operator=(copy);
deba@782
    73
	return *this;
deba@782
    74
      }
deba@782
    75
   
alpar@786
    76
      Value& operator[](const KeyType& key) {
deba@782
    77
	int id = MapBase::getGraph()->id(key);	
deba@782
    78
	return MapImpl::operator[](id >> 1);
deba@782
    79
      } 
deba@782
    80
		
alpar@786
    81
      const Value& operator[](const KeyType& 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
	
alpar@786
    86
      const Value& get(const KeyType& key) const {
deba@782
    87
	int id = MapBase::getGraph()->id(key);
deba@782
    88
	return MapImpl::operator[](id >> 1);
deba@782
    89
      } 
deba@782
    90
		
alpar@786
    91
      void set(const KeyType& key, const Value& val) {
deba@782
    92
	int id = MapBase::getGraph()->id(key);
deba@782
    93
	MapImpl::operator[](id >> 1) = val;
deba@782
    94
      }
deba@782
    95
		
alpar@786
    96
      void add(const KeyType& key) {
deba@782
    97
	int id = MapBase::getGraph()->id(key);
deba@782
    98
	if (id & 1) return;
deba@782
    99
	MapImpl::add(key);
deba@782
   100
      }
deba@782
   101
		
alpar@786
   102
      void erase(const KeyType& key) {
deba@782
   103
	int id = MapBase::getGraph()->id(key);
deba@782
   104
	if (id & 1) return;
deba@782
   105
	MapImpl::add(key);
deba@782
   106
      }
deba@782
   107
deba@782
   108
deba@782
   109
    };  
deba@782
   110
  };
deba@782
   111
}
deba@782
   112
#endif