Traits moved to own file
authordeba
Fri, 14 Oct 2005 10:48:34 +0000
changeset 1719674182524bd9
parent 1718 6a958ab38386
child 1720 578d8b2b76c6
Traits moved to own file
Tag for reference maps
Possibility to handle proper the return type
of the operator[]() const -- value or reference
lemon/bits/array_map.h
lemon/bits/map_iterator.h
lemon/bits/static_map.h
lemon/bits/vector_map.h
lemon/concept/maps.h
lemon/traits.h
     1.1 --- a/lemon/bits/array_map.h	Fri Oct 14 10:44:49 2005 +0000
     1.2 +++ b/lemon/bits/array_map.h	Fri Oct 14 10:48:34 2005 +0000
     1.3 @@ -48,20 +48,29 @@
     1.4  
     1.5      typedef _Item Item;
     1.6    public:
     1.7 -    typedef True AdaptibleTag;
     1.8 -		
     1.9      /// The graph type of the maps. 
    1.10      typedef _Graph Graph;
    1.11 +    /// The reference map tag.
    1.12 +    typedef True ReferenceMapTag;
    1.13 +
    1.14      /// The key type of the maps.
    1.15      typedef _Item Key;
    1.16 +    /// The value type of the map.
    1.17 +    typedef _Value Value;
    1.18 +    /// The const reference type of the map.
    1.19 +    typedef const _Value& ConstReference;
    1.20 +    /// The reference type of the map.
    1.21 +    typedef _Value& Reference;
    1.22 +
    1.23 +    typedef const Value ConstValue;
    1.24 +    typedef Value* Pointer;
    1.25 +    typedef const Value* ConstPointer;
    1.26  
    1.27      typedef AlterationNotifier<_Item> Registry;
    1.28  
    1.29      /// The MapBase of the Map which imlements the core regisitry function.
    1.30      typedef typename Registry::ObserverBase Parent;
    1.31  		
    1.32 -    /// The value type of the map.
    1.33 -    typedef _Value Value;
    1.34  
    1.35  
    1.36    private:
    1.37 @@ -70,9 +79,9 @@
    1.38  
    1.39    public:
    1.40  
    1.41 -    /// \brief Graph and Registry initialized map constructor.
    1.42 +    /// \brief Graph initialized map constructor.
    1.43      ///
    1.44 -    /// Graph and Registry initialized map constructor.
    1.45 +    /// Graph initialized map constructor.
    1.46      ArrayMap(const Graph& _g) : graph(&_g) {
    1.47        Item it;
    1.48        attach(_g.getNotifier(Item()));
     2.1 --- a/lemon/bits/map_iterator.h	Fri Oct 14 10:44:49 2005 +0000
     2.2 +++ b/lemon/bits/map_iterator.h	Fri Oct 14 10:48:34 2005 +0000
     2.3 @@ -104,8 +104,8 @@
     2.4  
     2.5      typedef typename Parent::ItemIt ItemIt;
     2.6  
     2.7 -    typedef typename ReferenceMapTraits<_Map>::Value MapValue;
     2.8 -    typedef typename ReferenceMapTraits<_Map>::Reference MapReference;
     2.9 +    typedef typename _Map::Value MapValue;
    2.10 +    typedef typename _Map::Reference MapReference;
    2.11      
    2.12    public:
    2.13  
    2.14 @@ -194,9 +194,8 @@
    2.15  
    2.16      typedef typename Parent::ItemIt ItemIt;
    2.17  
    2.18 -    typedef typename ReferenceMapTraits<_Map>::Value MapValue;
    2.19 -    typedef typename ReferenceMapTraits<_Map>::ConstReference
    2.20 -    MapReference;
    2.21 +    typedef typename _Map::Value MapValue;
    2.22 +    typedef typename _Map::ConstReference MapReference;
    2.23      
    2.24    public:
    2.25  
    2.26 @@ -353,11 +352,11 @@
    2.27      typedef typename Parent::ItemIt ItemIt;
    2.28  
    2.29      /// The value type of the iterator.
    2.30 -    typedef typename ReferenceMapTraits<Map>::Value MapValue;
    2.31 +    typedef typename Map::Value MapValue;
    2.32      /// The reference type of the iterator.
    2.33 -    typedef typename ReferenceMapTraits<Map>::Reference MapReference;
    2.34 +    typedef typename Map::Reference MapReference;
    2.35      /// The pointer type of the iterator.
    2.36 -    typedef typename ReferenceMapTraits<Map>::Pointer MapPointer;
    2.37 +    typedef typename Map::Pointer MapPointer;
    2.38  
    2.39    public:
    2.40  
    2.41 @@ -433,11 +432,11 @@
    2.42      typedef typename Parent::ItemIt ItemIt;
    2.43  
    2.44      /// The value type of the iterator.
    2.45 -    typedef typename ReferenceMapTraits<Map>::Value MapValue;
    2.46 +    typedef typename Map::Value MapValue;
    2.47      /// The reference type of the iterator.
    2.48 -    typedef typename ReferenceMapTraits<Map>::ConstReference MapReference;
    2.49 +    typedef typename Map::ConstReference MapReference;
    2.50      /// The pointer type of the iterator.
    2.51 -    typedef typename ReferenceMapTraits<Map>::ConstPointer MapPointer;
    2.52 +    typedef typename Map::ConstPointer MapPointer;
    2.53  
    2.54    public:
    2.55  
     3.1 --- a/lemon/bits/static_map.h	Fri Oct 14 10:44:49 2005 +0000
     3.2 +++ b/lemon/bits/static_map.h	Fri Oct 14 10:48:34 2005 +0000
     3.3 @@ -62,28 +62,37 @@
     3.4        }
     3.5      };
     3.6  
     3.7 -    typedef True AdaptibleTag;
     3.8 +  private:
     3.9  		
    3.10 +    typedef std::vector<_Value> Container;	
    3.11 +
    3.12 +  public:
    3.13 +
    3.14      /// The graph type of the map. 
    3.15      typedef _Graph Graph;
    3.16 +    /// The reference map tag.
    3.17 +    typedef True ReferenceMapTag;
    3.18 +
    3.19      /// The key type of the map.
    3.20      typedef _Item Key;
    3.21 -    /// The id map type of the map.
    3.22 -    typedef AlterationNotifier<_Item> Registry;
    3.23      /// The value type of the map.
    3.24      typedef _Value Value;
    3.25 +    /// The const reference type of the map.
    3.26 +    typedef typename Container::const_reference ConstReference;
    3.27 +    /// The reference type of the map.
    3.28 +    typedef typename Container::reference Reference;
    3.29 +
    3.30 +    typedef const Value ConstValue;
    3.31 +    typedef Value* Pointer;
    3.32 +    typedef const Value* ConstPointer;
    3.33 +
    3.34 +    typedef AlterationNotifier<_Item> Registry;
    3.35  
    3.36      /// The map type.
    3.37      typedef StaticMap Map;
    3.38      /// The base class of the map.
    3.39      typedef typename Registry::ObserverBase Parent;
    3.40  
    3.41 -  private:
    3.42 -		
    3.43 -    typedef std::vector<Value> Container;	
    3.44 -
    3.45 -  public:
    3.46 -
    3.47      /// \brief Constructor to attach the new map into the registry.
    3.48      ///
    3.49      /// It constructs a map and attachs it into the registry.
    3.50 @@ -141,12 +150,6 @@
    3.51  
    3.52    public:
    3.53  
    3.54 -    typedef typename Container::reference Reference;
    3.55 -    typedef typename Container::pointer Pointer;
    3.56 -    typedef const Value ConstValue;
    3.57 -    typedef typename Container::const_reference ConstReference;
    3.58 -    typedef typename Container::const_pointer ConstPointer;
    3.59 -
    3.60      /// \brief The subcript operator.
    3.61      ///
    3.62      /// The subscript operator. The map can be subscripted by the
     4.1 --- a/lemon/bits/vector_map.h	Fri Oct 14 10:44:49 2005 +0000
     4.2 +++ b/lemon/bits/vector_map.h	Fri Oct 14 10:48:34 2005 +0000
     4.3 @@ -55,31 +55,38 @@
     4.4      typename _Value
     4.5      >
     4.6    class VectorMap : public AlterationNotifier<_Item>::ObserverBase {
     4.7 +  private:
     4.8 +		
     4.9 +    /// The container type of the map.
    4.10 +    typedef std::vector<_Value> Container;	
    4.11 +
    4.12    public:
    4.13  
    4.14 -    typedef True AdaptibleTag;
    4.15 -		
    4.16      /// The graph type of the map. 
    4.17      typedef _Graph Graph;
    4.18 +    /// The reference map tag.
    4.19 +    typedef True ReferenceMapTag;
    4.20 +
    4.21      /// The key type of the map.
    4.22      typedef _Item Key;
    4.23 -    /// The id map type of the map.
    4.24 -    typedef AlterationNotifier<_Item> Registry;
    4.25      /// The value type of the map.
    4.26      typedef _Value Value;
    4.27 +    /// The const reference type of the map.
    4.28 +    typedef typename Container::const_reference ConstReference;
    4.29 +    /// The reference type of the map.
    4.30 +    typedef typename Container::reference Reference;
    4.31 +
    4.32 +    typedef const Value ConstValue;
    4.33 +    typedef Value* Pointer;
    4.34 +    typedef const Value* ConstPointer;
    4.35 +
    4.36 +    typedef AlterationNotifier<_Item> Registry;
    4.37  
    4.38      /// The map type.
    4.39      typedef VectorMap Map;
    4.40      /// The base class of the map.
    4.41      typedef typename Registry::ObserverBase Parent;
    4.42  
    4.43 -  private:
    4.44 -		
    4.45 -    /// The container type of the map.
    4.46 -    typedef std::vector<Value> Container;	
    4.47 -
    4.48 -  public:
    4.49 -
    4.50      /// The reference type of the map;
    4.51      typedef typename Container::reference Reference;
    4.52      /// The pointer type of the map;
     5.1 --- a/lemon/concept/maps.h	Fri Oct 14 10:44:49 2005 +0000
     5.2 +++ b/lemon/concept/maps.h	Fri Oct 14 10:48:34 2005 +0000
     5.3 @@ -17,6 +17,7 @@
     5.4  #ifndef LEMON_CONCEPT_MAPS_H
     5.5  #define LEMON_CONCEPT_MAPS_H
     5.6  
     5.7 +#include <lemon/utility.h>
     5.8  #include <lemon/concept_check.h>
     5.9  
    5.10  ///\ingroup concept
    5.11 @@ -97,7 +98,7 @@
    5.12  	typename _WriteMap::Value own_val;
    5.13  	Key& key;
    5.14  	typename _WriteMap::Key& own_key;
    5.15 -	WriteMap& m;
    5.16 +	_WriteMap& m;
    5.17  
    5.18        };
    5.19      };
    5.20 @@ -122,7 +123,7 @@
    5.21        struct Constraints {
    5.22  	void constraints() {
    5.23  	  checkConcept<ReadMap<K, T>, _ReadWriteMap >();
    5.24 -	  checkConcept<ReadMap<K, T>, _ReadWriteMap >();
    5.25 +	  checkConcept<WriteMap<K, T>, _ReadWriteMap >();
    5.26  	}
    5.27        };
    5.28      };
    5.29 @@ -133,6 +134,8 @@
    5.30      class ReferenceMap : public ReadWriteMap<K,T>
    5.31      {
    5.32      public:
    5.33 +      /// Tag for reference maps.
    5.34 +      typedef True ReferenceMapTag;
    5.35        /// Map's key type.
    5.36        typedef K Key;    
    5.37        /// Map's value type. (The type of objects associated with the keys).
    5.38 @@ -176,7 +179,7 @@
    5.39  	Key& key;
    5.40  	Value& val;
    5.41  	Reference& ref;
    5.42 -	ReferenceMap& m;
    5.43 +	_ReferenceMap& m;
    5.44        };
    5.45      };
    5.46  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/lemon/traits.h	Fri Oct 14 10:48:34 2005 +0000
     6.3 @@ -0,0 +1,168 @@
     6.4 +/* -*- C++ -*-
     6.5 + * lemon/traits.h - Part of LEMON, a generic C++ optimization library
     6.6 + *
     6.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6.8 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6.9 + *
    6.10 + * Permission to use, modify and distribute this software is granted
    6.11 + * provided that this copyright notice appears in all copies. For
    6.12 + * precise terms see the accompanying LICENSE file.
    6.13 + *
    6.14 + * This software is provided "AS IS" with no warranty of any kind,
    6.15 + * express or implied, and with no claim as to its suitability for any
    6.16 + * purpose.
    6.17 + *
    6.18 + */
    6.19 +
    6.20 +#ifndef LEMON_TRAITS_H
    6.21 +#define LEMON_TRAITS_H
    6.22 +
    6.23 +#include <lemon/utility.h>
    6.24 +
    6.25 +///\file
    6.26 +///\brief Traits for graphs and maps
    6.27 +///
    6.28 +
    6.29 +namespace lemon {
    6.30 +  template <typename _Graph, typename _Item>
    6.31 +  class ItemSetTraits {};
    6.32 +  
    6.33 +  template <typename _Graph>
    6.34 +  class ItemSetTraits<_Graph, typename _Graph::Node> {
    6.35 +  public:
    6.36 +    
    6.37 +    typedef _Graph Graph;
    6.38 +
    6.39 +    typedef typename Graph::Node Item;
    6.40 +    typedef typename Graph::NodeIt ItemIt;
    6.41 +
    6.42 +    template <typename _Value>
    6.43 +    class Map : public Graph::template NodeMap<_Value> {
    6.44 +    public:
    6.45 +      typedef typename Graph::template NodeMap<_Value> Parent; 
    6.46 +      typedef typename Parent::Value Value;
    6.47 +
    6.48 +      Map(const Graph& _graph) : Parent(_graph) {}
    6.49 +      Map(const Graph& _graph, const Value& _value) 
    6.50 +	: Parent(_graph, _value) {}
    6.51 +    };
    6.52 +
    6.53 +  };
    6.54 +
    6.55 +  template <typename _Graph>
    6.56 +  class ItemSetTraits<_Graph, typename _Graph::Edge> {
    6.57 +  public:
    6.58 +    
    6.59 +    typedef _Graph Graph;
    6.60 +
    6.61 +    typedef typename Graph::Edge Item;
    6.62 +    typedef typename Graph::EdgeIt ItemIt;
    6.63 +
    6.64 +    template <typename _Value>
    6.65 +    class Map : public Graph::template EdgeMap<_Value> {
    6.66 +    public:
    6.67 +      typedef typename Graph::template EdgeMap<_Value> Parent; 
    6.68 +      typedef typename Parent::Value Value;
    6.69 +
    6.70 +      Map(const Graph& _graph) : Parent(_graph) {}
    6.71 +      Map(const Graph& _graph, const Value& _value) 
    6.72 +	: Parent(_graph, _value) {}
    6.73 +    };
    6.74 +
    6.75 +  };
    6.76 +
    6.77 +  template <typename _Graph>
    6.78 +  class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
    6.79 +  public:
    6.80 +    
    6.81 +    typedef _Graph Graph;
    6.82 +
    6.83 +    typedef typename Graph::UndirEdge Item;
    6.84 +    typedef typename Graph::UndirEdgeIt ItemIt;
    6.85 +
    6.86 +    template <typename _Value>
    6.87 +    class Map : public Graph::template UndirEdgeMap<_Value> {
    6.88 +    public:
    6.89 +      typedef typename Graph::template UndirEdgeMap<_Value> Parent; 
    6.90 +      typedef typename Parent::Value Value;
    6.91 +
    6.92 +      Map(const Graph& _graph) : Parent(_graph) {}
    6.93 +      Map(const Graph& _graph, const Value& _value) 
    6.94 +	: Parent(_graph, _value) {}
    6.95 +    };
    6.96 +
    6.97 +  };
    6.98 +
    6.99 +  template <typename Map, typename Enable = void>
   6.100 +  struct MapTraits {
   6.101 +    typedef False ReferenceMapTag;
   6.102 +
   6.103 +    typedef typename Map::Key Key;
   6.104 +    typedef typename Map::Value Value;
   6.105 +
   6.106 +    typedef Value ConstReturnValue;
   6.107 +    typedef Value& ReturnValue;
   6.108 +  };
   6.109 +
   6.110 +  template <typename Map>
   6.111 +  struct MapTraits<
   6.112 +    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
   6.113 +  {
   6.114 +    typedef True ReferenceMapTag;
   6.115 +    
   6.116 +    typedef typename Map::Key Key;
   6.117 +    typedef typename Map::Value Value;
   6.118 +
   6.119 +    typedef typename Map::ConstReference ConstReturnValue;
   6.120 +    typedef typename Map::Reference ReturnValue;
   6.121 +
   6.122 +    typedef typename Map::ConstReference ConstReference; 
   6.123 +    typedef typename Map::Reference Reference;
   6.124 + };
   6.125 +
   6.126 +  // Indicators for the tags
   6.127 +
   6.128 +  template <typename Graph, typename Enable = void>
   6.129 +  struct NodeNumTagIndicator {
   6.130 +    static const bool value = false;
   6.131 +  };
   6.132 +
   6.133 +  template <typename Graph>
   6.134 +  struct NodeNumTagIndicator<
   6.135 +    Graph, 
   6.136 +    typename enable_if<typename Graph::NodeNumTag, void>::type
   6.137 +  > {
   6.138 +    static const bool value = true;
   6.139 +  };
   6.140 +
   6.141 +  template <typename Graph, typename Enable = void>
   6.142 +  struct EdgeNumTagIndicator {
   6.143 +    static const bool value = false;
   6.144 +  };
   6.145 +
   6.146 +  template <typename Graph>
   6.147 +  struct EdgeNumTagIndicator<
   6.148 +    Graph, 
   6.149 +    typename enable_if<typename Graph::EdgeNumTag, void>::type
   6.150 +  > {
   6.151 +    static const bool value = true;
   6.152 +  };
   6.153 +
   6.154 +  template <typename Graph, typename Enable = void>
   6.155 +  struct FindEdgeTagIndicator {
   6.156 +    static const bool value = false;
   6.157 +  };
   6.158 +
   6.159 +  template <typename Graph>
   6.160 +  struct FindEdgeTagIndicator<
   6.161 +    Graph, 
   6.162 +    typename enable_if<typename Graph::FindEdgeTag, void>::type
   6.163 +  > {
   6.164 +    static const bool value = true;
   6.165 +  };
   6.166 +
   6.167 +
   6.168 +
   6.169 +}
   6.170 +
   6.171 +#endif // LEMON_MAPS_H