Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Common/vtkLargeInteger.h

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