Added missing inheritances and map-creator functions.
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 07 Jan 2008 23:36:33 +0100
changeset 45bc69cdfe171c
parent 43 17e76967c49f
child 46 b6dd98b57d71
Added missing inheritances and map-creator functions.
lemon/maps.h
     1.1 --- a/lemon/maps.h	Mon Jan 07 16:24:39 2008 +0100
     1.2 +++ b/lemon/maps.h	Mon Jan 07 23:36:33 2008 +0100
     1.3 @@ -163,21 +163,23 @@
     1.4    ///This is essentially a wrapper for \c std::map with addition that
     1.5    ///you can specify a default value different from \c Value().
     1.6    template <typename K, typename T, typename Compare = std::less<K> >
     1.7 -  class StdMap {
     1.8 +  class StdMap : public MapBase<K, T> {
     1.9      template <typename K1, typename T1, typename C1>
    1.10      friend class StdMap;
    1.11    public:
    1.12  
    1.13 -    typedef True ReferenceMapTag;
    1.14 +    typedef MapBase<K, T> Parent;
    1.15      ///\e
    1.16 -    typedef K Key;
    1.17 +    typedef typename Parent::Key Key;
    1.18      ///\e
    1.19 -    typedef T Value;
    1.20 +    typedef typename Parent::Value Value;
    1.21      ///\e
    1.22      typedef T& Reference;
    1.23      ///\e
    1.24      typedef const T& ConstReference;
    1.25  
    1.26 +    typedef True ReferenceMapTag;
    1.27 +
    1.28    private:
    1.29      
    1.30      typedef std::map<K, T, Compare> Map;
    1.31 @@ -239,6 +241,27 @@
    1.32      }    
    1.33  
    1.34    };
    1.35 +  
    1.36 +  ///Returns a \ref StdMap class
    1.37 +
    1.38 +  ///This function just returns a \ref StdMap class with specified 
    1.39 +  ///default value.
    1.40 +  ///\relates StdMap
    1.41 +  template<typename K, typename V, typename Compare = std::less<K> > 
    1.42 +  inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
    1.43 +    return StdMap<K, V, Compare>(value);
    1.44 +  }
    1.45 +
    1.46 +  ///Returns a \ref StdMap class created from an appropriate std::map
    1.47 +
    1.48 +  ///This function just returns a \ref StdMap class created from an 
    1.49 +  ///appropriate std::map.
    1.50 +  ///\relates StdMap
    1.51 +  template<typename K, typename V, typename Compare = std::less<K> > 
    1.52 +  inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 
    1.53 +                                       const V& value = V() ) {
    1.54 +    return StdMap<K, V, Compare>(map, value);
    1.55 +  }
    1.56  
    1.57    /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
    1.58    ///
    1.59 @@ -249,23 +272,25 @@
    1.60    ///
    1.61    /// \todo Revise its name
    1.62    template <typename T>
    1.63 -  class IntegerMap {
    1.64 +  class IntegerMap : public MapBase<int, T> {
    1.65  
    1.66      template <typename T1>
    1.67      friend class IntegerMap;
    1.68  
    1.69    public:
    1.70  
    1.71 -    typedef True ReferenceMapTag;
    1.72 +    typedef MapBase<int, T> Parent;
    1.73      ///\e
    1.74 -    typedef int Key;
    1.75 +    typedef typename Parent::Key Key;
    1.76      ///\e
    1.77 -    typedef T Value;
    1.78 +    typedef typename Parent::Value Value;
    1.79      ///\e
    1.80      typedef T& Reference;
    1.81      ///\e
    1.82      typedef const T& ConstReference;
    1.83  
    1.84 +    typedef True ReferenceMapTag;
    1.85 +
    1.86    private:
    1.87      
    1.88      typedef std::vector<T> Vector;
    1.89 @@ -313,6 +338,15 @@
    1.90      }
    1.91  
    1.92    };
    1.93 +  
    1.94 +  ///Returns an \ref IntegerMap class
    1.95 +
    1.96 +  ///This function just returns an \ref IntegerMap class.
    1.97 +  ///\relates IntegerMap
    1.98 +  template<typename T>
    1.99 +  inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
   1.100 +    return IntegerMap<T>(size, value);
   1.101 +  }
   1.102  
   1.103    /// @}
   1.104  
   1.105 @@ -405,6 +439,15 @@
   1.106      ///\e
   1.107      Value operator[](Key k) const {return m[k];}
   1.108    };
   1.109 +  
   1.110 +  ///Returns a \ref SimpleMap class
   1.111 +
   1.112 +  ///This function just returns a \ref SimpleMap class.
   1.113 +  ///\relates SimpleMap
   1.114 +  template<typename M>
   1.115 +  inline SimpleMap<M> simpleMap(const M &m) {
   1.116 +    return SimpleMap<M>(m);
   1.117 +  }
   1.118  
   1.119    ///Simple writable wrapping of a map
   1.120  
   1.121 @@ -433,6 +476,15 @@
   1.122      void set(Key k, const Value& c) { m.set(k, c); }
   1.123    };
   1.124  
   1.125 +  ///Returns a \ref SimpleWriteMap class
   1.126 +
   1.127 +  ///This function just returns a \ref SimpleWriteMap class.
   1.128 +  ///\relates SimpleWriteMap
   1.129 +  template<typename M>
   1.130 +  inline SimpleWriteMap<M> simpleWriteMap(M &m) {
   1.131 +    return SimpleWriteMap<M>(m);
   1.132 +  }
   1.133 +
   1.134    ///Sum of two maps
   1.135  
   1.136    ///This \c concepts::ReadMap "read only map" returns the sum of the two