00001
00002
00003
00004
00005 #ifndef NDEBUG
00006 #include <cassert>
00007 #endif
00008
00009
00010 #ifndef SYNAPS_ARITHM_RG_H
00011 #define SYNAPS_ARITHM_RG_H
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 __BEGIN_NAMESPACE_SYNAPS
00021
00025 template<class T> struct Rg
00026 {
00027 public:
00028 shared_object<T> data;
00029 T & rep() {return *data;}
00030 const T & rep() const {return *data;}
00031
00032 Rg () {init(rep());}
00033 Rg (const Rg<T>& b) { init(rep()); data=b.data; }
00034 Rg (const T& t): data(t) {}
00035 Rg (signed long sl) {init_set(rep(),sl);}
00036 Rg (unsigned long ul) {init_set(rep(),ul);}
00037 Rg (int si) {init_set(rep(),si);}
00038 Rg (const char* str, unsigned int b=10) {init_set(rep(),str,b);}
00039
00040 ~Rg () {};
00041
00042
00043 template<class X> Rg<T> operator == (const VAL<X>& rhs) const
00044 {assign(this->rep(),rhs.rep());}
00045
00046 template<class X> bool operator == (const X& rhs) const
00047 { return cmp(rep(),rhs) ==0 ; }
00048 template<class X> bool operator != (const X& rhs) const
00049 { return cmp(rep(),rhs)!=0; }
00050 template<class X> bool operator > (const X& rhs) const
00051 { return cmp(rep(),rhs)>0; }
00052 template<class X> bool operator >= (const X& rhs) const
00053 { return cmp(rep(),rhs)>=0; }
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
00059 Rg<T>& operator = (const Rg<T>& rhs) {data=rhs.data; return *this;}
00060 template<class X> Rg<T>& operator += (const X & rhs)
00061 {*this=*this+rhs; return *this;}
00062 template<class X> Rg<T>& operator -= (const X & rhs)
00063 {*this=*this-rhs; return *this;}
00064 template<class X> Rg<T>& operator *= (const X & rhs)
00065 {*this=*this*rhs; return *this;}
00066 template<class X> Rg<T>& operator /= (const X & rhs)
00067 { assert(rhs!=0); *this=*this/rhs; return *this;}
00068 template<class X> Rg<T>& operator %= (const X & rhs)
00069 { assert(rhs!=0); *this=*this%rhs; return *this;}
00070
00071 void operator ++ ( );
00072 void operator -- ( );
00073
00074 };
00075
00077 template <class R> inline
00078 ostream & operator<<(ostream & os, const Rg<R> & p)
00079 {
00080 return Print(os,p.rep());
00081 }
00082
00083
00084
00085 template <class R> inline
00086 const Rg<R> operator+(const Rg<R> & a, const Rg<R> & b)
00087 {
00088 Rg<R> r; add(r.rep(),a.rep(),b.rep()); return r;
00089 }
00090 template<class R> inline
00091 const Rg<R> operator+(const Rg<R> & a, const int & b)
00092 {
00093 Rg<R> r; add(r.rep(),a.rep(),b); return r;
00094 }
00095 template<class R> inline
00096 const Rg<R> operator+(const int & b, const Rg<R> & a)
00097 {
00098 return a+b;
00099 }
00100
00101 template <class R> inline
00102 const Rg<R> operator-(const Rg<R> & a, const Rg<R> & b)
00103 {
00104 Rg<R> r; sub(r.rep(),a.rep(),b.rep()); return r;
00105 }
00106 template<class R> inline
00107 const Rg<R> operator-(const Rg<R> & a, const int & b)
00108 {
00109 Rg<R> r; sub(r.rep(),a.rep(),b); return r;
00110 }
00111 template<class R> inline
00112 const Rg<R> & operator-(const int & b, const Rg<R> & a)
00113 {
00114 return a+(-b);
00115 }
00116
00117 template<class R> inline
00118 const Rg<R> operator*(const Rg<R> & a, const Rg<R> & b)
00119 {
00120 Rg<R> r; mul(r.rep(),a.rep(),b.rep()); return r;
00121 }
00122
00123 template<class R> inline
00124 const Rg<R> operator*(const Rg<R> & a, int b)
00125 {
00126 Rg<R> r; mul(r.rep(),a.rep(),b); return r;
00127 }
00128 template<class R> inline
00129 const Rg<R> operator*(int b, const Rg<R> & a)
00130 {
00131 return a*b;
00132 }
00133
00134 template<class T> inline
00135 Rg<T>& operator - (const Rg<T>& b)
00136 {
00137 Rg<T> r(b); return (r.negate());
00138 }
00139
00140
00141 template <class R> inline
00142 const Rg<R> operator/(const Rg<R> & a, const Rg<R> & b)
00143 {
00144 assert(b!=0);
00145 Rg<R> r; div(r.rep(),a.rep(),b.rep()); return r;
00146 }
00147
00148 template <class R> inline
00149 const Rg<R> operator/(const Rg<R> & a, unsigned int b)
00150 {
00151 assert(b!=0);
00152 Rg<R> r; div(r.rep(),a.rep(),b); return r;
00153 }
00154
00155
00156 template <class R> inline
00157 const Rg<R> operator%(const Rg<R> & a, const Rg<R> & b)
00158 {
00159 assert(b!=0);
00160 Rg<R> r; mod(r.rep(),a.rep(),b.rep()); return r;
00161 }
00162
00163 template <class R> inline
00164 const Rg<R> operator%(const Rg<R> & a, unsigned int b)
00165 {
00166 assert(b!=0);
00167 Rg<R> r; mod(r.rep(),a.rep(),b); return r;
00168 }
00169
00170
00171 __END_NAMESPACE_SYNAPS
00172
00173 #endif // SYNAPS_ARITHM_RG_H
00174
00175