lemon/concepts/maps.h
changeset 2564 3250756f5add
parent 2553 bfced05fa852
     1.1 --- a/lemon/concepts/maps.h	Tue Feb 05 11:24:32 2008 +0000
     1.2 +++ b/lemon/concepts/maps.h	Tue Feb 05 12:41:05 2008 +0000
     1.3 @@ -34,17 +34,23 @@
     1.4      /// @{
     1.5  
     1.6      /// Readable map concept
     1.7 +
     1.8 +    /// Readable map concept.
     1.9 +    ///
    1.10      template<typename K, typename T>
    1.11      class ReadMap
    1.12      {
    1.13      public:
    1.14 -      /// Map's key type.
    1.15 +      /// The key type of the map.
    1.16        typedef K Key;    
    1.17 -      /// Map's value type. (The type of objects associated with the keys).
    1.18 +      /// The value type of the map. (The type of objects associated with the keys).
    1.19        typedef T Value;
    1.20  
    1.21 -      // \bug Value don't need to be default constructible.
    1.22        /// Returns the value associated with a key.
    1.23 +
    1.24 +      /// Returns the value associated with a key.
    1.25 +      /// \bug Value shouldn't need to be default constructible.
    1.26 +      ///
    1.27        Value operator[](const Key &) const {return Value();}
    1.28  
    1.29        template<typename _ReadMap>
    1.30 @@ -69,13 +75,16 @@
    1.31  
    1.32  
    1.33      /// Writable map concept
    1.34 +    
    1.35 +    /// Writable map concept.
    1.36 +    ///
    1.37      template<typename K, typename T>
    1.38      class WriteMap
    1.39      {
    1.40      public:
    1.41 -      /// Map's key type.
    1.42 +      /// The key type of the map.
    1.43        typedef K Key;    
    1.44 -      /// Map's value type. (The type of objects associated with the keys).
    1.45 +      /// The value type of the map. (The type of objects associated with the keys).
    1.46        typedef T Value;
    1.47  
    1.48        /// Sets the value associated with a key.
    1.49 @@ -105,15 +114,18 @@
    1.50        };
    1.51      };
    1.52  
    1.53 -    ///Read/Writable map concept
    1.54 +    /// Read/writable map concept
    1.55 +    
    1.56 +    /// Read/writable map concept.
    1.57 +    ///
    1.58      template<typename K, typename T>
    1.59      class ReadWriteMap : public ReadMap<K,T>,
    1.60 -			    public WriteMap<K,T>
    1.61 +			 public WriteMap<K,T>
    1.62      {
    1.63      public:
    1.64 -      /// Map's key type.
    1.65 +      /// The key type of the map.
    1.66        typedef K Key;    
    1.67 -      /// Map's value type. (The type of objects associated with the keys).
    1.68 +      /// The value type of the map. (The type of objects associated with the keys).
    1.69        typedef T Value;
    1.70  
    1.71        /// Returns the value associated with a key.
    1.72 @@ -132,39 +144,41 @@
    1.73    
    1.74    
    1.75      ///Dereferable map concept
    1.76 +    
    1.77 +    /// Dereferable map concept.
    1.78 +    ///
    1.79 +    /// \todo Rethink this concept.
    1.80      template<typename K, typename T, typename R, typename CR>
    1.81      class ReferenceMap : public ReadWriteMap<K,T>
    1.82      {
    1.83      public:
    1.84        /// Tag for reference maps.
    1.85        typedef True ReferenceMapTag;
    1.86 -      /// Map's key type.
    1.87 +      /// The key type of the map.
    1.88        typedef K Key;    
    1.89 -      /// Map's value type. (The type of objects associated with the keys).
    1.90 +      /// The value type of the map. (The type of objects associated with the keys).
    1.91        typedef T Value;
    1.92 -      /// Map's reference type.
    1.93 +      /// The reference type of the map.
    1.94        typedef R Reference;
    1.95 -      /// Map's const reference type.
    1.96 +      /// The const reference type of the map.
    1.97        typedef CR ConstReference;
    1.98  
    1.99      protected:
   1.100        Value tmp;
   1.101      public:
   1.102  
   1.103 -      ///Returns a reference to the value associated to a key.
   1.104 +      ///Returns a reference to the value associated with a key.
   1.105        Reference operator[](const Key &) { return tmp; }
   1.106 -      ///Returns a const reference to the value associated to a key.
   1.107 -      ConstReference operator[](const Key &) const
   1.108 -      { return tmp; }
   1.109 +      ///Returns a const reference to the value associated with a key.
   1.110 +      ConstReference operator[](const Key &) const { return tmp; }
   1.111        /// Sets the value associated with a key.
   1.112        void set(const Key &k,const Value &t) { operator[](k)=t; }
   1.113  
   1.114 -      // \todo rethink this concept
   1.115        template<typename _ReferenceMap>
   1.116 -      struct ReferenceMapConcept {
   1.117 +      struct Constraints {
   1.118  
   1.119  	void constraints() {
   1.120 -	  checkConcept<ReadWriteMap, _ReferenceMap >();
   1.121 +	  checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
   1.122  	  m[key] = val;
   1.123  	  val  = m[key];
   1.124  	  m[key] = ref;
   1.125 @@ -177,10 +191,10 @@
   1.126  
   1.127  	typename _ReferenceMap::Key& own_key;
   1.128  	typename _ReferenceMap::Value& own_val;
   1.129 -	typename _ReferenceMap::Reference& own_ref;
   1.130 +	typename _ReferenceMap::Reference own_ref;
   1.131  	Key& key;
   1.132  	Value& val;
   1.133 -	Reference& ref;
   1.134 +	Reference ref;
   1.135  	_ReferenceMap& m;
   1.136        };
   1.137      };
   1.138 @@ -188,5 +202,7 @@
   1.139      // @}
   1.140  
   1.141    } //namespace concepts
   1.142 +
   1.143  } //namespace lemon
   1.144 +
   1.145  #endif // LEMON_CONCEPT_MAPS_H