synaps/arithm/Rg_with_te.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************/
00005 
00006 #ifndef SYNAPS_ARITHM_RG_WITH_TE_H
00007 #define SYNAPS_ARITHM_RG_WITH_TE_H
00008 
00009 #ifndef NDEBUG
00010         #include <cassert>
00011 #endif
00012 
00013 //----------------------------------------------------------------------
00014 #include <synaps/init.h>
00015 #include <synaps/arithm/REF.h>
00016 #include <synaps/base/shared_object.h>
00017 #include <synaps/base/COUNT.h>
00018 //----------------------------------------------------------------------
00019 
00020 
00021 __BEGIN_NAMESPACE_SYNAPS
00022 
00023 
00027 template<class T> struct Rg
00028 {
00029 public:
00030   //data 
00031   shared_object<T>  data; 
00032   T &       rep()       {return (*data);}
00033   const T & rep() const {return (*data);}
00034 
00035   //T data;
00036   //  inline T &       rep()       {return (data);}
00037   //  inline const T & rep() const {return (data);}
00038 
00039   Rg () {init(rep());}
00040   Rg (const Rg<T>& b): data(b.data)       {}
00041   Rg (double d)         {init_set(rep(),d);}
00042   Rg (signed long sl)   {init_set(rep(),sl);}
00043   Rg (unsigned long ul) {init_set(rep(),ul);}
00044   Rg (int si)           {init_set(rep(),si);}
00045   Rg (const char* str, unsigned int b=10)  {init_set(rep(),str,b);}
00046   template<class X>  Rg(const X & P) {init();assign(this,P.rep());}
00047 
00048   ~Rg () { clear(rep()); }
00049 
00050   //-----------------------------------------------------------------
00051   template<class X> Rg<T> operator == (const VAL<X>& rhs) const 
00052     {assign(this->rep(),rhs.rep());}
00053   //-----------------------------------------------------------------
00054   template<class X> bool operator == (const X& rhs) const 
00055     { return cmp(rep(),rhs) ==0 ; }
00056   template<class X> bool operator != (const X& rhs) const
00057     { return cmp(rep(),rhs)!=0; }
00058   template<class X> bool operator >  (const X& rhs) const
00059     { return cmp(rep(),rhs)>0; }
00060   template<class X> bool operator >= (const X& rhs) const
00061     { return cmp(rep(),rhs)>=0; }
00062   template<class X> bool operator <  (const X& rhs) const
00063     { return cmp(rep(),rhs) <0; }
00064   template<class X> bool operator <= (const X& rhs) const
00065     { return cmp(rep(),rhs)<=0; }
00066   //-----------------------------------------------------------------
00067   Rg<T>& operator  = (const Rg<T>& rhs)  {data=rhs.data; return *this;}
00068   Rg<T>& operator += (const Rg<T>& rhs)  {add(rep(),rhs.rep()); return *this;}
00069   Rg<T>& operator -= (const Rg<T>& rhs)  {sub(rep(),rhs.rep()); return *this;}
00070   Rg<T>& operator *= (const Rg<T>& rhs)  {mul(rep(),rhs.rep()); return *this;}
00071   Rg<T>& operator /= (const Rg<T>& rhs) 
00072     { assert(rhs!=0); div(rep(),rhs.rep()); return *this; }
00073   Rg<T>& operator %= (const Rg<T>& rhs) 
00074     { assert(rhs!=0); mod(rep(),rhs.rep()); return *this; }
00075   //-----------------------------------------------------------------
00076   Rg<T>& operator  = (const int& rhs) {rep()=rhs; return *this; }
00077   Rg<T>& operator += (const int& rhs) {add(rep(),rhs); return *this; }
00078   Rg<T>& operator -= (const int& rhs) {sub(rep(),rhs); return *this; }
00079   Rg<T>& operator *= (const int& rhs) {mul(rep(),rhs); return *this; }
00080   Rg<T>& operator /= (const int& rhs) 
00081     { assert(rhs !=0); div(rep(),rhs); return *this; }
00082   Rg<T>& operator %= (const int& rhs)
00083     { assert(rhs!=0); mod(rep(),rhs); return *this; }
00084   //-----------------------------------------------------------------
00085   void                  operator ++ ( );
00086   void                  operator -- ( );
00087   //-----------------------------------------------------------------
00088 };
00089 //======================================================================
00091 template <class R> inline
00092 ostream & operator<<(ostream & os, const  Rg<R> & p)
00093 {
00094   return Print(os,p.rep());
00095 }
00096 //======================================================================
00097 // THE ARITHMETIC OPERATORS
00098 //======================================================================
00099 template <class R> inline
00100 VAL<OP<'+',Rg<R>,Rg<R> > > operator+(const Rg<R> & a, const Rg<R> & b)
00101 {
00102   return VAL<OP<'+',Rg<R>,Rg<R> > >(OP<'+',Rg<R>,Rg<R> >(a,b));
00103 }
00104 template<class R>
00105 VAL<OP<'+',Rg<R>,int> > operator+(const Rg<R> & a, const int & b)
00106 {
00107    return VAL<OP<'+',Rg<R>,int> >(OP<'+',Rg<R>,int>(a,b));
00108 }
00109 template<class R>
00110 VAL<OP<'+',Rg<R>,int> > operator+(const int & b, const Rg<R> & a)
00111 {
00112    return VAL<OP<'+',Rg<R>,int> >(OP<'+',Rg<R>,int>(a,b));
00113 }
00114 //----------------------------------------------------------------------
00115 template <class R> inline
00116 VAL<OP<'-',Rg<R>,Rg<R> > > operator-(const Rg<R> & a, const Rg<R> & b)
00117 {
00118   return VAL<OP<'-',Rg<R>,Rg<R> > >(OP<'-',Rg<R>,Rg<R> >(a,b));
00119 }
00120 template<class R>
00121 VAL<OP<'-',Rg<R>,int> > operator-(const Rg<R> & a, const int & b)
00122 {
00123    return VAL<OP<'-',Rg<R>,int> >(OP<'-',Rg<R>,int>(a,b));
00124 }
00125 template<class R>
00126 VAL<OP<'-',Rg<R>,int> > operator-(const int & b, const Rg<R> & a)
00127 {
00128    return VAL<OP<'-',Rg<R>,int> >(OP<'-',Rg<R>,int>(a,b));
00129 }
00130 //----------------------------------------------------------------------
00131 template<class R, class Y>
00132 VAL<OP<'*',Rg<R>,Y> > operator*(const Rg<R> & a, const Y & b)
00133 {
00134    return VAL<OP<'*',Rg<R>,Y> >(OP<'*',Rg<R>,Y>(a,b));
00135 }
00136 //----------------------------------------------------------------------
00137 template<class T> inline 
00138 Rg<T>& operator - (const Rg<T>& b) 
00139 {
00140   Rg<T> r(b); return (r.negate());
00141 }
00142 //----------------------------------------------------------------------
00143 // Product of polynomials 
00144 template <class R>  inline 
00145 VAL<OP<'*',Rg<R>,Rg<R> > > operator*(const Rg<R> & a, const Rg<R> & b)
00146 {
00147   return VAL<OP<'*',Rg<R>,Rg<R> > >(OP<'*',Rg<R>,Rg<R> >(a,b));
00148 }
00149 //----------------------------------------------------------------------
00150 // Division of polynomials 
00151 template <class R>  inline 
00152 VAL<OP<'/',Rg<R>,Rg<R> > > operator/(const Rg<R> & a, const Rg<R> & b)
00153 {
00154   assert(b!=0);
00155   return VAL<OP<'/',Rg<R>,Rg<R> > >(OP<'/',Rg<R>,Rg<R> >(a,b));
00156 }
00157 //----------------------------------------------------------------------
00158 // Division of polynomials 
00159 template <class R>  inline 
00160 VAL<OP<'%',Rg<R>,Rg<R> > > operator%(const Rg<R> & a, const Rg<R> & b)
00161 {
00162   assert(b!=0);
00163   return VAL<OP<'%',Rg<R>,Rg<R> > >(OP<'%',Rg<R>,Rg<R> >(a,b));
00164 }
00165 //----------------------------------------------------------------------
00166 // template<class T,class X> Rg<T>& operator + (const Rg<T>& b, const X& x)
00167 // template<class T,class X> Rg<T>& operator - (const Rg<T>& b, const X& x);
00168 // template<class T,class X> Rg<T>& operator * (const Rg<T>& b, const X& x);
00169 // template<class T,class X> Rg<T>& operator % (const Rg<T>& b, const X& x);
00170 //----------------------------------------------------------------------
00171 
00172 __END_NAMESPACE_SYNAPS
00173 
00174 #endif // SYNAPS_ARITHM_RG_WITH_TE_H
00175 
00176 

SYNAPS DOCUMENTATION
logo