src/lemon/maps.h
changeset 1011 5bd6c7671c9e
parent 977 48962802d168
child 1041 9d503ce002db
equal deleted inserted replaced
2:edc05caebb60 3:85ce3d7b573c
    34   template<typename K, typename T>
    34   template<typename K, typename T>
    35   class MapBase
    35   class MapBase
    36   {
    36   {
    37   public:
    37   public:
    38     ///\e
    38     ///\e
    39     typedef K KeyType;
    39     typedef K Key;
    40     ///\e
    40     ///\e
    41     typedef T ValueType;
    41     typedef T Value;
    42   };
    42   };
    43 
    43 
    44   /// Null map. (a.k.a. DoNothingMap)
    44   /// Null map. (a.k.a. DoNothingMap)
    45 
    45 
    46   /// If you have to provide a map only for its type definitions,
    46   /// If you have to provide a map only for its type definitions,
   106   };
   106   };
   107 
   107 
   108   /// \c std::map wrapper
   108   /// \c std::map wrapper
   109 
   109 
   110   /// This is essentially a wrapper for \c std::map. With addition that
   110   /// This is essentially a wrapper for \c std::map. With addition that
   111   /// you can specify a default value different from \c ValueType() .
   111   /// you can specify a default value different from \c Value() .
   112   ///
   112   ///
   113   /// \todo Provide allocator parameter...
   113   /// \todo Provide allocator parameter...
   114   template <typename Key, typename T, typename Compare = std::less<Key> >
   114   template <typename K, typename T, typename Compare = std::less<K> >
   115   class StdMap : public std::map<Key,T,Compare> {
   115   class StdMap : public std::map<K,T,Compare> {
   116     typedef std::map<Key,T,Compare> parent;
   116     typedef std::map<K,T,Compare> parent;
   117     T v;
   117     T v;
   118     typedef typename parent::value_type PairType;
   118     typedef typename parent::value_type PairType;
   119 
   119 
   120   public:
   120   public:
   121     typedef Key KeyType;
   121     typedef K Key;
   122     typedef T ValueType;
   122     typedef T Value;
   123     typedef T& ReferenceType;
   123     typedef T& Reference;
   124     typedef const T& ConstReferenceType;
   124     typedef const T& ConstReference;
   125 
   125 
   126 
   126 
   127     StdMap() : v() {}
   127     StdMap() : v() {}
   128     /// Constructor with specified default value
   128     /// Constructor with specified default value
   129     StdMap(const T& _v) : v(_v) {}
   129     StdMap(const T& _v) : v(_v) {}
   141     template<typename T1, typename Comp1>
   141     template<typename T1, typename Comp1>
   142     StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
   142     StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
   143       //FIXME; 
   143       //FIXME; 
   144     }
   144     }
   145 
   145 
   146     ReferenceType operator[](const Key &k) {
   146     Reference operator[](const Key &k) {
   147       return insert(PairType(k,v)).first -> second;
   147       return insert(PairType(k,v)).first -> second;
   148     }
   148     }
   149     ConstReferenceType operator[](const Key &k) const {
   149     ConstReference operator[](const Key &k) const {
   150       typename parent::iterator i = lower_bound(k);
   150       typename parent::iterator i = lower_bound(k);
   151       if (i == parent::end() || parent::key_comp()(k, (*i).first))
   151       if (i == parent::end() || parent::key_comp()(k, (*i).first))
   152 	return v;
   152 	return v;
   153       return (*i).second;
   153       return (*i).second;
   154     }
   154     }