src/lemon/xy.h
changeset 1422 469b3f628dd1
parent 1392 b87aa8f0feb8
child 1426 91eb70983697
equal deleted inserted replaced
16:d863bbbc95ef 17:38884f02f37c
    16 
    16 
    17 #ifndef LEMON_XY_H
    17 #ifndef LEMON_XY_H
    18 #define LEMON_XY_H
    18 #define LEMON_XY_H
    19 
    19 
    20 #include <iostream>
    20 #include <iostream>
       
    21 #include <lemon/utility.h>
    21 
    22 
    22 ///\ingroup misc
    23 ///\ingroup misc
    23 ///\file
    24 ///\file
    24 ///\brief A simple two dimensional vector and a bounding box implementation 
    25 ///\brief A simple two dimensional vector and a bounding box implementation 
    25 ///
    26 ///
   348   ///\ingroup maps
   349   ///\ingroup maps
   349   ///
   350   ///
   350   template<class M>
   351   template<class M>
   351   class XMap 
   352   class XMap 
   352   {
   353   {
   353     M &_map;
   354     typename SmartReference<M>::Type _map;
   354   public:
   355   public:
       
   356     typedef True NeedCopy;
       
   357 
   355     typedef typename M::Value::Value Value;
   358     typedef typename M::Value::Value Value;
   356     typedef typename M::Key Key;
   359     typedef typename M::Key Key;
   357     ///\e
   360     ///\e
   358     XMap(M &map) : _map(map) {}
   361     XMap(typename SmartParameter<M>::Type map) : _map(map) {}
   359     Value operator[](Key k) const {return _map[k].x;}
   362     Value operator[](Key k) const {return _map[k].x;}
   360     void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
   363     void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
   361   };
   364   };
   362     
   365     
   363   ///Returns an \ref XMap class
   366   ///Returns an \ref XMap class
   370   inline XMap<M> xMap(M &m) 
   373   inline XMap<M> xMap(M &m) 
   371   {
   374   {
   372     return XMap<M>(m);
   375     return XMap<M>(m);
   373   }
   376   }
   374 
   377 
       
   378   template<class M> 
       
   379   inline XMap<M> xMap(const M &m) 
       
   380   {
       
   381     return XMap<M>(m);
       
   382   }
       
   383 
   375   ///Constant (read only) version of \ref XMap
   384   ///Constant (read only) version of \ref XMap
   376 
   385 
   377   ///\ingroup maps
   386   ///\ingroup maps
   378   ///
   387   ///
   379   template<class M>
   388   template<class M>
   380   class ConstXMap 
   389   class ConstXMap 
   381   {
   390   {
   382     const M &_map;
   391     typename SmartConstReference<M>::Type _map;
   383   public:
   392   public:
       
   393     typedef True NeedCopy;
       
   394 
   384     typedef typename M::Value::Value Value;
   395     typedef typename M::Value::Value Value;
   385     typedef typename M::Key Key;
   396     typedef typename M::Key Key;
   386     ///\e
   397     ///\e
   387     ConstXMap(const M &map) : _map(map) {}
   398     ConstXMap(const M &map) : _map(map) {}
   388     Value operator[](Key k) const {return _map[k].x;}
   399     Value operator[](Key k) const {return _map[k].x;}
   405   ///\ingroup maps
   416   ///\ingroup maps
   406   ///
   417   ///
   407   template<class M>
   418   template<class M>
   408   class YMap 
   419   class YMap 
   409   {
   420   {
   410     M &_map;
   421     typename SmartReference<M>::Type _map;
   411   public:
   422   public:
       
   423     typedef True NeedCopy;
       
   424 
   412     typedef typename M::Value::Value Value;
   425     typedef typename M::Value::Value Value;
   413     typedef typename M::Key Key;
   426     typedef typename M::Key Key;
   414     ///\e
   427     ///\e
   415     YMap(M &map) : _map(map) {}
   428     YMap(typename SmartParameter<M>::Type map) : _map(map) {}
   416     Value operator[](Key k) const {return _map[k].y;}
   429     Value operator[](Key k) const {return _map[k].y;}
   417     void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
   430     void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
   418   };
   431   };
   419 
   432 
   420   ///Returns an \ref YMap class
   433   ///Returns an \ref YMap class
   427   inline YMap<M> yMap(M &m) 
   440   inline YMap<M> yMap(M &m) 
   428   {
   441   {
   429     return YMap<M>(m);
   442     return YMap<M>(m);
   430   }
   443   }
   431 
   444 
       
   445   template<class M> 
       
   446   inline YMap<M> yMap(const M &m) 
       
   447   {
       
   448     return YMap<M>(m);
       
   449   }
       
   450 
   432   ///Constant (read only) version of \ref YMap
   451   ///Constant (read only) version of \ref YMap
   433 
   452 
   434   ///\ingroup maps
   453   ///\ingroup maps
   435   ///
   454   ///
   436   template<class M>
   455   template<class M>
   437   class ConstYMap 
   456   class ConstYMap 
   438   {
   457   {
   439     const M &_map;
   458     typename SmartConstReference<M>::Type _map;
   440   public:
   459   public:
       
   460     typedef True NeedCopy;
       
   461 
   441     typedef typename M::Value::Value Value;
   462     typedef typename M::Value::Value Value;
   442     typedef typename M::Key Key;
   463     typedef typename M::Key Key;
   443     ///\e
   464     ///\e
   444     ConstYMap(const M &map) : _map(map) {}
   465     ConstYMap(const M &map) : _map(map) {}
   445     Value operator[](Key k) const {return _map[k].y;}
   466     Value operator[](Key k) const {return _map[k].y;}
   464   ///\ingroup maps
   485   ///\ingroup maps
   465   ///
   486   ///
   466   template<class M>
   487   template<class M>
   467   class NormSquareMap 
   488   class NormSquareMap 
   468   {
   489   {
   469     const M &_map;
   490     typename SmartConstReference<M>::Type _map;
   470   public:
   491   public:
       
   492     typedef True NeedCopy;
       
   493 
   471     typedef typename M::Value::Value Value;
   494     typedef typename M::Value::Value Value;
   472     typedef typename M::Key Key;
   495     typedef typename M::Key Key;
   473     ///\e
   496     ///\e
   474     NormSquareMap(const M &map) : _map(map) {}
   497     NormSquareMap(const M &map) : _map(map) {}
   475     Value operator[](Key k) const {return _map[k].normSquare();}
   498     Value operator[](Key k) const {return _map[k].normSquare();}