src/hugo/maps.h
changeset 921 818510fa3d99
parent 920 2d6c8075d9d0
child 922 e816fac59f6d
     1.1 --- a/src/hugo/maps.h	Wed Sep 29 14:12:26 2004 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,176 +0,0 @@
     1.4 -/* -*- C++ -*-
     1.5 - * src/hugo/maps.h - Part of HUGOlib, a generic C++ optimization library
     1.6 - *
     1.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
     1.9 - *
    1.10 - * Permission to use, modify and distribute this software is granted
    1.11 - * provided that this copyright notice appears in all copies. For
    1.12 - * precise terms see the accompanying LICENSE file.
    1.13 - *
    1.14 - * This software is provided "AS IS" with no warranty of any kind,
    1.15 - * express or implied, and with no claim as to its suitability for any
    1.16 - * purpose.
    1.17 - *
    1.18 - */
    1.19 -
    1.20 -#ifndef HUGO_MAPS_H
    1.21 -#define HUGO_MAPS_H
    1.22 -
    1.23 -///\file
    1.24 -///\brief Miscellaneous property maps
    1.25 -///
    1.26 -///\todo This file has the same name as the concept file in skeletons,
    1.27 -/// and this is not easily detectable in docs...
    1.28 -
    1.29 -#include <map>
    1.30 -
    1.31 -namespace hugo {
    1.32 -
    1.33 -  /// Base class of maps.
    1.34 -
    1.35 -  /// Base class of maps.
    1.36 -  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    1.37 -  template<typename K, typename T>
    1.38 -  class MapBase
    1.39 -  {
    1.40 -  public:
    1.41 -    ///\e
    1.42 -    typedef K KeyType;
    1.43 -    ///\e
    1.44 -    typedef T ValueType;
    1.45 -  };
    1.46 -
    1.47 -  /// Null map. (a.k.a. DoNothingMap)
    1.48 -
    1.49 -  /// If you have to provide a map only for its type definitions,
    1.50 -  /// or if you have to provide a writable map, but
    1.51 -  /// data written to it will sent to <tt>/dev/null</tt>...
    1.52 -  template<typename K, typename T>
    1.53 -  class NullMap : public MapBase<K,T>
    1.54 -  {
    1.55 -  public:
    1.56 -
    1.57 -    /// Gives back a default constructed element.
    1.58 -    T operator[](const K&) const { return T(); }
    1.59 -    /// Absorbs the value.
    1.60 -    void set(const K&, const T&) {}
    1.61 -  };
    1.62 -
    1.63 -
    1.64 -  /// Constant map.
    1.65 -
    1.66 -  /// This is a readable map which assigns a specified value to each key.
    1.67 -  /// In other aspects it is equivalent to the \ref NullMap.
    1.68 -  /// \todo set could be used to set the value.
    1.69 -  template<typename K, typename T>
    1.70 -  class ConstMap : public MapBase<K,T>
    1.71 -  {
    1.72 -    T v;
    1.73 -  public:
    1.74 -
    1.75 -    /// Default constructor
    1.76 -
    1.77 -    /// The value of the map will be uninitialized. 
    1.78 -    /// (More exactly it will be default constructed.)
    1.79 -    ConstMap() {}
    1.80 -    ///\e
    1.81 -
    1.82 -    /// \param _v The initial value of the map.
    1.83 -    ///
    1.84 -    ConstMap(const T &_v) : v(_v) {}
    1.85 -
    1.86 -    T operator[](const K&) const { return v; }
    1.87 -    void set(const K&, const T&) {}
    1.88 -
    1.89 -    template<typename T1>
    1.90 -    struct rebind {
    1.91 -      typedef ConstMap<K,T1> other;
    1.92 -    };
    1.93 -
    1.94 -    template<typename T1>
    1.95 -    ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
    1.96 -  };
    1.97 -
    1.98 -  //to document later
    1.99 -  template<typename T, T v>
   1.100 -  struct Const { };
   1.101 -  //to document later
   1.102 -  template<typename K, typename V, V v>
   1.103 -  class ConstMap<K, Const<V, v> > : public MapBase<K, V>
   1.104 -  {
   1.105 -  public:
   1.106 -    ConstMap() { }
   1.107 -    V operator[](const K&) const { return v; }
   1.108 -    void set(const K&, const V&) { }
   1.109 -  };
   1.110 -  //to document later
   1.111 -  typedef Const<bool, true> True;
   1.112 -  typedef Const<bool, false> False;
   1.113 -
   1.114 -  /// \c std::map wrapper
   1.115 -
   1.116 -  /// This is essentially a wrapper for \c std::map. With addition that
   1.117 -  /// you can specify a default value different from \c ValueType() .
   1.118 -  ///
   1.119 -  /// \todo Provide allocator parameter...
   1.120 -  template <typename Key, typename T, typename Compare = std::less<Key> >
   1.121 -  class StdMap : public std::map<Key,T,Compare> {
   1.122 -    typedef std::map<Key,T,Compare> parent;
   1.123 -    T v;
   1.124 -    typedef typename parent::value_type PairType;
   1.125 -
   1.126 -  public:
   1.127 -    typedef Key KeyType;
   1.128 -    typedef T ValueType;
   1.129 -    typedef T& ReferenceType;
   1.130 -    typedef const T& ConstReferenceType;
   1.131 -
   1.132 -
   1.133 -    StdMap() : v() {}
   1.134 -    /// Constructor with specified default value
   1.135 -    StdMap(const T& _v) : v(_v) {}
   1.136 -
   1.137 -    /// \brief Constructs the map from an appropriate std::map.
   1.138 -    ///
   1.139 -    /// \warning Inefficient: copies the content of \c m !
   1.140 -    StdMap(const parent &m) : parent(m) {}
   1.141 -    /// \brief Constructs the map from an appropriate std::map, and explicitly
   1.142 -    /// specifies a default value.
   1.143 -    ///
   1.144 -    /// \warning Inefficient: copies the content of \c m !
   1.145 -    StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
   1.146 -    
   1.147 -    template<typename T1, typename Comp1>
   1.148 -    StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
   1.149 -      //FIXME; 
   1.150 -    }
   1.151 -
   1.152 -    ReferenceType operator[](const Key &k) {
   1.153 -      return insert(PairType(k,v)).first -> second;
   1.154 -    }
   1.155 -    ConstReferenceType operator[](const Key &k) const {
   1.156 -      typename parent::iterator i = lower_bound(k);
   1.157 -      if (i == parent::end() || parent::key_comp()(k, (*i).first))
   1.158 -	return v;
   1.159 -      return (*i).second;
   1.160 -    }
   1.161 -    void set(const Key &k, const T &t) {
   1.162 -      parent::operator[](k) = t;
   1.163 -    }
   1.164 -
   1.165 -    /// Changes the default value of the map.
   1.166 -    /// \return Returns the previous default value.
   1.167 -    ///
   1.168 -    /// \warning The value of some keys (which has already been queried, but
   1.169 -    /// the value has been unchanged from the default) may change!
   1.170 -    T setDefault(const T &_v) { T old=v; v=_v; return old; }
   1.171 -
   1.172 -    template<typename T1>
   1.173 -    struct rebind {
   1.174 -      typedef StdMap<Key,T1,Compare> other;
   1.175 -    };
   1.176 -  };
   1.177 -  
   1.178 -}
   1.179 -#endif // HUGO_MAPS_H