guid.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_GUID_H
00026 #define __SYNFIG_GUID_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include "string.h"
00031 #include <stdint.h>
00032 #include <cassert>
00033 
00034 /* === M A C R O S ========================================================= */
00035 
00036 /* === T Y P E D E F S ===================================================== */
00037 
00038 /* === C L A S S E S & S T R U C T S ======================================= */
00039 
00040 namespace synfig {
00041 
00042 class GUID
00043 {
00044     union {
00045         struct {
00046             unsigned int a;
00047             unsigned int b;
00048             unsigned int c;
00049             unsigned int d;
00050         } u_32;
00051         struct {
00052             uint64_t a;
00053             uint64_t b;
00054         } u_64;
00055 
00056     } data;
00057 
00058 public:
00059     GUID()
00060         { make_unique(); }
00061     GUID(const GUID& x):data(x.data)
00062         { }
00063     GUID(const int i){assert(!i); data.u_64.a=0;data.u_64.b=0;}
00064 
00065     GUID(const String& str);
00066 
00067     static GUID zero() { return GUID(0); }
00068     static GUID hasher(const String& str);
00069     static GUID hasher(int i);
00070 
00071     operator bool()const { return data.u_32.a||data.u_32.b||data.u_32.c||data.u_32.d; }
00072 
00073     uint64_t get_hi()const { return data.u_64.a; }
00074     uint64_t get_lo()const { return data.u_64.b; }
00075 
00076     uint64_t get_hi_hi()const { return data.u_32.a; }
00077     uint64_t get_hi_lo()const { return data.u_32.b; }
00078     uint64_t get_lo_hi()const { return data.u_32.c; }
00079     uint64_t get_lo_lo()const { return data.u_32.d; }
00080 
00081     void make_unique();
00082     String get_string()const;
00083 
00084     bool operator==(const GUID& rhs)const
00085         { return data.u_64.a==rhs.data.u_64.a && data.u_64.b==rhs.data.u_64.b; }
00086     bool operator!=(const GUID& rhs)const
00087         { return data.u_64.a!=rhs.data.u_64.a || data.u_64.b!=rhs.data.u_64.b; }
00088     bool operator<(const GUID& rhs)const
00089         { return (data.u_64.a==rhs.data.u_64.a)?(data.u_64.b<rhs.data.u_64.b):(data.u_64.a<rhs.data.u_64.a); }
00090     bool operator>(const GUID& rhs)const
00091         { return (data.u_64.a==rhs.data.u_64.a)?(data.u_64.b>rhs.data.u_64.b):(data.u_64.a>rhs.data.u_64.a); }
00092     bool operator<=(const GUID& rhs)const
00093         { return operator<(rhs) || operator==(rhs); }
00094     bool operator>=(const GUID& rhs)const
00095         { return operator>(rhs) || operator==(rhs); }
00096 
00098 
00100     GUID& operator^=(const GUID& rhs)
00101     {
00102         data.u_32.a^=rhs.data.u_32.a;
00103         data.u_32.b^=rhs.data.u_32.b;
00104         data.u_32.c^=rhs.data.u_32.c;
00105         data.u_32.d^=rhs.data.u_32.d;
00106         return *this;
00107     }
00108     GUID operator^(const GUID& rhs)const { return GUID(*this)^=rhs; }
00109 
00111 
00112     GUID& operator%=(const GUID& rhs)
00113     {
00114         data.u_32.a^=rhs.data.u_32.b;
00115         data.u_32.b^=rhs.data.u_32.c;
00116         data.u_32.c^=rhs.data.u_32.d;
00117         data.u_32.d^=rhs.data.u_32.a;
00118         return *this;
00119     }
00120     GUID operator%(const GUID& rhs)const { return GUID(*this)%=rhs; }
00121 
00122 };
00123 
00124 class GUIDHash
00125 {
00126 public:
00127     size_t operator()(const GUID& guid)const
00128     {
00129         return
00130             guid.get_hi_hi()+
00131             guid.get_hi_lo()+
00132             guid.get_lo_hi()+
00133             guid.get_lo_lo();
00134     }
00135 };
00136 
00137 };
00138 
00139 /* === E N D =============================================================== */
00140 
00141 #endif

Generated on Wed Dec 12 03:11:41 2007 for synfig by  doxygen 1.5.4