Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_GUID_H__
00024 #define __MYGUI_GUID_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Types.h"
00028
00029 namespace MyGUI
00030 {
00031
00032 class MYGUI_EXPORT Guid
00033 {
00034 public:
00035 Guid() { fast._data1 = fast._data2 = fast._data3 = fast._data4 = 0; }
00036 Guid( Guid const& _value ) { *this = _value; }
00037 explicit Guid(const std::string& _value) { *this = parse(_value); }
00038 explicit Guid(unsigned char(&_id)[16]) { ::memcpy((void*)&vec._data1[0], (void*)&_id[0], 16); }
00039
00040 bool operator == (Guid const& _comp) const
00041 {
00042 return _comp.fast._data1 == fast._data1
00043 && _comp.fast._data2 == fast._data2
00044 && _comp.fast._data3 == fast._data3
00045 && _comp.fast._data4 == fast._data4;
00046 }
00047
00048 bool operator != ( Guid const& _comp ) const
00049 {
00050 return ! (*this == _comp);
00051 }
00052
00053 bool operator < ( Guid const& _comp ) const
00054 {
00055 if (_comp.fast._data1 < fast._data1) return true;
00056 else if (_comp.fast._data1 > fast._data1) return false;
00057 if (_comp.fast._data2 < fast._data2) return true;
00058 else if (_comp.fast._data2 > fast._data2) return false;
00059 if (_comp.fast._data3 < fast._data3) return true;
00060 else if (_comp.fast._data3 > fast._data3) return false;
00061 if (_comp.fast._data4 < fast._data4) return true;
00062 return false;
00063 }
00064
00065 Guid& operator = (Guid const& _rvalue)
00066 {
00067 fast._data1 = _rvalue.fast._data1;
00068 fast._data2 = _rvalue.fast._data2;
00069 fast._data3 = _rvalue.fast._data3;
00070 fast._data4 = _rvalue.fast._data4;
00071 return *this;
00072 }
00073
00074 bool empty() const
00075 {
00076 return fast._data1 == 0
00077 && fast._data2 == 0
00078 && fast._data3 == 0
00079 && fast._data4 == 0;
00080 }
00081
00082 void clear()
00083 {
00084 fast._data1 = fast._data2 = fast._data3 = fast._data4 = 0;
00085 }
00086
00087 std::string print() const;
00088 static Guid parse(const std::string& _value);
00089 static Guid generate();
00090
00091 friend std::ostream& operator << ( std::ostream& _stream, const Guid& _value )
00092 {
00093 _stream << _value.print();
00094 return _stream;
00095 }
00096
00097 friend std::istream& operator >> ( std::istream& _stream, Guid& _value )
00098 {
00099 std::string value;
00100 _stream >> value;
00101 if (_stream.fail()) _value.clear();
00102 else _value = Guid::parse(value);
00103 return _stream;
00104 }
00105
00106 private:
00107
00108 static const char convert_hex[64];
00109
00110 struct _original
00111 {
00112 uint32 data1;
00113 uint16 data2, data3;
00114 uint8 data4[8];
00115 };
00116 struct _fast
00117 {
00118 uint32 _data1, _data2, _data3, _data4;
00119 };
00120 struct _vec
00121 {
00122 unsigned char _data1[16];
00123 };
00124
00125 union
00126 {
00127 _original original;
00128 _fast fast;
00129 _vec vec;
00130 };
00131
00132 };
00133
00134 }
00135
00136 #endif // __MYGUI_GUID_H__