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

spl/UInt32.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 _uint32_h
00018 #define _uint32_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Int32.h>
00022 #include <spl/Numeric.h>
00023 #include <spl/String.h>
00024 
00025 #ifdef HAVE_LIMITS_H
00026 #include <limits.h>
00027 #endif
00028 
00035 #define UINT32_MAJIC 0x0012             //< Majic number for ASSERT's in Compare and Convert
00036 
00040 class UInt32 : public Numeric
00041 {
00042 private:
00043         uint32 m_val;
00044 public:
00045         UInt32();
00046         UInt32(const uint32 i);
00047         UInt32(const UInt32& i);
00048         virtual ~UInt32();
00049 
00050         virtual int32 HashCode() const;
00051 
00052         virtual bool Equals(const IComparable *a) const;
00053         virtual int Compare(const IComparable *a) const;
00054         virtual bool Equals( const IComparable& a ) const;
00055         virtual int Compare( const IComparable& a ) const;
00056         virtual int32 MajicNumber() const;
00057 
00058         virtual int ToInt() const;
00059         virtual double ToDouble() const;
00060         virtual StringPtr ToString() const;
00061 
00062         inline operator uint32()
00063         {
00064                 return m_val;
00065         }
00066 
00067 #ifdef DEBUG
00068         virtual void ValidateMem() const;
00069         virtual void CheckMem() const;
00070 #endif
00071 
00072 public:
00073         static uint32 Parse(const char *cp, const int cplen, int radix);
00074         inline static uint32 Parse(const char *cp, const int cplen) { return Parse(cp, cplen, 10); }
00075         inline static uint32 Parse(const String& str) { return Parse(str.GetChars(), str.Length(), 10); }
00076         inline static uint32 Parse(const String *str) { return Parse(str->GetChars(), str->Length(), 10); }
00077         inline static uint32 Parse(const String& str, int radix) { return Parse(str.GetChars(), str.Length(), radix); }
00078         inline static uint32 Parse(const String *str, int radix) { return Parse(str->GetChars(), str->Length(), radix); }
00079 
00080         inline static bool IsInt(const char *cp, const int cplen, int radix) { return cp[0] != '-' && cp[0] != '+' && Int32::IsInt(cp, cplen, radix); }
00081         inline static bool IsInt(const char *cp, const int cplen) { return cp[0] != '-' && IsInt(cp, cplen, 10); }
00082         inline static bool IsInt(const String& str) { return IsInt(str.GetChars(), str.Length(), 10); }
00083         inline static bool IsInt(const String *str) { return IsInt(str->GetChars(), str->Length(), 10); }
00084         inline static bool IsInt(const String& str, int radix) { return IsInt(str.GetChars(), str.Length(), radix); }
00085         inline static bool IsInt(const String *str, int radix) { return IsInt(str->GetChars(), str->Length(), radix); }
00086 
00087         static StringPtr ToString(uint32 i, int radix);
00088         inline static StringPtr ToString(uint32 i) { return ToString(i, 10); }
00089 
00090         inline static uint32 MaxValue() { return UINT_MAX; }
00091         inline static uint32 MinValue() { return 0; }
00092 };
00093 
00094 REGISTER_TYPEOF( 576, UInt32 );
00095 
00098 #endif