synaps/arithm/let.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS library.       *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 History:
00006 $Id: let.h,v 1.3 2005/09/28 06:40:43 mourrain Exp $
00007 **********************************************************************/
00008 #ifndef synaps_arithm_let_H
00009 #define synaps_arithm_let_H
00010 //--------------------------------------------------------------------
00011 #include <cstdlib>
00012 #include <complex>
00013 #include <iostream>
00014 #include <synaps/init.h>
00015 #include <synaps/base/type.h>
00016 #include <synaps/arithm/let.h>
00017 
00018 //--------------------------------------------------------------------
00019 namespace std {template<class C> struct complex;}
00020 //--------------------------------------------------------------------
00021 __BEGIN_NAMESPACE_SYNAPS
00022 //====================================================================
00024 
00030 namespace let {
00031   //--------------------------------------------------------------------
00032   //  template<class A, class B> inline void assign(A& a, const B& b);
00033   //--------------------------------------------------------------------
00035   template<class A, class B> inline void assign(A& a, const B & b)
00036   {
00037     //PRT_DEBUG("generic assign");
00038     a=b;
00039   }
00040   //  template<class A> inline void assign(A& a, const A& b) {a=b;};
00041   //--------------------------------------------------------------------
00042   template<class A, class B> void copy( A & a, const B& b );
00043   //--------------------------------------------------------------------
00044 
00045   inline void assign( int & a, double d ) { a =  (int)rint(d); };
00046   //--------------------------------------------------------------------
00047   inline void assign(double & d, int i)        {d = double(i);}
00048   inline void assign(double & d, unsigned i)   {d = double(i);}
00049   inline void assign(double & d, double z)     {d = z;}
00050   //--------------------------------------------------------------------
00052   template<class X> inline
00053   const X & convert(const X& x, const type::As<X>& mth)
00054   {
00055     return x;
00056   }
00057   template<class X, class Y> inline
00058   Y  convert(const X& x, const type::As<Y>& mth )
00059   {
00060     return (Y)x;
00061   };
00062   //--------------------------------------------------------------------
00063   template < typename FT,
00064              typename T > inline
00065   FT convert(const T& a, const T& b, const type::As<FT>& mth)   {return FT(a, b); }
00066 
00067   template<class T> 
00068   double convert(const T&  a, const T& b, const type::As<double>& mth) 
00069   {
00070     double u,v;
00071     assign(u,a); assign(v,b);
00072     return  u/v;
00073   }
00074   inline double convert(double a, double b, const type::As<double>& mth) {return  a/b;}
00075 
00076   template<class C> inline
00077   void assign(std::complex<C> & z, const C& x) { z= std::complex<C>(x);}
00078   //--------------------------------------------------------------------
00079   template<class X> inline void assign(X & a, char *s) { a = X(s); }
00080   //----------------------------------------------------------------------
00081   template<> inline void assign(int &i, char *s)      {i = atoi(s);}
00082   template<> inline void assign(long int &i,  char *s) {i = atol(s);}
00083   //----------------------------------------------------------------------
00084 #ifndef __CYGWIN__
00085   template<> inline void assign(long long int &i,char *s) {i = atoll(s);}
00086 #endif //__CYGWIN__
00087   //----------------------------------------------------------------------
00088   //  template<> 
00089   inline void assign(float & d,  char* s)       {d = atof(s);}
00090   //  template<> 
00091   inline void assign(double & d,  char* s)                 {d = atof(s);}
00092   //  template<> 
00093   inline void assign(long double & d, char *s) {d = atof(s);}
00094   //--------------------------------------------------------------------
00095   inline void assign(std::complex<double> & z, const char* s) 
00096   {
00097     z = std::complex<double>(atof(s),0);
00098   }
00099   //------------------------------------------------------------------
00100   
00101 
00102   //--------------------------------------------------------------------
00103 }
00104 //========================================================================
00105 __END_NAMESPACE_SYNAPS
00106 #endif // synaps_arithm_let_H
00107 

SYNAPS DOCUMENTATION
logo