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

spl/Int64.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 _int64_h
00018 #define _int64_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Numeric.h>
00022 #include <spl/String.h>
00023 
00024 #ifdef HAVE_LIMITS_H
00025 #include <limits.h>
00026 #endif
00027 
00034 #define INT64_MAJIC 0x0011              //< Majic number for ASSERT's in Compare and Convert
00035 
00039 class Int64 : public Numeric
00040 {
00041 private:
00042         int64 m_val;
00043 public:
00044         Int64();
00045         Int64(const int64 i);
00046         Int64(const Int64& i);
00047         virtual ~Int64();
00048 
00049         virtual int32 HashCode() const;
00050 
00051         virtual bool Equals(const IComparable *a) const;
00052         virtual int Compare(const IComparable *a) const;
00053         virtual bool Equals( const IComparable& a ) const;
00054         virtual int Compare( const IComparable& a ) const;
00055         virtual int32 MajicNumber() const;
00056 
00057         virtual int ToInt() const;
00058         virtual double ToDouble() const;
00059         virtual StringPtr ToString() const;
00060 
00061         inline operator int64()
00062         {
00063                 return m_val;
00064         }
00065 
00066 #ifdef DEBUG
00067         virtual void ValidateMem() const;
00068         virtual void CheckMem() const;
00069 #endif
00070 
00071 public:
00072         static int64 Parse(const char *cp, const int cplen);
00073         inline static int64 Parse(const String& str) { return Parse(str.GetChars(), str.Length()); }
00074         inline static int64 Parse(const String *str) { return Parse(str->GetChars(), str->Length()); }
00075 
00076 
00077         static bool IsInt(const char *cp, const int cplen);             
00078         inline static bool IsInt(const String& str) { return IsInt(str.GetChars(), str.Length()); }
00079         inline static bool IsInt(const String *str) { return IsInt(str->GetChars(), str->Length()); }
00080 
00081         static StringPtr ToString(int64 i, int numberBase);
00082         inline static StringPtr ToString(int64 i) { return ToString(i, 10); }
00083 
00084         inline static int64 MaxValue() 
00085         { 
00086 #ifdef LLONG_MAX
00087                 return LLONG_MAX; 
00088 #elif _MSC_VER > 1200
00089                 return IL_MAX_INT64;
00090 #else
00091                 return 9223372036854775807;
00092 #endif
00093         }
00094         
00095         inline static int64 MinValue() 
00096         { 
00097 #ifdef LLONG_MIN
00098                 return LLONG_MIN; 
00099 #elif _MSC_VER > 1200
00100                 return IL_MIN_INT64;
00101 #else
00102                 return -int64(9223372036854775808);
00103 #endif
00104         }
00105 };
00106 
00107 REGISTER_TYPEOF( 568, Int64 );
00108 
00111 #endif