(none)
authordeba
Fri, 03 Sep 2004 15:11:17 +0000
changeset 7986d1abeb62dd3
parent 797 a76d8d52b25c
child 799 3393abe30678
(none)
src/hugo/default_map_factory.h
src/hugo/full_graph.h
src/hugo/list_graph.h
src/hugo/smart_graph.h
src/hugo/sym_map_factory.h
src/hugo/vector_map_factory.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/hugo/default_map_factory.h	Fri Sep 03 15:11:17 2004 +0000
     1.3 @@ -0,0 +1,143 @@
     1.4 +// -*- c++ -*-
     1.5 +#ifndef DEFAULT_MAP_FACTORY_H
     1.6 +#define DEFAULT_MAP_FACTORY_H
     1.7 +
     1.8 +
     1.9 +#include <hugo/array_map_factory.h>
    1.10 +#include <hugo/vector_map_factory.h>
    1.11 +
    1.12 +namespace hugo {
    1.13 +
    1.14 +#define DEFAULT_MAP_BODY(Factory, Val) \
    1.15 +  { \
    1.16 +    typedef typename Factory<MapRegistry>::template Map<Val> MapImpl; \
    1.17 +  \
    1.18 +  public: \
    1.19 +  \
    1.20 +    typedef typename MapRegistry::Graph Graph; \
    1.21 +    typedef typename MapRegistry::Key Key; \
    1.22 +    typedef typename MapRegistry::KeyIt KeyIt; \
    1.23 +    typedef Val Value; \
    1.24 +  \
    1.25 +    typedef typename MapRegistry::MapBase MapBase; \
    1.26 +  \
    1.27 +    DefaultMap() : MapImpl() {} \
    1.28 +  \
    1.29 +    DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \
    1.30 +  \
    1.31 +    DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    1.32 +      : MapImpl(g, r, v) {} \
    1.33 +  \
    1.34 +    DefaultMap(const DefaultMap& copy) \
    1.35 +      : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    1.36 +  \
    1.37 +    template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {} \
    1.38 +  \
    1.39 +    DefaultMap& operator=(const DefaultMap& copy) { \
    1.40 +      MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
    1.41 +      return *this; \
    1.42 +    } \
    1.43 +  \
    1.44 +    template <typename CMap> DefaultMap& operator=(const CMap& copy) { \
    1.45 +      MapImpl::operator=(copy); \
    1.46 +      return *this; \
    1.47 +    } \
    1.48 +  \
    1.49 +  };
    1.50 +
    1.51 +
    1.52 +  template <typename MapRegistry, typename Type>
    1.53 +  class DefaultMap : public ArrayMapFactory<MapRegistry>::template Map<Type> 
    1.54 +  DEFAULT_MAP_BODY(ArrayMapFactory, Type);
    1.55 +
    1.56 +  template <typename MapRegistry>
    1.57 +  class DefaultMap<MapRegistry, bool> 
    1.58 +    : public VectorMapFactory<MapRegistry>::template Map<bool> 
    1.59 +  DEFAULT_MAP_BODY(VectorMapFactory, bool);
    1.60 +
    1.61 +  template <typename MapRegistry>
    1.62 +  class DefaultMap<MapRegistry, char> 
    1.63 +    : public VectorMapFactory<MapRegistry>::template Map<char> 
    1.64 +  DEFAULT_MAP_BODY(VectorMapFactory, char);
    1.65 +
    1.66 +  template <typename MapRegistry>
    1.67 +  class DefaultMap<MapRegistry, int> 
    1.68 +    : public VectorMapFactory<MapRegistry>::template Map<int> 
    1.69 +  DEFAULT_MAP_BODY(VectorMapFactory, int);
    1.70 +
    1.71 +  template <typename MapRegistry>
    1.72 +  class DefaultMap<MapRegistry, short> 
    1.73 +    : public VectorMapFactory<MapRegistry>::template Map<short> 
    1.74 +  DEFAULT_MAP_BODY(VectorMapFactory, short);
    1.75 +
    1.76 +  template <typename MapRegistry>
    1.77 +  class DefaultMap<MapRegistry, long> 
    1.78 +    : public VectorMapFactory<MapRegistry>::template Map<long> 
    1.79 +  DEFAULT_MAP_BODY(VectorMapFactory, long);
    1.80 +
    1.81 +  template <typename MapRegistry>
    1.82 +  class DefaultMap<MapRegistry, float> 
    1.83 +    : public VectorMapFactory<MapRegistry>::template Map<float> 
    1.84 +  DEFAULT_MAP_BODY(VectorMapFactory, float);
    1.85 +
    1.86 +  template <typename MapRegistry>
    1.87 +  class DefaultMap<MapRegistry, double> 
    1.88 +    : public VectorMapFactory<MapRegistry>::template Map<double> 
    1.89 +  DEFAULT_MAP_BODY(VectorMapFactory, double);
    1.90 +
    1.91 +  template <typename MapRegistry>
    1.92 +  class DefaultMap<MapRegistry, long double> 
    1.93 +    : public VectorMapFactory<MapRegistry>::template Map<long double> 
    1.94 +  DEFAULT_MAP_BODY(VectorMapFactory, long double);
    1.95 +
    1.96 +  template <typename MapRegistry, typename Type>
    1.97 +  class DefaultMap<MapRegistry, Type*>
    1.98 +    : public VectorMapFactory<MapRegistry>::template Map<Type*> 
    1.99 +  DEFAULT_MAP_BODY(VectorMapFactory, Type*);
   1.100 +
   1.101 +  template <typename MapRegistry>
   1.102 +  class DefaultMapFactory {
   1.103 +		
   1.104 +  public:
   1.105 +		
   1.106 +    typedef typename MapRegistry::Graph Graph;
   1.107 +    typedef typename MapRegistry::Key Key;
   1.108 +    typedef typename MapRegistry::KeyIt KeyIt;
   1.109 +
   1.110 +    typedef typename MapRegistry::MapBase MapBase;
   1.111 +
   1.112 +    template <typename V> 
   1.113 +    class Map : public DefaultMap<MapRegistry, V> {
   1.114 +
   1.115 +      typedef DefaultMap<MapRegistry, V> MapImpl;
   1.116 +
   1.117 +    public:
   1.118 +      
   1.119 +      typedef V Value;
   1.120 +
   1.121 +      Map() : MapImpl() {}
   1.122 +
   1.123 +      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
   1.124 +
   1.125 +      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
   1.126 +
   1.127 +      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
   1.128 +
   1.129 +      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
   1.130 +
   1.131 +      Map& operator=(const Map& copy) {
   1.132 +	MapImpl::operator=(static_cast<const MapImpl&>(copy));
   1.133 +	return *this;
   1.134 +      }
   1.135 +
   1.136 +      template <typename CMap> Map& operator=(const CMap& copy) {
   1.137 +	MapImpl::operator=(copy);
   1.138 +	return *this;
   1.139 +      }
   1.140 +
   1.141 +    };
   1.142 +
   1.143 +  };
   1.144 +}
   1.145 +
   1.146 +#endif
     2.1 --- a/src/hugo/full_graph.h	Fri Sep 03 14:26:03 2004 +0000
     2.2 +++ b/src/hugo/full_graph.h	Fri Sep 03 15:11:17 2004 +0000
     2.3 @@ -13,7 +13,7 @@
     2.4  #include <hugo/invalid.h>
     2.5  
     2.6  #include <hugo/map_registry.h>
     2.7 -#include <hugo/array_map_factory.h>
     2.8 +#include <hugo/default_map_factory.h>
     2.9  
    2.10  namespace hugo {
    2.11  
    2.12 @@ -48,7 +48,7 @@
    2.13      class InEdgeIt;
    2.14      
    2.15      CREATE_MAP_REGISTRIES;
    2.16 -    CREATE_MAPS(ArrayMapFactory);
    2.17 +    CREATE_MAPS(DefaultMapFactory);
    2.18      
    2.19    public:
    2.20  
     3.1 --- a/src/hugo/list_graph.h	Fri Sep 03 14:26:03 2004 +0000
     3.2 +++ b/src/hugo/list_graph.h	Fri Sep 03 15:11:17 2004 +0000
     3.3 @@ -13,7 +13,7 @@
     3.4  #include <hugo/invalid.h>
     3.5  
     3.6  #include <hugo/map_registry.h>
     3.7 -#include <hugo/array_map_factory.h>
     3.8 +#include <hugo/default_map_factory.h>
     3.9  
    3.10  #include <hugo/sym_map_factory.h>
    3.11  
    3.12 @@ -80,7 +80,7 @@
    3.13      class InEdgeIt;
    3.14  
    3.15      CREATE_MAP_REGISTRIES;
    3.16 -    CREATE_MAPS(ArrayMapFactory);
    3.17 +    CREATE_MAPS(DefaultMapFactory);
    3.18  
    3.19    public:
    3.20  
    3.21 @@ -425,7 +425,7 @@
    3.22      KEEP_EDGE_MAP(ListGraph);
    3.23  
    3.24      CREATE_SYM_EDGE_MAP_REGISTRY;
    3.25 -    CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
    3.26 +    CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
    3.27      IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
    3.28  
    3.29      SymListGraph() : ListGraph() { }
    3.30 @@ -508,7 +508,7 @@
    3.31      class InEdgeIt;
    3.32      
    3.33      CREATE_MAP_REGISTRIES;
    3.34 -    CREATE_MAPS(ArrayMapFactory);
    3.35 +    CREATE_MAPS(DefaultMapFactory);
    3.36      
    3.37    public:
    3.38  
    3.39 @@ -805,7 +805,7 @@
    3.40  
    3.41  
    3.42      CREATE_EDGE_MAP_REGISTRY;
    3.43 -    CREATE_EDGE_MAP_FACTORY(ArrayMapFactory);
    3.44 +    CREATE_EDGE_MAP_FACTORY(DefaultMapFactory);
    3.45      IMPORT_EDGE_MAP(EdgeMapFactory);
    3.46      
    3.47      
     4.1 --- a/src/hugo/smart_graph.h	Fri Sep 03 14:26:03 2004 +0000
     4.2 +++ b/src/hugo/smart_graph.h	Fri Sep 03 15:11:17 2004 +0000
     4.3 @@ -12,7 +12,7 @@
     4.4  
     4.5  #include <hugo/invalid.h>
     4.6  
     4.7 -#include <hugo/array_map_factory.h>
     4.8 +#include <hugo/default_map_factory.h>
     4.9  #include <hugo/sym_map_factory.h>
    4.10  #include <hugo/map_registry.h>
    4.11  
    4.12 @@ -73,7 +73,7 @@
    4.13      class InEdgeIt;
    4.14      
    4.15      CREATE_MAP_REGISTRIES;
    4.16 -    CREATE_MAPS(ArrayMapFactory);
    4.17 +    CREATE_MAPS(DefaultMapFactory);
    4.18      
    4.19    public:
    4.20  
    4.21 @@ -296,7 +296,7 @@
    4.22      KEEP_EDGE_MAP(SmartGraph);
    4.23  
    4.24      CREATE_SYM_EDGE_MAP_REGISTRY;
    4.25 -    CREATE_SYM_EDGE_MAP_FACTORY(ArrayMapFactory);
    4.26 +    CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
    4.27      IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
    4.28  
    4.29      SymSmartGraph() : SmartGraph() { }
    4.30 @@ -305,7 +305,9 @@
    4.31      Edge addEdge(Node u, Node v)
    4.32      {
    4.33        Edge e = SmartGraph::addEdge(u,v);
    4.34 -      SmartGraph::addEdge(v,u);
    4.35 +      Edge f = SmartGraph::addEdge(v,u);
    4.36 +      sym_edge_maps.add(e);
    4.37 +      sym_edge_maps.add(f);
    4.38        return e;
    4.39      }
    4.40  
     5.1 --- a/src/hugo/sym_map_factory.h	Fri Sep 03 14:26:03 2004 +0000
     5.2 +++ b/src/hugo/sym_map_factory.h	Fri Sep 03 15:11:17 2004 +0000
     5.3 @@ -12,7 +12,11 @@
     5.4        : EdgeIt() {}
     5.5  
     5.6      SymEdgeIt(const Graph& graph) 
     5.7 -      : EdgeIt(graph) {}
     5.8 +      : EdgeIt(graph) {
     5.9 +      while ( n != -1 && (n & 1)) {
    5.10 +	EdgeIt::operator++();
    5.11 +      }
    5.12 +    }
    5.13  
    5.14      SymEdgeIt(Invalid invalid) 
    5.15        : EdgeIt(invalid) {}
    5.16 @@ -52,7 +56,8 @@
    5.17  
    5.18        Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
    5.19  
    5.20 -      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
    5.21 +      Map(const Graph& g, MapRegistry& r, const Value& v) 
    5.22 +	: MapImpl(g, r, v) {}
    5.23  
    5.24        Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
    5.25  
     6.1 --- a/src/hugo/vector_map_factory.h	Fri Sep 03 14:26:03 2004 +0000
     6.2 +++ b/src/hugo/vector_map_factory.h	Fri Sep 03 15:11:17 2004 +0000
     6.3 @@ -17,7 +17,7 @@
     6.4    
     6.5    /** The VectorMapFactory template class is a factory class
     6.6     *  to create maps for the edge and nodes. This map factory
     6.7 -   *  use the std::vector to implement the container function.
     6.8 +   *  uses the std::vector to implement the container function.
     6.9     *
    6.10     *  The template parameter is the MapRegistry that the maps
    6.11     *  will belong to.
    6.12 @@ -42,12 +42,27 @@
    6.13       */
    6.14      template <typename V> 
    6.15      class Map : public MapBase {
    6.16 +
    6.17 +      typedef std::vector<V> Container;	
    6.18 +
    6.19      public:
    6.20  
    6.21        /// The value type of the map.
    6.22 +      typedef V ValueType;
    6.23 +
    6.24 +      /// The value type of the map.
    6.25        typedef V Value;
    6.26 +      /// The reference type of the map;
    6.27 +      typedef typename Container::reference Reference;
    6.28 +      /// The pointer type of the map;
    6.29 +      typedef typename Container::pointer Pointer;
    6.30  
    6.31 -      typedef std::vector<Value> Container;	
    6.32 +      /// The const value type of the map.
    6.33 +      typedef const Value ConstValue;
    6.34 +      /// The const reference type of the map;
    6.35 +      typedef typename Container::const_reference ConstReference;
    6.36 +      /// The pointer type of the map;
    6.37 +      typedef typename Container::const_pointer ConstPointer;
    6.38  
    6.39        /** Default constructor for the map.
    6.40         */
    6.41 @@ -64,7 +79,7 @@
    6.42        Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
    6.43  	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    6.44            int id = getGraph()->id(it);
    6.45 -	  if (id >= container.size()) {
    6.46 +	  if (id >= (int)container.size()) {
    6.47  	    container.resize(id + 1);
    6.48  	  }
    6.49  	  set(it, v);
    6.50 @@ -77,7 +92,7 @@
    6.51  	if (getGraph()) {
    6.52  	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    6.53  	    int id = getGraph()->id(it);
    6.54 -	    if (id >= container.size()) {
    6.55 +	    if (id >= (int)container.size()) {
    6.56  	      container.resize(id + 1);
    6.57  	    }
    6.58  	    set(it, copy[it]);
    6.59 @@ -95,12 +110,13 @@
    6.60  	if (getGraph()) {
    6.61  	  for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    6.62  	    int id = getGraph()->id(it);
    6.63 -	    if (id >= container.size()) {
    6.64 +	    if (id >= (int)container.size()) {
    6.65  	      container.resize(id + 1);
    6.66  	    }
    6.67  	    set(it, copy[it]);
    6.68  	  }
    6.69  	}
    6.70 +	return *this;
    6.71        }
    6.72  
    6.73        /** The destructor of the map.
    6.74 @@ -112,7 +128,11 @@
    6.75         * The subscript operator. The map can be subscripted by the
    6.76         * actual keys of the graph. 
    6.77         */
    6.78 +<<<<<<< .mine
    6.79 +      Reference operator[](const Key& key) {
    6.80 +=======
    6.81        typename Container::reference operator[](const KeyType& key) {
    6.82 +>>>>>>> .r1091
    6.83  	int id = getGraph()->id(key);
    6.84  	return container[id];
    6.85        } 
    6.86 @@ -121,7 +141,11 @@
    6.87         * The const subscript operator. The map can be subscripted by the
    6.88         * actual keys of the graph. 
    6.89         */
    6.90 +<<<<<<< .mine
    6.91 +      ConstReference operator[](const Key& key) const {
    6.92 +=======
    6.93        typename Container::const_reference operator[](const KeyType& key) const {
    6.94 +>>>>>>> .r1091
    6.95  	int id = getGraph()->id(key);
    6.96  	return container[id];
    6.97        }
    6.98 @@ -138,7 +162,7 @@
    6.99         */
   6.100        void add(const KeyType& key) {
   6.101  	int id = getGraph()->id(key);
   6.102 -	if (id >= container.size()) {
   6.103 +	if (id >= (int)container.size()) {
   6.104  	  container.resize(id + 1);
   6.105  	}
   6.106        }
   6.107 @@ -173,7 +197,7 @@
   6.108  	iterator() {}
   6.109  
   6.110  	typedef extended_pair<const KeyType&, const KeyType&, 
   6.111 -			      Value&, Value&> Reference;
   6.112 +			      Map::Reference, Map::Reference> Reference;
   6.113  
   6.114  	/** Dereference operator for map.
   6.115  	 */	 
   6.116 @@ -263,7 +287,7 @@
   6.117  	const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
   6.118        
   6.119  	typedef extended_pair<const KeyType&, const KeyType&, 
   6.120 -	  const Value&, const Value&> Reference;
   6.121 +	  Map::ConstReference, Map::ConstReference> Reference;
   6.122  
   6.123  	/** Dereference operator for map.
   6.124  	 */