COIN-OR::LEMON - Graph Library

Changeset 1219:ce885274b754 in lemon-0.x


Ignore:
Timestamp:
03/16/05 14:25:19 (20 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1639
Message:

ForkMap? and CombineMap? added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/maps.h

    r1178 r1219  
    492492    Value operator[](Key k) const {return m1[m2[k]];}
    493493  };
    494  
    495494  ///Returns a \ref ComposeMap class
    496495
    497496  ///This function just returns a \ref ComposeMap class.
     497  ///
    498498  ///\relates ComposeMap
    499499  template<class M1,class M2>
     
    501501  {
    502502    return ComposeMap<M1,M2>(m1,m2);
     503  }
     504 
     505  ///Combine of two maps using an STL (binary) functor.
     506
     507  ///Combine of two maps using an STL (binary) functor.
     508  ///
     509  ///
     510  ///This \ref concept::ReadMap "read only map" takes to maps and a
     511  ///binary functor and returns the composition of
     512  ///two
     513  ///given maps unsing the functor.
     514  ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
     515  ///and \c f is of \c F,
     516  ///then for
     517  ///\code
     518  ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
     519  ///\endcode
     520  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
     521  ///
     522  ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
     523  ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
     524  ///input parameter of \c F and the return type of \c F must be convertible
     525  ///to \c V.
     526  ///\todo Check the requirements.
     527
     528  template<class M1,class M2,class F,class V>
     529  class CombineMap
     530  {
     531    const M1 &m1;
     532    const M2 &m2;
     533    const F &f;
     534  public:
     535    typedef typename M1::Key Key;
     536    typedef V Value;
     537
     538    ///Constructor
     539
     540    ///\e
     541    ///
     542    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
     543      : m1(_m1), m2(_m2), f(_f) {};
     544    Value operator[](Key k) const {return f(m1[k],m2[k]);}
     545  };
     546 
     547  ///Returns a \ref CombineMap class
     548
     549  ///This function just returns a \ref CombineMap class.
     550  ///
     551  ///Only the first template parameter (the value type) must be given.
     552  ///
     553  ///For example if \c m1 and \c m2 are both \c double valued maps, then
     554  ///\code
     555  ///combineMap<double>(m1,m2,std::plus<double>)
     556  ///\endcode
     557  ///is equivalent with
     558  ///\code
     559  ///addMap(m1,m2)
     560  ///\endcode
     561  ///
     562  ///\relates CombineMap
     563  template<class V,class M1,class M2,class F>
     564  inline CombineMap<M1,M2,F,V> combineMap(const M1 &m1,const M2 &m2,const F &f)
     565  {
     566    return CombineMap<M1,M2,F,V>(m1,m2,f);
    503567  }
    504568
     
    628692  }
    629693
    630   ///Converts a map to an STL style functor
    631 
    632   ///This class Converts a map to an STL style functor.
     694  ///Converts a map to an STL style (unary) functor
     695
     696  ///This class Converts a map to an STL style (unary) functor.
    633697  ///that is it provides an <tt>operator()</tt> to read its values.
    634698  ///
     
    670734
    671735
     736  ///Apply all map setting operations to two maps
     737
     738  ///This map has two \ref concept::WriteMap "writable map"
     739  ///parameters and each write request will be passed to both of them.
     740  ///If \c M1 is also \ref concept::ReadMap "readable",
     741  ///then the read operations will return the
     742  ///corresponding values \c M1.
     743  ///
     744  ///The \c Key and \c Value will be inherited from \c M1.
     745  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
     746
     747  template<class M1,class M2>
     748  class ForkMap
     749  {
     750    const M1 &m1;
     751    const M2 &m2;
     752  public:
     753    typedef typename M1::Key Key;
     754    typedef typename M1::Value Value;
     755
     756    ///Constructor
     757
     758    ///\e
     759    ///
     760    ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
     761    Value operator[](Key k) const {return m1[k];}
     762    void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);}
     763  };
     764 
     765  ///Returns an \ref ForkMap class
     766
     767  ///This function just returns an \ref ForkMap class.
     768  ///\todo How to call these type of functions?
     769  ///
     770  ///\relates ForkMap
     771  ///\todo Wrong scope in Doxygen when \c \\relates is used
     772  template<class M1,class M2>
     773  inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2)
     774  {
     775    return ForkMap<M1,M2>(m1,m2);
     776  }
     777
    672778  /// @}
    673779 
Note: See TracChangeset for help on using the changeset viewer.