1.1 --- a/src/include/maps.h Thu May 06 09:26:23 2004 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,129 +0,0 @@
1.4 -// -*- C++ -*- //
1.5 -#ifndef HUGO_MAPS_H
1.6 -#define HUGO_MAPS_H
1.7 -
1.8 -///\file
1.9 -///\brief Miscellaneous property maps
1.10 -///
1.11 -///\todo This file has the same name as the concept file in skeletons,
1.12 -/// and this is not easily detectable in docs...
1.13 -
1.14 -#include <map>
1.15 -
1.16 -namespace hugo {
1.17 -
1.18 - /// Null map. (aka DoNothingMap)
1.19 -
1.20 - /// If you have to provide a map only for its type definitions,
1.21 - /// or if you have to provide a writable map, but will not use the
1.22 - /// data written to it...
1.23 - template<typename K, typename T>
1.24 - class NullMap
1.25 - {
1.26 - public:
1.27 - typedef K KeyType;
1.28 - typedef T ValueType;
1.29 -
1.30 - T operator[](const K&) const { return T(); }
1.31 - void set(const K&, const T&) {}
1.32 - ///\bug when update is removed from map concepts by being dynamic
1.33 - ///stuffs, this line have to be removed.
1.34 - void update() { }
1.35 - };
1.36 -
1.37 -
1.38 - /// Constant map.
1.39 -
1.40 - /// This is a readable map which assignes a specified value to each key.
1.41 - /// In other aspects it is equivalent to the \ref NullMap
1.42 - template<typename K, typename T>
1.43 - class ConstMap
1.44 - {
1.45 - T v;
1.46 - public:
1.47 - typedef K KeyType;
1.48 - typedef T ValueType;
1.49 -
1.50 - ConstMap() {}
1.51 - ConstMap(const T &_v) : v(_v) {}
1.52 -
1.53 - T operator[](const K&) const { return v; }
1.54 - void set(const K&, const T&) {}
1.55 -
1.56 - template<typename T1>
1.57 - struct rebind {
1.58 - typedef ConstMap<K,T1> other;
1.59 - };
1.60 -
1.61 - template<typename T1>
1.62 - ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
1.63 - };
1.64 -
1.65 -
1.66 -
1.67 - /// \c std::map wrapper
1.68 -
1.69 - /// This is essentially a wrapper for \c std::map. With addition that
1.70 - /// you can specify a default value different from \c ValueType() .
1.71 - ///
1.72 - /// \todo Provide allocator parameter...
1.73 - template <typename Key, typename T, typename Compare = std::less<Key> >
1.74 - class StdMap : public std::map<Key,T,Compare> {
1.75 - typedef std::map<Key,T,Compare> parent;
1.76 - T v;
1.77 - typedef typename parent::value_type PairType;
1.78 -
1.79 - public:
1.80 - typedef Key KeyType;
1.81 - typedef T ValueType;
1.82 - typedef T& ReferenceType;
1.83 - typedef const T& ConstReferenceType;
1.84 -
1.85 -
1.86 - StdMap() : v() {}
1.87 - /// Constructor with specified default value
1.88 - StdMap(const T& _v) : v(_v) {}
1.89 -
1.90 - /// \brief Constructs the map from an appropriate std::map.
1.91 - ///
1.92 - /// \warning Inefficient: copies the content of \c m !
1.93 - StdMap(const parent &m) : parent(m) {}
1.94 - /// \brief Constructs the map from an appropriate std::map, and explicitly
1.95 - /// specifies a default value.
1.96 - ///
1.97 - /// \warning Inefficient: copies the content of \c m !
1.98 - StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
1.99 -
1.100 - template<typename T1, typename Comp1>
1.101 - StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) {
1.102 - //FIXME;
1.103 - }
1.104 -
1.105 - ReferenceType operator[](const Key &k) {
1.106 - return insert(PairType(k,v)).first -> second;
1.107 - }
1.108 - ConstReferenceType operator[](const Key &k) const {
1.109 - typename parent::iterator i = lower_bound(k);
1.110 - if (i == parent::end() || parent::key_comp()(k, (*i).first))
1.111 - return v;
1.112 - return (*i).second;
1.113 - }
1.114 - void set(const Key &k, const T &t) {
1.115 - parent::operator[](k) = t;
1.116 - }
1.117 -
1.118 - /// Changes the default value of the map.
1.119 - /// \return Returns the previous default value.
1.120 - ///
1.121 - /// \warning The value of some keys (which has alredy been queried, but
1.122 - /// the value has been unchanged from the default) may change!
1.123 - T setDefault(const T &_v) { T old=v; v=_v; return old; }
1.124 -
1.125 - template<typename T1>
1.126 - struct rebind {
1.127 - typedef StdMap<Key,T1,Compare> other;
1.128 - };
1.129 - };
1.130 -
1.131 -}
1.132 -#endif // HUGO_MAPS_H