SkelGIS  3.0
/home/helene/Documents/These/SkelGIS/SkelGIS_Library/SkelGIS_V3/skelgis/skeletons/middle_skeletons/map.hpp
00001 #ifndef MAP_H
00002 #define MAP_H
00003 
00004 namespace skelgis{
00005 
00006   //================================================================================
00007   //Types of user functions for the map skeleton
00008   //-------------------------------------------------------------------------------
00009   template <typename T, typename T2> struct _Map_Func
00010   //-------------------------------------------------------------------------------
00011   {
00012     virtual T2 operator()(T element) const =0;
00013   };
00014   //================================================================================
00015 
00016   //================================================================================
00017   //Hidden structure to apply the skeleton map through ApplyUnary
00018   //-------------------------------------------------------------------------------
00019   template<class T, int R, class T2, int R2, bool line=true> struct _ApplyUnary_Map : public _ApplyUnary_Func<T, R, T2,R2>
00020   //-------------------------------------------------------------------------------
00021   {
00022     const _Map_Func<T, T2> *func;
00023     void operator()(DMatrix<T,R>& inp, DMatrix<T2,R2>& outp) const
00024     {
00025       iterator<T,R> itBeg = inp.begin();
00026       iterator<T,R> itEnd = inp.end();
00027       iterator<T2,R2> itOut = outp.begin();
00028       for( ; itBeg<itEnd; ++itBeg , ++itOut)
00029         {
00030           outp[itOut] = (*func)(inp[itBeg]);
00031         }
00032       }
00033   };
00034   //-------------------------------------------------------------------------------
00035   template<class T, int R, class T2, int R2> struct _ApplyUnary_Map<T,R,T2,R2,false> : public _ApplyUnary_Func<T, R, T2,R2,false>
00036   //-------------------------------------------------------------------------------
00037   {
00038     const _Map_Func<T, T2> *func;
00039     void operator()(DMatrix<T,R,false>& inp, DMatrix<T2,R2,false>& outp) const
00040     {
00041       iterator<T,R> itBeg = inp.begin();
00042       iterator<T,R> itEnd = inp.end();
00043       iterator<T2,R2> itOut = outp.begin();
00044       for( ; itBeg<itEnd; ++itBeg , ++itOut)
00045         {
00046           outp[itOut] = (*func)(inp[itBeg]);
00047         }
00048       }
00049   };
00050   //================================================================================
00051 
00052   //================================================================================
00053   //The map skeleton, called by the user
00054   //no specialization for R=0 because no impact on the map as no exchanges are done
00055   //-------------------------------------------------------------------------------
00056   //-------------------------------------------------------------------------------
00057   template<class T,int R,class T2,int R2,bool line=true> struct Map{};
00058   //-------------------------------------------------------------------------------
00059 
00060   //-------------------------------------------------------------------------------
00061   template<class T,int R,class T2,int R2> struct Map<T,R,T2,R2>
00062   //-------------------------------------------------------------------------------
00063   {
00064     //need an operator=(DMatrixw<...> m) in dmatrix.hpp
00065     /*inline static DMatrix<T2,R2> apply(const _Map_Func<T,T2>& func, DMatrix<T,R>& m)
00066     {
00067       DMatrix<T2,R2> m2(m.getGlobalHeader(),0);
00068       
00069       _ApplyUnary_Map<T,R,T2,R2> map_f;
00070       map_f.func = &func;
00071       ApplyUnary<T,R,T2,R2,true,true>::apply(map_f,m,m2);
00072 
00073       return m2;
00074       }*/
00075 
00076     inline static void apply(const _Map_Func<T,T2>& func, DMatrix<T,R>& m, DMatrix<T2,R2>& m2)
00077     {
00078       _ApplyUnary_Map<T,R,T2,R2> map_f;
00079       map_f.func = &func;
00080       ApplyUnary<T,R,T2,R2,true,true>::apply(map_f,m,m2);
00081     }
00082   };
00083   //-------------------------------------------------------------------------------
00084 
00085   //-------------------------------------------------------------------------------
00086   template<class T,int R,class T2,int R2> struct Map<T,R,T2,R2,false>
00087   //-------------------------------------------------------------------------------
00088   {
00089     //need an operator=(DMatrixw<...> m) in dmatrix.hpp
00090     /*inline static DMatrix<T2,R2,false> apply(const _Map_Func<T,T2>& func, DMatrix<T,R,false>& m)
00091     {
00092       DMatrix<T2,R2,false> m2(m.getGlobalHeader(),0);
00093       
00094       _ApplyUnary_Map<T,R,T2,R2,false> map_f;
00095       map_f.func = &func;
00096       ApplyUnary<T,R,T2,R2,false,true>::apply(map_f,m,m2);
00097 
00098       return m2;
00099       }*/
00100 
00101     inline static void apply(const _Map_Func<T,T2>& func, DMatrix<T,R,false>& m, DMatrix<T2,R2,false>& m2)
00102     {
00103       _ApplyUnary_Map<T,R,T2,R2,false> map_f;
00104       map_f.func = &func;
00105       ApplyUnary<T,R,T2,R2,false,true>::apply(map_f,m,m2);
00106     }
00107   };
00108   //-------------------------------------------------------------------------------
00109   //================================================================================
00110 
00111 }
00112 
00113 #endif
 All Classes Files Functions Variables Defines