synaps/arithm/GENERIC.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS library.       *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 $Id: GENERIC.h,v 1.1 2005/07/11 10:39:47 mourrain Exp $
00006 **********************************************************************/
00007 #ifndef SYNAPS_ARITHM_GENERIC_H
00008 #define SYNAPS_ARITHM_GENERIC_H
00009 //--------------------------------------------------------------------
00010 #include <iostream>
00011 #include <synaps/init.h>
00012 //--------------------------------------------------------------------
00013 __BEGIN_NAMESPACE_SYNAPS
00014 //----------------------------------------------------------------------
00015 template<class R> struct Coef;
00016 template<class R> struct Ind;
00017 //----------------------------------------------------------------------
00018 template<class T> class cat;
00019 //----------------------------------------------------------------------
00020 template<class T> struct Info;
00021 //----------------------------------------------------------------------
00022 template <typename T>
00023 class OPTraits {
00024 public:
00025   typedef T const & OP_node_ref;
00026 };
00027 //----------------------------------------------------------------------
00028 template <char O, class A, class B> 
00029 struct OP {
00030   typename OPTraits<A>::OP_node_ref op1;
00031   typename OPTraits<B>::OP_node_ref op2;
00032   OP () {};
00033   OP(const OP<O,A,B> &  p): op1(p.op1), op2(p.op2) {};
00034   OP(const A & a, const B & b) : op1(a), op2(b) {};
00035 };
00036 //----------------------------------------------------------------------
00037 template<char O, class R, class T> struct Coef<OP<O,R,T> >
00038 {
00039   typedef typename Coef<R>::value_type value_type;
00040 };
00041 //----------------------------------------------------------------------
00042 template<char O, class T, class R> struct Ind<OP<O,R,T> >
00043 {
00044   typedef typename R::size_type size_type;
00045 };
00046 //----------------------------------------------------------------------
00047 template<char O, class R, class T> struct Info<OP<O,R,T> >
00048 {
00049   typedef typename Info<R>::value_type  value_type;
00050   typedef typename Info<R>::size_type size_type;
00051 };
00052 //----------------------------------------------------------------------
00053 template<>
00054 class OPTraits<char> {
00055 public:
00056   typedef const char OP_node_ref;
00057 };
00058 template<>
00059 class OPTraits<unsigned char> {
00060 public:
00061   typedef const unsigned char OP_node_ref;
00062 };
00063 template<>
00064 class OPTraits<int> {
00065 public:
00066   typedef const int OP_node_ref;
00067 };
00068 template<>
00069 class OPTraits<unsigned int> {
00070 public:
00071   typedef const unsigned int OP_node_ref;
00072 };
00073 template<>
00074 class OPTraits<long> {
00075 public:
00076   typedef const long OP_node_ref;
00077 };
00078 template<>
00079 class OPTraits<unsigned long> {
00080 public:
00081   typedef const unsigned long OP_node_ref;
00082 };
00083 template<>
00084 class OPTraits<float> {
00085 public:
00086   typedef const float OP_node_ref;
00087 };
00088 template<>
00089 class OPTraits<double> {
00090 public:
00091   typedef const double OP_node_ref;
00092 };
00093 //----------------------------------------------------------------------
00094 template <char O, class A, class B> 
00095 struct S_OP {
00096   const A & op1;
00097   const B & op2;
00098   S_OP () {};
00099   S_OP(const OP<O,A,B> &  p): op1(p.op1), op2(p.op2) {};
00100   S_OP(const A & a, const B & b) : op1(a), op2(b) {};
00101 };
00102 //----------------------------------------------------------------------
00103 template<char O, class R, class T> struct Coef<S_OP<O,R,T> >
00104 {
00105   typedef typename Coef<R>::value_type value_type;
00106 };
00107 //----------------------------------------------------------------------
00108 template<char O, class T, class R> struct Ind<S_OP<O,R,T> >
00109 {
00110   typedef typename R::size_type size_type;
00111 };
00112 //====================================================================
00113 template <class A> 
00114 struct UMinus {
00115   const A & op;
00116   UMinus () {};
00117   UMinus(const UMinus<A> &  p): op(p.op) {};
00118   UMinus(const A & a) : op(a){};
00119 };
00120 //--------------------------------------------------------------------
00121 template <class R> struct Coef
00122 {
00123   typedef typename R::value_type value_type;
00124 };
00125 template <class R> struct Ind
00126 {
00127   typedef typename R::size_type size_type;
00128 };
00129 //----------------------------------------------------------------------
00130 template<class R, class T> struct Coef<OP<'+',R,T> >
00131 {
00132   typedef typename Coef<R>::value_type value_type;
00133 };
00134 
00135 template <class T, class R> struct Ind<OP<'+',R,T> >
00136 {
00137   typedef typename R::size_type size_type;
00138 };
00139 
00140 //----------------------------------------------------------------------
00141 template<class R, class T> struct Info<OP<'+',R,T> >
00142 {
00143   typedef typename Info<R>::value_type  value_type;
00144   typedef typename Info<R>::size_type size_type;
00145 };
00146 
00147 //---------------------------------------------------------------------
00148 template <class T, class R> struct Coef<OP<'-',R,T> >
00149 {
00150   typedef typename R::value_type value_type;
00151 };
00152 
00153 template <class T, class R> struct Ind<OP<'-',R,T> >
00154 {
00155   typedef typename R::size_type size_type;
00156 };
00157 //--------------------------------------------------------------------
00158 template <class T, class R> struct Coef<OP<'*',R,T> >
00159 {
00160   typedef typename R::value_type value_type;
00161 };
00162 
00163 template <class T, class R> struct Ind<OP<'*',R,T> >
00164 {
00165   typedef typename R::size_type size_type;
00166 };
00167 //-------------------------------------------------------------------
00168 template <class T, class R> struct Coef<OP<'.',R,T> >
00169 {
00170   typedef typename R::value_type value_type;
00171 };
00172 
00173 template <class T, class R> struct Ind<OP<'.',R,T> >
00174 {
00175   typedef typename R::size_type size_type;
00176 };
00177 //-------------------------------------------------------------------
00178 // template <class T, class R> struct Coef<S_OP<'*',R,T> >
00179 // {
00180 //   typedef typename T::value_type value_type;
00181 // };
00182 
00183 // template <class T, class R> struct Ind<S_OP<'*',R,T> >
00184 // {
00185 //   typedef typename T::size_type size_type;
00186 // };
00187 //------------------------------------------------------------------
00188 // template <class T, class R> struct Coef<Divd<R,T> >
00189 // {
00190 //   typedef typename R::value_type value_type;
00191 // };
00192 
00193 //------------------------------------------------------------------
00194 template <class R> struct Coef<UMinus<R> >
00195 {
00196   typedef typename R::value_type value_type;
00197 };
00198 
00199 template <class R> struct Ind<UMinus<R> >
00200 {
00201   typedef typename R::size_type size_type;
00202 };
00203 //----------------------------------------------------------------------
00204 //struct ostream;
00205 template<char O,class R,class T> inline
00206 std::ostream & operator << (std::ostream & os,const OP<O,R,T> & M)
00207 {
00208   os <<"("<<M.op1<<")"<<O<<"("<<M.op2<<")"; return os;
00209 }
00210 
00211 
00212 __END_NAMESPACE_SYNAPS
00213 
00214 #endif //SYNAPS_ARITHM_GENERIC_H
00215 

SYNAPS DOCUMENTATION
logo