• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/UInt64.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _uint64_h
00018 #define _uint64_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Int32.h>
00022 #include <spl/Int64.h>
00023 #include <spl/Numeric.h>
00024 #include <spl/String.h>
00025 
00026 #ifdef HAVE_LIMITS_H
00027 #include <limits.h>
00028 #endif
00029 
00036 #define UINT64_MAJIC 0x013              //< Majic number for ASSERT's in Compare and Convert
00037 
00041 class UInt64 : public Numeric
00042 {
00043 private:
00044         uint64 m_val;
00045 public:
00046         UInt64();
00047         UInt64(const uint64 i);
00048         UInt64(const UInt64& i);
00049         virtual ~UInt64();
00050 
00051         virtual int32 HashCode() const;
00052 
00053         virtual bool Equals(const IComparable *a) const;
00054         virtual int Compare(const IComparable *a) const;
00055         virtual bool Equals( const IComparable& a ) const;
00056         virtual int Compare( const IComparable& a ) const;
00057         virtual int32 MajicNumber() const;
00058 
00059         virtual int ToInt() const;
00060         virtual double ToDouble() const;
00061         virtual StringPtr ToString() const;
00062 
00063         inline operator uint64()
00064         {
00065                 return m_val;
00066         }
00067 
00068 #ifdef DEBUG
00069         virtual void ValidateMem() const;
00070         virtual void CheckMem() const;
00071 #endif
00072 
00073 public:
00074         static uint64 Parse(const char *cp, const int cplen, int radix);
00075         inline static uint64 Parse(const char *cp, const int cplen) { return Parse(cp, cplen, 10); }
00076         inline static uint64 Parse(const String& str) { return Parse(str.GetChars(), str.Length(), 10); }
00077         inline static uint64 Parse(const String *str) { return Parse(str->GetChars(), str->Length(), 10); }
00078         inline static uint64 Parse(const String& str, int radix) { return Parse(str.GetChars(), str.Length(), radix); }
00079         inline static uint64 Parse(const String *str, int radix) { return Parse(str->GetChars(), str->Length(), radix); }
00080 
00081         inline static bool IsInt(const char *cp, const int cplen) { return cp[0] != '-' && cp[0] != '+' && Int64::IsInt(cp, cplen); }
00082         inline static bool IsInt(const String& str) { return IsInt(str.GetChars(), str.Length()); }
00083         inline static bool IsInt(const String *str) { return IsInt(str->GetChars(), str->Length()); }
00084 
00085         static StringPtr ToString(uint64 i, int radix);
00086         inline static StringPtr ToString(uint64 i) { return ToString(i, 10); }
00087 
00088         inline static uint64 MaxValue() 
00089         { 
00090 #ifdef ULLONG_MAX
00091                 return ULLONG_MAX;
00092 #elif _MSC_VER > 1200
00093                 return IL_MAX_UINT64; 
00094 #else
00095                 return (int64)0x7FFFFFFFFFFFFFFF;
00096 #endif
00097         }
00098         
00099         inline static uint64 MinValue() { return 0; }
00100 };
00101 
00102 REGISTER_TYPEOF( 578, UInt64 );
00103 
00106 #endif