Wm4TInteger.h

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
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 // N is the number of 32-bit words you want per TInteger.
00029 template <int N>
00030 class TInteger
00031 {
00032 public:
00033     // construction and destruction
00034     TInteger (int i = 0);
00035     TInteger (const TInteger& rkI);
00036     ~TInteger ();
00037 
00038     // assignment
00039     TInteger& operator= (const TInteger& rkI);
00040 
00041     // comparison
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     // arithmetic operations
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     // arithmetic updates
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     // shift operations
00064     TInteger operator<< (int iShift) const;
00065     TInteger operator>> (int iShift) const;
00066 
00067     // shift updates
00068     TInteger& operator<<= (int iShift);
00069     TInteger& operator>>= (int iShift);
00070 
00071 private:
00072     // Support for comparisons.  The return value of Compare is -1 if I0 < I1,
00073     // is 0 if I0 == I1, or is +1 if I0 > I1.
00074     static int Compare (const TInteger& rkI0, const TInteger& rkI1);
00075     int GetSign () const;
00076 
00077     // support for division and modulo
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     // miscellaneous utilities
00088     int GetLeadingBlock () const;
00089     int GetTrailingBlock () const;
00090     int GetLeadingBit (int i) const;  // of m_asBuffer[i]
00091     int GetTrailingBit (int i) const;  // of m_asBuffer[i]
00092     int GetLeadingBit () const;  // of entire number
00093     int GetTrailingBit () const;  // of entire number
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     // TRational needs access to private members of TInteger.
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

Generated on Wed Nov 23 19:01:09 2011 for FreeCAD by  doxygen 1.6.1