Wm4TInteger.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef WM4TINTEGER_H
00018 #define WM4TINTEGER_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4System.h"
00022 
00023 namespace Wm4
00024 {
00025 
00026 template <int N> class TRational;
00027 
00028 
00029 template <int N>
00030 class TInteger
00031 {
00032 public:
00033     
00034     TInteger (int i = 0);
00035     TInteger (const TInteger& rkI);
00036     ~TInteger ();
00037 
00038     
00039     TInteger& operator= (const TInteger& rkI);
00040 
00041     
00042     bool operator== (const TInteger& rkI) const;
00043     bool operator!= (const TInteger& rkI) const;
00044     bool operator<  (const TInteger& rkI) const;
00045     bool operator<= (const TInteger& rkI) const;
00046     bool operator>  (const TInteger& rkI) const;
00047     bool operator>= (const TInteger& rkI) const;
00048 
00049     
00050     TInteger operator- () const;
00051     TInteger operator+ (const TInteger& rkI) const;
00052     TInteger operator- (const TInteger& rkI) const;
00053     TInteger operator* (const TInteger& rkI) const;
00054     TInteger operator/ (const TInteger& rkI) const;
00055     TInteger operator% (const TInteger& rkI) const;
00056 
00057     
00058     TInteger& operator+= (const TInteger& rkI);
00059     TInteger& operator-= (const TInteger& rkI);
00060     TInteger& operator*= (const TInteger& rkI);
00061     TInteger& operator/= (const TInteger& rkI);
00062 
00063     
00064     TInteger operator<< (int iShift) const;
00065     TInteger operator>> (int iShift) const;
00066 
00067     
00068     TInteger& operator<<= (int iShift);
00069     TInteger& operator>>= (int iShift);
00070 
00071 private:
00072     
00073     
00074     static int Compare (const TInteger& rkI0, const TInteger& rkI1);
00075     int GetSign () const;
00076 
00077     
00078     static bool GetDivMod (const TInteger& rkNumer, const TInteger& rkDenom,
00079         TInteger& rkQuotient, TInteger& rkRemainder);
00080 
00081     static void DivSingle (const TInteger& rkNumer, short usDenom,
00082         TInteger& rkQuo, TInteger& rkRem);
00083 
00084     static void DivMultiple (const TInteger& rkNumer, const TInteger& rkDenom,
00085         TInteger& rkQuo, TInteger& rkRem);
00086 
00087     
00088     int GetLeadingBlock () const;
00089     int GetTrailingBlock () const;
00090     int GetLeadingBit (int i) const;  
00091     int GetTrailingBit (int i) const;  
00092     int GetLeadingBit () const;  
00093     int GetTrailingBit () const;  
00094     void SetBit (int i, bool bOn);
00095     bool GetBit (int i) const;
00096     unsigned int ToUnsignedInt (int i) const;
00097     void FromUnsignedInt (int i, unsigned int uiValue);
00098     unsigned int ToUnsignedInt (int iLo, int iHi) const;
00099     int ToInt (int i) const;
00100 
00101     enum
00102     {
00103         TINT_SIZE = 2*N,
00104         TINT_BYTES = TINT_SIZE*sizeof(short),
00105         TINT_LAST = TINT_SIZE-1
00106     };
00107 
00108     short m_asBuffer[TINT_SIZE];
00109 
00110     
00111     friend class TRational<N>;
00112 };
00113 
00114 template <int N>
00115 TInteger<N> operator* (int i, const TInteger<N>& rkI);
00116 
00117 }
00118 
00119 #include "Wm4TInteger.inl"
00120 
00121 #endif