COIN-OR::LEMON - Graph Library

Changeset 2248:1ac928089d68 in lemon-0.x for lemon/maps.h


Ignore:
Timestamp:
10/17/06 13:01:16 (13 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2998
Message:

SimpleMap? and SimpleWriteMap?

  • Trivial adaptors, but they are useful in some case

Some combined maps will be reference map if the first
template parameter map is reference map or not. If I want
to give a refernce map as first map but there is a non
reference map parameter then I should wrap my first map
to a regular read-write map.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/maps.h

    r2093 r2248  
    288288  }
    289289
     290  ///Simple wrapping of the map
     291
     292  ///This \ref concept::ReadMap "read only map" returns the simple
     293  ///wrapping of the given map. Sometimes the reference maps cannot be
     294  ///combined with simple read maps. This map adaptor wraps the given
     295  ///map to simple read map.
     296  template<typename M>
     297  class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
     298    const M& m;
     299
     300  public:
     301    typedef MapBase<typename M::Key, typename M::Value> Parent;
     302    typedef typename Parent::Key Key;
     303    typedef typename Parent::Value Value;
     304
     305    ///Constructor
     306    SimpleMap(const M &_m) : m(_m) {};
     307    Value operator[](Key k) const {return m[k];}
     308  };
     309
     310  ///Simple writeable wrapping of the map
     311
     312  ///This \ref concept::ReadMap "read only map" returns the simple
     313  ///wrapping of the given map. Sometimes the reference maps cannot be
     314  ///combined with simple read-write maps. This map adaptor wraps the
     315  ///given map to simple read-write map.
     316  template<typename M>
     317  class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
     318    M& m;
     319
     320  public:
     321    typedef MapBase<typename M::Key, typename M::Value> Parent;
     322    typedef typename Parent::Key Key;
     323    typedef typename Parent::Value Value;
     324
     325    ///Constructor
     326    SimpleWriteMap(M &_m) : m(_m) {};
     327    Value operator[](Key k) const {return m[k];}
     328    void set(Key k, const Value& c) { m.set(k, c); }
     329  };
     330
    290331  ///Sum of two maps
    291332
Note: See TracChangeset for help on using the changeset viewer.