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

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

Go to the documentation of this file.
00001 #ifndef __J2K__Integer_HPP__
00002 #define __J2K__Integer_HPP__
00003 
00004 #include <j2k/Fred/Math/MathStat.hpp>
00005 #include <j2k/Fred/Math/MCNumber.hpp>
00006 #include <stdlib.h>
00007 
00008 // Long Integer definition
00009 
00010 class Integer {
00011 //: public Object {
00012   public:
00013     inline Integer() : value(0), status( Valid ) {
00014        verify();
00015     }
00016 
00017     inline Integer(long i) : value(i), status( Valid ) { 
00018        verify();
00019     }
00020 
00021     inline Integer(long i, enum MathState s) : value(i), status( s ) {
00022        verify();
00023     }
00024 
00025     inline Integer(const char *s) {
00026       status = getState( s );
00027       value  = atoi(s);
00028 
00029       if ( (int)status < 3 ) { // Change state, only if not Invalid
00030         verify();       
00031       }
00032     }
00033 
00034     Integer(const Integer &I)
00035       : value( I.value ), status( I.status ) { }
00036 
00037     inline virtual ~Integer() { }
00038 
00039     friend ostream& operator<<(ostream& os, Integer& I) {
00040       unsigned int state = (unsigned int)(I.status);
00041       if ( state < 3 ) {
00042         return os << I.value;
00043       } else if ( state < J2K_MAX_MathState ) {
00044         return os << MathStateTxt[ state ];
00045       }
00046 
00047       // Something weird occured, if this get executed !
00048       abort();  
00049       return os << "";
00050 
00051     }
00052 
00053     // operator overloads
00054 
00055     inline operator int() const {
00056        return (int)value;
00057     }
00058 
00059     inline operator long() const {
00060        return (long)value;
00061     }
00062 
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 
00069     inline Integer operator~() {
00070       return Integer( ~value );
00071     }
00072 
00073     // Use macro to define all possible choice
00074     // for arithmetic and compare functions
00075 
00076     MC_Number_Verify( long, 0L )
00077     MC_Number_Operators1( Integer, long )
00078     MC_Number_Operators2( Integer, long, long )
00079     MC_Number_Operators2( Integer, long, float )
00080     MC_Number_Operators2( Integer, long, double )
00081     
00082 /*
00083     // Object methods
00084     Object *Copy() const;
00085 
00086     void Serialize(Serializer &) const;
00087     void Deserialize(Deserializer &);
00088 
00089     unsigned int hash() const;
00090     String toString() const;
00091 
00092     declareSerializable(Integer);
00093   protected:
00094     bool Equals(const Object &o) const;
00095     bool lessThan(const Object &o) const;
00096     bool lessThanEquals(const Object &o) const;
00097 */
00098 
00099   private:
00100     long value;
00101     enum MathState status;
00102 };
00103 
00104 inline Integer operator<<(const Integer &l,const Integer &r) {
00105     return Integer(l.value<<r.value);
00106 }
00107 
00108 inline Integer operator>>(const Integer &l,const Integer &r) {
00109     return Integer(l.value>>r.value);
00110 }
00111 
00112 inline Integer operator|(const Integer &l,const Integer &r) {
00113     return Integer(l.value|r.value);
00114 }
00115 
00116 inline Integer operator&(const Integer &l,const Integer &r) {
00117     return Integer(l.value&r.value);
00118 }
00119 
00120 inline Integer operator^(const Integer &l,const Integer &r) {
00121     return Integer(l.value^r.value);
00122 }
00123 
00124 #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