src/hugo/sym_map_factory.h
changeset 782 df2e45e09652
child 786 d7b3b13b9df6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/hugo/sym_map_factory.h	Thu Sep 02 10:07:30 2004 +0000
     1.3 @@ -0,0 +1,107 @@
     1.4 +// -*- c++ -*-
     1.5 +#ifndef SYM_MAP_FACTORY_H
     1.6 +#define SYM_MAP_FACTORY_H
     1.7 +
     1.8 +namespace hugo {
     1.9 +
    1.10 +  template <typename Graph, typename Edge, typename EdgeIt>
    1.11 +  class SymEdgeIt : public EdgeIt {
    1.12 +  public:
    1.13 +
    1.14 +    SymEdgeIt() 
    1.15 +      : EdgeIt() {}
    1.16 +
    1.17 +    SymEdgeIt(const Graph& graph) 
    1.18 +      : EdgeIt(graph) {}
    1.19 +
    1.20 +    SymEdgeIt(Invalid invalid) 
    1.21 +      : EdgeIt(invalid) {}
    1.22 +
    1.23 +    SymEdgeIt(const Graph& graph, Edge edge)
    1.24 +      : EdgeIt(graph, edge) {}
    1.25 +
    1.26 +    SymEdgeIt& operator++() {
    1.27 +      EdgeIt::operator++();
    1.28 +      while ( n != -1 && (n & 1)) {
    1.29 +	EdgeIt::operator++();
    1.30 +      }
    1.31 +      return *this;
    1.32 +    }
    1.33 +  };
    1.34 +
    1.35 +  template <typename MapRegistry, template <typename> class MapFactory>
    1.36 +  class SymMapFactory {
    1.37 +
    1.38 +  public:
    1.39 +		
    1.40 +    typedef typename MapRegistry::Graph Graph;
    1.41 +    typedef typename MapRegistry::Key Key;
    1.42 +    typedef typename MapRegistry::KeyIt KeyIt;
    1.43 +
    1.44 +    typedef typename MapRegistry::MapBase MapBase;
    1.45 +
    1.46 +    template <typename V>
    1.47 +    class Map : public MapFactory<MapRegistry>::template Map<V> {
    1.48 +
    1.49 +      typedef typename MapFactory<MapRegistry>::template Map<V> MapImpl;
    1.50 +    public:
    1.51 +
    1.52 +      typedef V Value;
    1.53 +
    1.54 +      Map() : MapImpl() {}
    1.55 +
    1.56 +      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
    1.57 +
    1.58 +      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
    1.59 +
    1.60 +      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
    1.61 +
    1.62 +      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
    1.63 +
    1.64 +      Map& operator=(const Map& copy) {
    1.65 +	MapImpl::operator=(static_cast<const MapImpl&>(copy));
    1.66 +	return *this;
    1.67 +      }
    1.68 +
    1.69 +      template <typename CMap> Map& operator=(const CMap& copy) {
    1.70 +	MapImpl::operator=(copy);
    1.71 +	return *this;
    1.72 +      }
    1.73 +   
    1.74 +      Value& operator[](const Key& key) {
    1.75 +	int id = MapBase::getGraph()->id(key);	
    1.76 +	return MapImpl::operator[](id >> 1);
    1.77 +      } 
    1.78 +		
    1.79 +      const Value& operator[](const Key& key) const {
    1.80 +	int id = MapBase::getGraph()->id(key);
    1.81 +	return MapImpl::operator[](id >> 1);
    1.82 +      }
    1.83 +	
    1.84 +      const Value& get(const Key& key) const {
    1.85 +	int id = MapBase::getGraph()->id(key);
    1.86 +	return MapImpl::operator[](id >> 1);
    1.87 +      } 
    1.88 +		
    1.89 +      void set(const Key& key, const Value& val) {
    1.90 +	int id = MapBase::getGraph()->id(key);
    1.91 +	MapImpl::operator[](id >> 1) = val;
    1.92 +      }
    1.93 +		
    1.94 +      void add(const Key& key) {
    1.95 +	int id = MapBase::getGraph()->id(key);
    1.96 +	if (id & 1) return;
    1.97 +	MapImpl::add(key);
    1.98 +      }
    1.99 +		
   1.100 +      void erase(const Key& key) {
   1.101 +	int id = MapBase::getGraph()->id(key);
   1.102 +	if (id & 1) return;
   1.103 +	MapImpl::add(key);
   1.104 +      }
   1.105 +
   1.106 +
   1.107 +    };  
   1.108 +  };
   1.109 +}
   1.110 +#endif