Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/Math/nb/Integer.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__INTEGER_HPP__
00002 #define __J2K__INTEGER_HPP__
00003 
00004 #include <j2k/Fred/Number/MathStat.hpp>
00005 #include <stdlib.h>
00006 
00007 class Integer {
00008 //: public Object {
00009   public:
00010     inline Integer() : value(0), status( Valid ) {
00011        verify();
00012     }
00013 
00014     inline Integer(int i) : value(i), status( Valid ) { 
00015        verify();
00016     }
00017 
00018     inline Integer(int i, enum MathState s) : value(i), status( s ) {
00019        verify();
00020     }
00021 
00022     inline Integer(const char *s) {
00023       status = Valid;  // SHOULD check if s = "NaN", etc.
00024       value  = atoi(s);
00025     }
00026 
00027     Integer(const Integer &I)
00028       : value( I.value ), status( I.status ) { }
00029 
00030     inline virtual ~Integer() { }
00031 
00032     friend ostream& operator<<(ostream& os, Integer& I) {
00033       unsigned int state = (unsigned int)(I.status);
00034       if ( !state ) {
00035         return os << I.value;
00036       } else if ( state < J2K_MAX_MathState ) {
00037         return os << MathStateTxt[ state ];
00038       }
00039 
00040       // Something weird occured, if this get executed !
00041       abort();  
00042       return os << "";
00043 
00044     }
00045 
00046     // operator overloads
00047 
00048     inline operator int () const {
00049    return value;
00050     }
00051     inline const Integer &operator=(int i) {
00052    value=i;
00053    return *this;
00054     }
00055     friend bool operator==(const Integer &l,const Integer &r);
00056     friend bool operator!=(const Integer &l,const Integer &r);
00057     friend bool operator<(const Integer &l,const Integer &r);
00058     friend bool operator<=(const Integer &l,const Integer &r);
00059     friend bool operator>(const Integer &l,const Integer &r);
00060     friend bool operator>=(const Integer &l,const Integer &r);
00061 
00062     friend Integer operator+(const Integer &l,const Integer &r);
00063     friend Integer operator-(const Integer &l,const Integer &r);
00064     friend Integer operator*(const Integer &l,const Integer &r);
00065     friend Integer operator/(const Integer &l,const Integer &r);
00066     friend Integer operator<<(const Integer &l,const Integer &r);
00067     friend Integer operator>>(const Integer &l,const Integer &r);
00068     friend Integer operator|(const Integer &l,const Integer &r);
00069     friend Integer operator&(const Integer &l,const Integer &r);
00070     friend Integer operator^(const Integer &l,const Integer &r);
00071 
00072     inline Integer operator!() {
00073    return Integer(!value);
00074     }
00075     inline Integer operator-() {
00076    return Integer(-value);
00077     }
00078     inline Integer operator~() {
00079    return Integer(~value);
00080     }
00081     inline Integer operator--() {
00082    return Integer(--value);
00083     }
00084     inline Integer operator--(int) {
00085    return Integer(value--);
00086     }
00087     inline Integer operator++() {
00088    return Integer(++value);
00089     }
00090     inline Integer operator++(int) {
00091    return Integer(value++);
00092     }
00093 
00094 /*
00095     // Object methods
00096     Object *Copy() const;
00097 
00098     void Serialize(Serializer &) const;
00099     void Deserialize(Deserializer &);
00100 
00101     unsigned int hash() const;
00102     String toString() const;
00103 
00104     declareSerializable(Integer);
00105   protected:
00106     bool Equals(const Object &o) const;
00107     bool lessThan(const Object &o) const;
00108     bool lessThanEquals(const Object &o) const;
00109 */
00110 
00111   private:
00112     int value;
00113     enum MathState status;
00114 };
00115 
00116 inline bool operator==(const Integer &l,const Integer &r) {
00117     return l.value==r.value;
00118 }
00119 
00120 inline bool operator!=(const Integer &l,const Integer &r) {
00121     return l.value!=r.value;
00122 }
00123 
00124 inline bool operator<(const Integer &l,const Integer &r) {
00125     return l.value<r.value;
00126 }
00127 
00128 inline bool operator<=(const Integer &l,const Integer &r) {
00129     return l.value<=r.value;
00130 }
00131 
00132 inline bool operator>(const Integer &l,const Integer &r) {
00133     return l.value>r.value;
00134 }
00135 
00136 inline bool operator>=(const Integer &l,const Integer &r) {
00137     return l.value>=r.value;
00138 }
00139 
00140 inline Integer operator+(const Integer &l,const Integer &r) {
00141     return Integer(l.value+r.value);
00142 }
00143 
00144 inline Integer operator-(const Integer &l,const Integer &r) {
00145     return Integer(l.value-r.value);
00146 }
00147 
00148 inline Integer operator*(const Integer &l,const Integer &r) {
00149     return Integer(l.value*r.value);
00150 }
00151 
00152 inline Integer operator/(const Integer &l,const Integer &r) {
00153     return Integer(l.value/r.value);
00154 }
00155 
00156 inline Integer operator<<(const Integer &l,const Integer &r) {
00157     return Integer(l.value<<r.value);
00158 }
00159 
00160 inline Integer operator>>(const Integer &l,const Integer &r) {
00161     return Integer(l.value>>r.value);
00162 }
00163 
00164 inline Integer operator|(const Integer &l,const Integer &r) {
00165     return Integer(l.value|r.value);
00166 }
00167 
00168 inline Integer operator&(const Integer &l,const Integer &r) {
00169     return Integer(l.value&r.value);
00170 }
00171 
00172 inline Integer operator^(const Integer &l,const Integer &r) {
00173     return Integer(l.value^r.value);
00174 }
00175 
00176 #endif

Generated on Sun Oct 14 18:46:13 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001