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

spl/GUID.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 _guid_h
00018 #define _guid_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 #include <spl/collection/Array.h>
00023 #include <spl/RefCountPtr.h>
00024 #include <spl/String.h>
00025 
00032 #define GUID_SIZE_BYTES 16
00033 
00038 class Guid
00039 {
00040 protected:
00041         uint32 data1;
00042         uint16 data2;
00043         uint16 data3;
00044         uint64 data4;
00045 
00046 public:
00047         Guid();
00048         Guid( const Array<byte>& bytes );
00049         Guid( const Guid& guid );
00050         ~Guid();
00051 
00052         inline static int Length() { return GUID_SIZE_BYTES; }
00053 
00054         void GetBytes( Array<byte>& bytes ) const;
00055         Array<byte> GetBytes() const;
00056         StringPtr ToBase64();
00057         StringPtr ToHex();
00058 
00059         inline bool Equals( const Guid& g ) { return data1 == g.data1 && data2 == g.data2 && data3 == g.data3 && data4 == g.data4; }
00060         
00061         static Guid ParseBase64(const String& str);
00062         static Guid ParseHex(const String& str);
00063 };
00064 
00065 inline void ValidateType( const Guid& guid )
00066 {
00067 }
00068 
00069 inline void ValidateType ( Guid *guid )
00070 {
00071         DEBUG_NOTE_MEM(guid);
00072         ASSERT_MEM(guid, sizeof(Guid));
00073 }
00074 
00075 REGISTER_TYPEOF( 564, Guid );
00076 
00079 #endif