00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkLargeInteger.h,v $ 00005 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00033 #ifndef __vtkLargeInteger_h 00034 #define __vtkLargeInteger_h 00035 00036 #include "vtkObject.h" 00037 00038 class VTK_COMMON_EXPORT vtkLargeInteger 00039 { 00040 public: 00041 vtkLargeInteger(void); 00042 vtkLargeInteger(long n); 00043 vtkLargeInteger(unsigned long n); 00044 vtkLargeInteger(int n); 00045 vtkLargeInteger(unsigned int n); 00046 vtkLargeInteger(const vtkLargeInteger& n); 00047 ~vtkLargeInteger(void); 00048 00049 char CastToChar(void) const; 00050 short CastToShort(void) const; 00051 int CastToInt(void) const; 00052 long CastToLong(void) const; 00053 unsigned long CastToUnsignedLong(void) const; 00054 00055 int IsEven(void) const; 00056 int IsOdd(void) const; 00057 int GetLength(void) const; // in bits 00058 int GetBit(unsigned int p) const; // p'th bit (from zero) 00059 int IsZero() const; // is zero 00060 int GetSign(void) const; // is negative 00061 00062 void Truncate(unsigned int n); // reduce to lower n bits 00063 void Complement(void); // * -1 00064 00065 int operator==(const vtkLargeInteger& n) const; 00066 int operator!=(const vtkLargeInteger& n) const; 00067 int operator<(const vtkLargeInteger& n) const; 00068 int operator<=(const vtkLargeInteger& n) const; 00069 int operator>(const vtkLargeInteger& n) const; 00070 int operator>=(const vtkLargeInteger& n) const; 00071 00072 vtkLargeInteger& operator=(const vtkLargeInteger& n); 00073 vtkLargeInteger& operator+=(const vtkLargeInteger& n); 00074 vtkLargeInteger& operator-=(const vtkLargeInteger& n); 00075 vtkLargeInteger& operator<<=(int n); 00076 vtkLargeInteger& operator>>=(int n); 00077 vtkLargeInteger& operator++(void); 00078 vtkLargeInteger& operator--(void); 00079 vtkLargeInteger operator++(int); 00080 vtkLargeInteger operator--(int); 00081 vtkLargeInteger& operator*=(const vtkLargeInteger& n); 00082 vtkLargeInteger& operator/=(const vtkLargeInteger& n); 00083 vtkLargeInteger& operator%=(const vtkLargeInteger& n); 00084 // no change of sign for following operators 00085 vtkLargeInteger& operator&=(const vtkLargeInteger& n); 00086 vtkLargeInteger& operator|=(const vtkLargeInteger& n); 00087 vtkLargeInteger& operator^=(const vtkLargeInteger& n); 00088 00089 vtkLargeInteger operator+(const vtkLargeInteger& n) const; 00090 vtkLargeInteger operator-(const vtkLargeInteger& n) const; 00091 vtkLargeInteger operator*(const vtkLargeInteger& n) const; 00092 vtkLargeInteger operator/(const vtkLargeInteger& n) const; 00093 vtkLargeInteger operator%(const vtkLargeInteger& n) const; 00094 // no change of sign for following operators 00095 vtkLargeInteger operator&(const vtkLargeInteger& n) const; 00096 vtkLargeInteger operator|(const vtkLargeInteger& n) const; 00097 vtkLargeInteger operator^(const vtkLargeInteger& n) const; 00098 vtkLargeInteger operator<<(int n) const; 00099 vtkLargeInteger operator>>(int n) const; 00100 00101 friend ostream& operator<<(ostream& s, const vtkLargeInteger& n); 00102 friend istream& operator>>(istream& s, vtkLargeInteger& n); 00103 00104 private: 00105 char* Number; 00106 int Negative; 00107 unsigned int Sig; 00108 unsigned int Max; 00109 00110 // unsigned operators 00111 int IsSmaller(const vtkLargeInteger& n) const; // unsigned 00112 int IsGreater(const vtkLargeInteger& n) const; // unsigned 00113 void Expand(unsigned int n); // ensure n'th bit exits 00114 void Contract(); // remove leading 0s 00115 void Plus(const vtkLargeInteger& n); // unsigned 00116 void Minus(const vtkLargeInteger& n); // unsigned 00117 }; 00118 00119 #endif 00120 00121