COIN-OR::LEMON - Graph Library

Changeset 1705:3f63d9db307b in lemon-0.x


Ignore:
Timestamp:
10/05/05 15:18:51 (18 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2232
Message:

Removing smart references

Location:
lemon
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lemon/graph_reader.h

    r1540 r1705  
    123123    /// Construct a new GraphReader. It reads into the given graph
    124124    /// and it uses the given reader as the default skipper.
    125     GraphReader(std::istream& _is,
    126                 typename SmartParameter<Graph>::Type _graph,
     125    GraphReader(std::istream& _is, Graph& _graph,
    127126                const DefaultSkipper& _skipper = DefaultSkipper())
    128127      : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
     
    138137    /// Construct a new GraphReader. It reads into the given graph
    139138    /// and it uses the given reader as the default skipper.
    140     GraphReader(const std::string& _filename,
    141                 typename SmartParameter<Graph>::Type _graph,
     139    GraphReader(const std::string& _filename, Graph& _graph,
    142140                const DefaultSkipper& _skipper = DefaultSkipper())
    143141      : reader(new LemonReader(_filename)), own_reader(true),
     
    154152    /// Construct a new GraphReader. It reads into the given graph
    155153    /// and it uses the given reader as the default skipper.
    156     GraphReader(LemonReader& _reader,
    157                 typename SmartParameter<Graph>::Type _graph,
     154    GraphReader(LemonReader& _reader, Graph& _graph,
    158155                const DefaultSkipper& _skipper = DefaultSkipper())
    159156      : reader(_reader), own_reader(false), skipper(_skipper),
  • lemon/lemon_reader.h

    r1627 r1705  
    3737#include <lemon/bits/item_reader.h>
    3838
     39#include <lemon/xy.h>
     40
    3941#include <lemon/concept_check.h>
    4042#include <lemon/concept/maps.h>
     
    9597    };
    9698
    97     template <typename M1, typename M2>
    98     class WriteComposeMap {
     99    template <typename Map>
     100    struct Ref { typedef Map& Type; };
     101    template <typename Map>
     102    struct Arg { typedef Map& Type; };
     103
     104    template <typename Graph, typename Map>
     105    class ForwardComposeMap {
    99106    public:
    100       typedef True NeedCopy;
     107      typedef typename Graph::UndirEdge Key;
     108      typedef typename Map::Value Value;
     109
     110      ForwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map)
     111        : graph(_graph), map(_map) {}
    101112     
    102       typedef typename M2::Key Key;
    103       typedef typename M1::Value Value;
    104 
    105       WriteComposeMap(typename SmartParameter<M1>::Type _m1, const M2& _m2)
    106         : m1(_m1), m2(_m2) {}
     113      void set(const Key& key, const Value& val) {
     114        map.set(graph.direct(key, true), val);
     115      }
     116
     117    private:
     118      typename Ref<Map>::Type map;
     119      const Graph& graph;
     120    };
     121
     122    template <typename Graph, typename Map>
     123    ForwardComposeMap<Graph, Map>
     124    forwardComposeMap(const Graph& graph, const Map& map) {
     125      return ForwardComposeMap<Graph, Map>(graph, map);
     126    }
     127
     128    template <typename Graph, typename Map>
     129    ForwardComposeMap<Graph, Map>
     130    forwardComposeMap(const Graph& graph, Map& map) {
     131      return ForwardComposeMap<Graph, Map>(graph, map);
     132    }
     133
     134    template <typename Graph, typename Map>
     135    class BackwardComposeMap {
     136    public:
     137      typedef typename Graph::UndirEdge Key;
     138      typedef typename Map::Value Value;
     139
     140      BackwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map)
     141        : graph(_graph), map(_map) {}
    107142     
    108       void set(const Key& key, const Value& value) {
    109         m1.set(m2[key], value);
     143      void set(const Key& key, const Value& val) {
     144        map.set(graph.direct(key, false), val);
    110145      }
    111146
    112147    private:
    113      
    114       typename SmartReference<M1>::Type m1;
    115       typename SmartConstReference<M2>::Type m2;
    116      
    117     };
    118 
    119     template <typename M1, typename M2>
    120     WriteComposeMap<M1, M2> writeComposeMap(M1& m1, const M2& m2) {
    121       return WriteComposeMap<M1, M2>(m1, m2);
    122     }
    123 
    124     template <typename M1, typename M2>
    125     WriteComposeMap<M1, M2> writeComposeMap(const M1& m1, const M2& m2) {
    126       return WriteComposeMap<M1, M2>(m1, m2);
    127     }
    128  
     148      typename Ref<Map>::Type map;
     149      const Graph& graph;
     150    };
     151
     152
     153    template <typename Graph, typename Map>
     154    BackwardComposeMap<Graph, Map>
     155    backwardComposeMap(const Graph& graph, const Map& map) {
     156      return BackwardComposeMap<Graph, Map>(graph, map);
     157    }
     158
     159    template <typename Graph, typename Map>
     160    BackwardComposeMap<Graph, Map>
     161    backwardComposeMap(const Graph& graph, Map& map) {
     162      return BackwardComposeMap<Graph, Map>(graph, map);
     163    }
     164
     165    template <typename Graph, typename Map>
     166    struct Ref<ForwardComposeMap<Graph, Map> > {
     167      typedef ForwardComposeMap<Graph, Map> Type;
     168    };
     169    template <typename Graph, typename Map>
     170    struct Arg<ForwardComposeMap<Graph, Map> > {
     171      typedef const ForwardComposeMap<Graph, Map>& Type;
     172    };
     173
     174    template <typename Graph, typename Map>
     175    struct Ref<BackwardComposeMap<Graph, Map> > {
     176      typedef BackwardComposeMap<Graph, Map> Type;
     177    };
     178    template <typename Graph, typename Map>
     179    struct Arg<BackwardComposeMap<Graph, Map> > {
     180      typedef const BackwardComposeMap<Graph, Map>& Type;
     181    };
     182
     183    template <typename Map>
     184    struct Ref<XMap<Map> > {
     185      typedef XMap<Map> Type;
     186    };
     187    template <typename Map>
     188    struct Arg<XMap<Map> > {
     189      typedef const XMap<Map>& Type;
     190    };
     191
     192    template <typename Map>
     193    struct Ref<YMap<Map> > {
     194      typedef YMap<Map> Type;
     195    };
     196    template <typename Map>
     197    struct Arg<YMap<Map> > {
     198      typedef const YMap<Map>& Type;
     199    };
     200
    129201  }
    130202
     
    433505      typedef std::map<Value, Item, _reader_bits::Less<Value> > Inverse;
    434506
    435       typename SmartReference<Map>::Type map;
     507      typename _reader_bits::Ref<Map>::Type map;
    436508      Reader reader;
    437509      Inverse inverse;
    438510
    439       MapReaderInverter(typename SmartParameter<Map>::Type _map,
     511      MapReaderInverter(typename _reader_bits::Arg<Map>::Type _map,
    440512                        const Reader& _reader)
    441513        : map(_map), reader(_reader) {}
     
    527599      typedef _Item Item;
    528600     
    529       typename SmartReference<Map>::Type map;
     601      typename _reader_bits::Ref<Map>::Type map;
    530602      Reader reader;
    531603
    532       MapReader(typename SmartParameter<Map>::Type _map,
     604      MapReader(typename _reader_bits::Arg<Map>::Type _map,
    533605                const Reader& _reader)
    534606        : map(_map), reader(_reader) {}
     
    660732    /// the section when the \c section_id and the \c _id are the same.
    661733    NodeSetReader(LemonReader& _reader,
    662                   typename SmartParameter<Graph>::Type _graph,
     734                  Graph& _graph,
    663735                  const std::string& _id = std::string(),
    664736                  const DefaultSkipper& _skipper = DefaultSkipper())
     
    689761      return _readMap<
    690762        typename Traits::template Reader<typename Map::Value>, Map,
    691         typename SmartParameter<Map>::Type>(name, map);
     763        typename _reader_bits::Arg<Map>::Type>(name, map);
    692764    }
    693765
     
    696768      return _readMap<
    697769        typename Traits::template Reader<typename Map::Value>, Map,
    698         typename SmartParameter<Map>::Type>(name, map);
     770        typename _reader_bits::Arg<Map>::Type>(name, map);
    699771    }
    700772
     
    705777    NodeSetReader& readNodeMap(std::string name, Map& map,
    706778                               const Reader& reader = Reader()) {
    707       return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
     779      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
    708780        (name, map, reader);
    709781    }
     
    712784    NodeSetReader& readNodeMap(std::string name, const Map& map,
    713785                               const Reader& reader = Reader()) {
    714       return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
     786      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
    715787        (name, map, reader);
    716788    }
     
    818890    MapReaders readers;
    819891   
    820     typename SmartReference<Graph>::Type graph;   
     892    Graph& graph;   
    821893    std::string id;
    822894    SkipReader<Node, DefaultSkipper> skipper;
     
    868940    template <typename NodeIdReader>
    869941    EdgeSetReader(LemonReader& _reader,
    870                   typename SmartParameter<Graph>::Type _graph,
     942                  Graph& _graph,
    871943                  const NodeIdReader& _nodeIdReader,
    872944                  const std::string& _id = std::string(),
     
    899971      return _readMap<
    900972        typename Traits::template Reader<typename Map::Value>, Map,
    901         typename SmartParameter<Map>::Type>(name, map);
     973        typename _reader_bits::Arg<Map>::Type>(name, map);
    902974    }
    903975
     
    906978      return _readMap<
    907979        typename Traits::template Reader<typename Map::Value>, Map,
    908         typename SmartParameter<Map>::Type>(name, map);
     980        typename _reader_bits::Arg<Map>::Type>(name, map);
    909981    }
    910982
     
    916988                           const Reader& reader = Reader()) {
    917989      return _readMap<Reader, Map,
    918         typename SmartParameter<Map>::Type>(name, map, reader);
     990        typename _reader_bits::Arg<Map>::Type>(name, map, reader);
    919991    }
    920992
     
    923995                               const Reader& reader = Reader()) {
    924996      return _readMap<Reader, Map,
    925         typename SmartParameter<Map>::Type>(name, map, reader);
     997        typename _reader_bits::Arg<Map>::Type>(name, map, reader);
    926998    }
    927999
     
    10331105    MapReaders readers;
    10341106   
    1035     typename SmartReference<Graph>::Type graph;   
     1107    Graph& graph;   
    10361108    std::string id;
    10371109    SkipReader<Edge, DefaultSkipper> skipper;
     
    10901162    template <typename NodeIdReader>
    10911163    UndirEdgeSetReader(LemonReader& _reader,
    1092                        typename SmartParameter<Graph>::Type _graph,
     1164                       Graph& _graph,
    10931165                       const NodeIdReader& _nodeIdReader,
    10941166                       const std::string& _id = std::string(),
     
    11211193      return _readMap<
    11221194        typename Traits::template Reader<typename Map::Value>, Map,
    1123         typename SmartParameter<Map>::Type>(name, map);
     1195        typename _reader_bits::Arg<Map>::Type>(name, map);
    11241196    }
    11251197
     
    11281200      return _readMap<
    11291201        typename Traits::template Reader<typename Map::Value>, Map,
    1130         typename SmartParameter<Map>::Type>(name, map);
     1202        typename _reader_bits::Arg<Map>::Type>(name, map);
    11311203    }
    11321204
     
    11371209    UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map,
    11381210                                         const Reader& reader = Reader()) {
    1139       return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
     1211      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
    11401212        (name, map, reader);
    11411213    }
     
    11441216    UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map,
    11451217                                         const Reader& reader = Reader()) {
    1146       return _readMap<Reader, Map, typename SmartParameter<Map>::Type >
     1218      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type >
    11471219        (name, map, reader);
    11481220    }
     
    11901262      return _readDirMap<
    11911263        typename Traits::template Reader<typename Map::Value>, Map,
    1192         typename SmartParameter<Map>::Type>(name, map);
     1264        typename _reader_bits::Arg<Map>::Type>(name, map);
    11931265    }
    11941266
     
    11971269      return _readDirMap<
    11981270        typename Traits::template Reader<typename Map::Value>, Map,
    1199         typename SmartParameter<Map>::Type>(name, map);
     1271        typename _reader_bits::Arg<Map>::Type>(name, map);
    12001272    }
    12011273
     
    12061278    UndirEdgeSetReader& readEdgeMap(std::string name, Map& map,
    12071279                                    const Reader& reader = Reader()) {
    1208       return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>
     1280      return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
    12091281        (name, map, reader);
    12101282    }
     
    12131285    UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map,
    12141286                                    const Reader& reader = Reader()) {
    1215       return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>
     1287      return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
    12161288        (name, map, reader);
    12171289    }
     
    12251297      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    12261298      readMap("+" + name,
    1227               _reader_bits::writeComposeMap(map, forwardMap(graph)), reader);
     1299              _reader_bits::forwardComposeMap(graph, map), reader);
    12281300      readMap("-" + name,
    1229               _reader_bits::writeComposeMap(map, backwardMap(graph)), reader);
     1301              _reader_bits::backwardComposeMap(graph, map), reader);
    12301302      return *this;     
    12311303    }
     
    13371409    MapReaders readers;
    13381410   
    1339     typename SmartReference<Graph>::Type graph;   
     1411    Graph& graph;   
    13401412    std::string id;
    13411413    SkipReader<UndirEdge, DefaultSkipper> skipper;
  • lemon/lemon_writer.h

    r1690 r1705  
    3636#include <lemon/utility.h>
    3737#include <lemon/maps.h>
     38#include <lemon/xy.h>
    3839
    3940#include <lemon/concept_check.h>
     
    8586    };
    8687
     88    template <typename Map>
     89    struct Ref { typedef const Map& Type; };
     90
     91    template <typename Graph, typename Map>
     92    class ForwardComposeMap {
     93    public:
     94      typedef typename Graph::UndirEdge Key;
     95      typedef typename Map::Value Value;
     96
     97      ForwardComposeMap(const Graph& _graph, const Map& _map)
     98        : graph(_graph), map(_map) {}
     99     
     100      Value operator[](const Key& key) {
     101        return map[graph.direct(key, false)];
     102      }
     103
     104    private:
     105      typename Ref<Map>::Type map;
     106      const Graph& graph;
     107    };
     108
     109    template <typename Graph, typename Map>
     110    ForwardComposeMap<Graph, Map>
     111    forwardComposeMap(const Graph& graph, const Map& map) {
     112      return ForwardComposeMap<Graph, Map>(graph, map);
     113    }
     114
     115    template <typename Graph, typename Map>
     116    class BackwardComposeMap {
     117    public:
     118      typedef typename Graph::UndirEdge Key;
     119      typedef typename Map::Value Value;
     120
     121      BackwardComposeMap(const Graph& _graph, const Map& _map)
     122        : graph(_graph), map(_map) {}
     123     
     124      Value operator[](const Key& key) {
     125        return map[graph.direct(key, false)];
     126      }
     127
     128    private:
     129      typename Ref<Map>::Type map;
     130      const Graph& graph;
     131    };
     132
     133    template <typename Graph, typename Map>
     134    BackwardComposeMap<Graph, Map>
     135    backwardComposeMap(const Graph& graph, const Map& map) {
     136      return BackwardComposeMap<Graph, Map>(graph, map);
     137    }
     138
     139    template <typename Graph, typename Map>
     140    struct Ref<ForwardComposeMap<Graph, Map> > {
     141      typedef ForwardComposeMap<Graph, Map> Type;
     142    };
     143
     144    template <typename Graph, typename Map>
     145    struct Ref<BackwardComposeMap<Graph, Map> > {
     146      typedef BackwardComposeMap<Graph, Map> Type;
     147    };
     148
     149    template <typename Map>
     150    struct Ref<XMap<Map> > {
     151      typedef XMap<Map> Type;
     152    };
     153    template <typename Map>
     154    struct Ref<ConstXMap<Map> > {
     155      typedef ConstXMap<Map> Type;
     156    };
     157
     158    template <typename Map>
     159    struct Ref<YMap<Map> > {
     160      typedef YMap<Map> Type;
     161    };
     162    template <typename Map>
     163    struct Ref<ConstYMap<Map> > {
     164      typedef ConstYMap<Map> Type;
     165    };
     166
    87167  }
    88168
     
    235315      typedef _Item Item;
    236316     
    237       typename SmartConstReference<Map>::Type map;
     317      typename _writer_bits::Ref<Map>::Type map;
    238318      Writer writer;
    239319
     
    454534    bool forceIdMap;
    455535   
    456     typename SmartConstReference<Graph>::Type graph;   
     536    const Graph& graph;   
    457537    std::string id;
    458538
     
    628708    bool forceIdMap;
    629709   
    630     typename SmartConstReference<Graph>::Type graph;   
     710    const Graph& graph;   
    631711    std::string id;
    632712
     
    747827      checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
    748828      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    749       writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
    750       writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
     829      writeUndirEdge("+" + name,
     830                     _writer_bits::forwardComposeMap(graph, map), writer);
     831      writeUndirEdge("-" + name,
     832                     _writer_bits::backwardComposeMap(graph, map), writer);
    751833      return *this;
    752834    }
     
    854936    bool forceIdMap;
    855937   
    856     typename SmartConstReference<Graph>::Type graph;   
     938    const Graph& graph;   
    857939    std::string id;
    858940
  • lemon/maps.h

    r1695 r1705  
    3939  /// Base class of maps.
    4040  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
    41   template<typename K, typename T, typename _NeedCopy = False>
     41  template<typename K, typename T>
    4242  class MapBase {
    4343  public:
    44     /// \e
    45     typedef _NeedCopy NeedCopy;
    4644    ///\e
    4745    typedef K Key;
     
    5553  /// or if you have to provide a writable map, but
    5654  /// data written to it will sent to <tt>/dev/null</tt>...
    57   template<typename K, typename T, typename NC = False>
    58   class NullMap : public MapBase<K, T, NC> {
    59   public:
    60     typedef MapBase<K, T, NC> Parent;
     55  template<typename K, typename T>
     56  class NullMap : public MapBase<K, T> {
     57  public:
     58    typedef MapBase<K, T> Parent;
    6159    typedef typename Parent::Key Key;
    6260    typedef typename Parent::Value Value;
     
    6967
    7068  template <typename K, typename V>
    71   NullMap<K, V, True> nullMap() {
    72     return NullMap<K, V, True>();
     69  NullMap<K, V> nullMap() {
     70    return NullMap<K, V>();
    7371  }
    7472
     
    7977  /// In other aspects it is equivalent to the \ref NullMap.
    8078  /// \todo set could be used to set the value.
    81   template<typename K, typename T, typename NC = False>
    82   class ConstMap : public MapBase<K, T, NC> {
     79  template<typename K, typename T>
     80  class ConstMap : public MapBase<K, T> {
    8381  private:
    8482    T v;
    8583  public:
    8684
    87     typedef MapBase<K, T, NC> Parent;
     85    typedef MapBase<K, T> Parent;
    8886    typedef typename Parent::Key Key;
    8987    typedef typename Parent::Value Value;
     
    117115  ///\relates ConstMap
    118116  template<typename K, typename V>
    119   inline ConstMap<K, V, True> constMap(const V &v) {
    120     return ConstMap<K, V, True>(v);
     117  inline ConstMap<K, V> constMap(const V &v) {
     118    return ConstMap<K, V>(v);
    121119  }
    122120
     
    127125
    128126  //\todo to document later
    129   template<typename K, typename V, V v, typename NC>
    130   class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
    131   public:
    132     typedef MapBase<K, V, False> Parent;
     127  template<typename K, typename V, V v>
     128  class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
     129  public:
     130    typedef MapBase<K, V> Parent;
    133131    typedef typename Parent::Key Key;
    134132    typedef typename Parent::Value Value;
     
    144142  ///\relates ConstMap
    145143  template<typename K, typename V, V v>
    146   inline ConstMap<K, Const<V, v>, True> constMap() {
    147     return ConstMap<K, Const<V, v>, True>();
     144  inline ConstMap<K, Const<V, v> > constMap() {
     145    return ConstMap<K, Const<V, v> >();
    148146  }
    149147
     
    226224  /// This mapping gives back the given key as value without any
    227225  /// modification.
    228   template <typename T, typename NC = False>
    229   class IdentityMap : public MapBase<T, T, NC> {
    230   public:
    231     typedef MapBase<T, T, NC> Parent;
     226  template <typename T>
     227  class IdentityMap : public MapBase<T, T> {
     228  public:
     229    typedef MapBase<T, T> Parent;
    232230    typedef typename Parent::Key Key;
    233231    typedef typename Parent::Value Value;
     
    243241  ///\relates IdentityMap
    244242  template<typename T>
    245   inline IdentityMap<T, True> identityMap() {
    246     return IdentityMap<T, True>();
     243  inline IdentityMap<T> identityMap() {
     244    return IdentityMap<T>();
    247245  }
    248246 
     
    253251  ///converts the \c Value of a maps to type \c T.
    254252  ///Its \c Key is inherited from \c M.
    255   template <typename M, typename T, typename NC = False>
    256   class ConvertMap : public MapBase<typename M::Key, T, NC> {
    257     typename SmartConstReference<M>::Type m;
    258   public:
    259     typedef MapBase<typename M::Key, T, NC> Parent;
     253  template <typename M, typename T>
     254  class ConvertMap : public MapBase<typename M::Key, T> {
     255    const M& m;
     256  public:
     257    typedef MapBase<typename M::Key, T> Parent;
    260258    typedef typename Parent::Key Key;
    261259    typedef typename Parent::Value Value;
     
    281279  ///\todo The order of the template parameters are changed.
    282280  template<typename T, typename M>
    283   inline ConvertMap<M, T, True> convertMap(const M &m) {
    284     return ConvertMap<M, T, True>(m);
     281  inline ConvertMap<M, T> convertMap(const M &m) {
     282    return ConvertMap<M, T>(m);
    285283  }
    286284
     
    291289  ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
    292290
    293   template<typename M1, typename M2, typename NC = False>
    294   class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    295     typename SmartConstReference<M1>::Type m1;
    296     typename SmartConstReference<M2>::Type m2;
    297 
    298   public:
    299     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     291  template<typename M1, typename M2>
     292  class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
     293    const M1& m1;
     294    const M2& m2;
     295
     296  public:
     297    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
    300298    typedef typename Parent::Key Key;
    301299    typedef typename Parent::Value Value;
     
    314312  ///\todo Wrong scope in Doxygen when \c \\relates is used
    315313  template<typename M1, typename M2>
    316   inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
    317     return AddMap<M1, M2, True>(m1,m2);
     314  inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
     315    return AddMap<M1, M2>(m1,m2);
    318316  }
    319317
     
    333331  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
    334332  ///\endcode
    335   template<typename M, typename C = typename M::Value, typename NC = False>
    336   class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
    337     typename SmartConstReference<M>::Type m;
     333  template<typename M, typename C = typename M::Value>
     334  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
     335    const M& m;
    338336    C v;
    339337  public:
    340     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     338    typedef MapBase<typename M::Key, typename M::Value> Parent;
    341339    typedef typename Parent::Key Key;
    342340    typedef typename Parent::Value Value;
     
    357355  ///\todo A better name is required.
    358356  template<typename M, typename C>
    359   inline ShiftMap<M, C, True> shiftMap(const M &m,const C &v) {
    360     return ShiftMap<M, C, True>(m,v);
     357  inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
     358    return ShiftMap<M, C>(m,v);
    361359  }
    362360
     
    368366  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    369367
    370   template<typename M1, typename M2, typename NC = False>
    371   class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    372     typename SmartConstReference<M1>::Type m1;
    373     typename SmartConstReference<M2>::Type m2;
    374   public:
    375     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     368  template<typename M1, typename M2>
     369  class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
     370    const M1& m1;
     371    const M2& m2;
     372  public:
     373    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
    376374    typedef typename Parent::Key Key;
    377375    typedef typename Parent::Value Value;
     
    388386  ///\relates SubMap
    389387  template<typename M1, typename M2>
    390   inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
    391     return SubMap<M1, M2, True>(m1, m2);
     388  inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
     389    return SubMap<M1, M2>(m1, m2);
    392390  }
    393391
     
    400398  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    401399
    402   template<typename M1, typename M2, typename NC = False>
    403   class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    404     typename SmartConstReference<M1>::Type m1;
    405     typename SmartConstReference<M2>::Type m2;
    406   public:
    407     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     400  template<typename M1, typename M2>
     401  class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
     402    const M1& m1;
     403    const M2& m2;
     404  public:
     405    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
    408406    typedef typename Parent::Key Key;
    409407    typedef typename Parent::Value Value;
     
    419417  ///\relates MulMap
    420418  template<typename M1, typename M2>
    421   inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
    422     return MulMap<M1, M2, True>(m1,m2);
     419  inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
     420    return MulMap<M1, M2>(m1,m2);
    423421  }
    424422 
     
    438436  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
    439437  ///\endcode
    440   template<typename M, typename C = typename M::Value, typename NC = False>
    441   class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
    442     typename SmartConstReference<M>::Type m;
     438  template<typename M, typename C = typename M::Value>
     439  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
     440    const M& m;
    443441    C v;
    444442  public:
    445     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     443    typedef MapBase<typename M::Key, typename M::Value> Parent;
    446444    typedef typename Parent::Key Key;
    447445    typedef typename Parent::Value Value;
     
    462460  ///\todo A better name is required.
    463461  template<typename M, typename C>
    464   inline ScaleMap<M, C, True> scaleMap(const M &m,const C &v) {
    465     return ScaleMap<M, C, True>(m,v);
     462  inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
     463    return ScaleMap<M, C>(m,v);
    466464  }
    467465
     
    473471  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
    474472
    475   template<typename M1, typename M2, typename NC = False>
    476   class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    477     typename SmartConstReference<M1>::Type m1;
    478     typename SmartConstReference<M2>::Type m2;
    479   public:
    480     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     473  template<typename M1, typename M2>
     474  class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
     475    const M1& m1;
     476    const M2& m2;
     477  public:
     478    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
    481479    typedef typename Parent::Key Key;
    482480    typedef typename Parent::Value Value;
     
    492490  ///\relates DivMap
    493491  template<typename M1, typename M2>
    494   inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
    495     return DivMap<M1, M2, True>(m1,m2);
     492  inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
     493    return DivMap<M1, M2>(m1,m2);
    496494  }
    497495 
     
    513511  ///\todo Check the requirements.
    514512
    515   template <typename M1, typename M2, typename NC = False>
    516   class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
    517     typename SmartConstReference<M1>::Type m1;
    518     typename SmartConstReference<M2>::Type m2;
    519   public:
    520     typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
     513  template <typename M1, typename M2>
     514  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
     515    const M1& m1;
     516    const M2& m2;
     517  public:
     518    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
    521519    typedef typename Parent::Key Key;
    522520    typedef typename Parent::Value Value;
     
    532530  ///\relates ComposeMap
    533531  template <typename M1, typename M2>
    534   inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
    535     return ComposeMap<M1, M2, True>(m1,m2);
     532  inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
     533    return ComposeMap<M1, M2>(m1,m2);
    536534  }
    537535 
     
    562560           typename V = typename F::result_type,
    563561           typename NC = False>
    564   class CombineMap : public MapBase<typename M1::Key, V, NC> {
    565     typename SmartConstReference<M1>::Type m1;
    566     typename SmartConstReference<M2>::Type m2;
     562  class CombineMap : public MapBase<typename M1::Key, V> {
     563    const M1& m1;
     564    const M2& m2;
    567565    F f;
    568566  public:
    569     typedef MapBase<typename M1::Key, V, NC> Parent;
     567    typedef MapBase<typename M1::Key, V> Parent;
    570568    typedef typename Parent::Key Key;
    571569    typedef typename Parent::Value Value;
     
    594592  ///\relates CombineMap
    595593  template<typename M1, typename M2, typename F, typename V>
    596   inline CombineMap<M1, M2, F, V, True>
     594  inline CombineMap<M1, M2, F, V>
    597595  combineMap(const M1& m1,const M2& m2, const F& f) {
    598     return CombineMap<M1, M2, F, V, True>(m1,m2,f);
     596    return CombineMap<M1, M2, F, V>(m1,m2,f);
    599597  }
    600598
    601599  template<typename M1, typename M2, typename F>
    602   inline CombineMap<M1, M2, F, typename F::result_type, True>
     600  inline CombineMap<M1, M2, F, typename F::result_type>
    603601  combineMap(const M1& m1, const M2& m2, const F& f) {
    604602    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
     
    606604
    607605  template<typename M1, typename M2, typename K1, typename K2, typename V>
    608   inline CombineMap<M1, M2, V (*)(K1, K2), V, True>
     606  inline CombineMap<M1, M2, V (*)(K1, K2), V>
    609607  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
    610608    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
     
    619617  ///The unary \c - operator must be defined for \c Value, of course.
    620618
    621   template<typename M, typename NC = False>
    622   class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
    623     typename SmartConstReference<M>::Type m;
    624   public:
    625     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     619  template<typename M>
     620  class NegMap : public MapBase<typename M::Key, typename M::Value> {
     621    const M& m;
     622  public:
     623    typedef MapBase<typename M::Key, typename M::Value> Parent;
    626624    typedef typename Parent::Key Key;
    627625    typedef typename Parent::Value Value;
     
    637635  ///\relates NegMap
    638636  template <typename M>
    639   inline NegMap<M, True> negMap(const M &m) {
    640     return NegMap<M, True>(m);
     637  inline NegMap<M> negMap(const M &m) {
     638    return NegMap<M>(m);
    641639  }
    642640
     
    665663 
    666664
    667   template<typename M, typename NC = False>
    668   class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
    669     typename SmartConstReference<M>::Type m;
    670   public:
    671     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     665  template<typename M>
     666  class AbsMap : public MapBase<typename M::Key, typename M::Value> {
     667    const M& m;
     668  public:
     669    typedef MapBase<typename M::Key, typename M::Value> Parent;
    672670    typedef typename Parent::Key Key;
    673671    typedef typename Parent::Value Value;
     
    687685  ///\relates AbsMap
    688686  template<typename M>
    689   inline AbsMap<M, True> absMap(const M &m) {
    690     return AbsMap<M, True>(m);
     687  inline AbsMap<M> absMap(const M &m) {
     688    return AbsMap<M>(m);
    691689  }
    692690
     
    708706           typename V = typename F::result_type,
    709707           typename NC = False>
    710   class FunctorMap : public MapBase<K, V, NC> {
     708  class FunctorMap : public MapBase<K, V> {
    711709    F f;
    712710  public:
    713     typedef MapBase<K, V, NC> Parent;
     711    typedef MapBase<K, V> Parent;
    714712    typedef typename Parent::Key Key;
    715713    typedef typename Parent::Value Value;
     
    728726  ///\relates FunctorMap
    729727  template<typename K, typename V, typename F> inline
    730   FunctorMap<F, K, V, True> functorMap(const F &f) {
    731     return FunctorMap<F, K, V, True>(f);
     728  FunctorMap<F, K, V> functorMap(const F &f) {
     729    return FunctorMap<F, K, V>(f);
    732730  }
    733731
    734732  template <typename F> inline
    735   FunctorMap<F, typename F::argument_type, typename F::result_type, True>
     733  FunctorMap<F, typename F::argument_type, typename F::result_type>
    736734  functorMap(const F &f) {
    737735    return FunctorMap<F, typename F::argument_type,
    738       typename F::result_type, True>(f);
     736      typename F::result_type>(f);
    739737  }
    740738
    741739  template <typename K, typename V> inline
    742   FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
    743     return FunctorMap<V (*)(K), K, V, True>(f);
     740  FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
     741    return FunctorMap<V (*)(K), K, V>(f);
    744742  }
    745743
     
    754752  ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
    755753
    756   template <typename M, typename NC = False>
    757   class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
    758     typename SmartConstReference<M>::Type m;
    759   public:
    760     typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
     754  template <typename M>
     755  class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
     756    const M& m;
     757  public:
     758    typedef MapBase<typename M::Key, typename M::Value> Parent;
    761759    typedef typename Parent::Key Key;
    762760    typedef typename Parent::Value Value;
     
    780778  ///\relates MapFunctor
    781779  template<typename M>
    782   inline MapFunctor<M, True> mapFunctor(const M &m) {
    783     return MapFunctor<M, True>(m);
     780  inline MapFunctor<M> mapFunctor(const M &m) {
     781    return MapFunctor<M>(m);
    784782  }
    785783
     
    796794  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
    797795
    798   template<typename  M1, typename M2, typename NC = False>
    799   class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
    800     typename SmartConstReference<M1>::Type m1;
    801     typename SmartConstReference<M2>::Type m2;
    802   public:
    803     typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
     796  template<typename  M1, typename M2>
     797  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
     798    const M1& m1;
     799    const M2& m2;
     800  public:
     801    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
    804802    typedef typename Parent::Key Key;
    805803    typedef typename Parent::Value Value;
     
    819817  ///\todo Wrong scope in Doxygen when \c \\relates is used
    820818  template <typename M1, typename M2>
    821   inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
    822     return ForkMap<M1, M2, True>(m1,m2);
     819  inline ForkMap<M1, M2> forkMap(const M1 &m1,const M2 &m2) {
     820    return ForkMap<M1, M2>(m1,m2);
    823821  }
    824822
     
    835833  ///its Value is <tt>bool</tt>.
    836834
    837   template <typename M, typename NC = False>
    838   class NotMap : public MapBase<typename M::Key, bool, NC> {
    839     typename SmartConstReference<M>::Type m;
    840   public:
    841     typedef MapBase<typename M::Key, bool, NC> Parent;
     835  template <typename M>
     836  class NotMap : public MapBase<typename M::Key, bool> {
     837    const M& m;
     838  public:
     839    typedef MapBase<typename M::Key, bool> Parent;
    842840    typedef typename Parent::Key Key;
    843841    typedef typename Parent::Value Value;
     
    853851  ///\relates NotMap
    854852  template <typename M>
    855   inline NotMap<M, True> notMap(const M &m) {
    856     return NotMap<M, True>(m);
     853  inline NotMap<M> notMap(const M &m) {
     854    return NotMap<M>(m);
    857855  }
    858856
  • lemon/utility.h

    r1696 r1705  
    140140  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
    141141
    142   // smart referencing
    143 
    144   template <typename _Type, typename Enable = void>
    145   struct SmartReference {
    146     typedef _Type& Type;
    147   };
    148  
    149   template <typename _Type>
    150   struct SmartReference<
    151     _Type,
    152     typename enable_if<typename _Type::NeedCopy, void>::type
    153   > {
    154     typedef _Type Type;
    155   };
    156 
    157   template <typename _Type, typename Enable = void>
    158   struct SmartConstReference {
    159     typedef const _Type& Type;
    160   };
    161  
    162   template <typename _Type>
    163   struct SmartConstReference<
    164     _Type,
    165     typename enable_if<typename _Type::NeedCopy, void>::type
    166   > {
    167     typedef const _Type Type;
    168   };
    169 
    170   template <typename _Type, typename Enable = void>
    171   struct SmartParameter {
    172     typedef _Type& Type;
    173   };
    174  
    175   template <typename _Type>
    176   struct SmartParameter<
    177     _Type,
    178     typename enable_if<typename _Type::NeedCopy, void>::type
    179   > {
    180     typedef const _Type& Type;
    181   };
    182 
    183142} // namespace lemon
    184143
Note: See TracChangeset for help on using the changeset viewer.