1 /* === S I N F G =========================================================== */
3 ** \brief Template Header
5 ** $Id: guid.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_GUID_H
25 #define __SINFG_GUID_H
27 /* === H E A D E R S ======================================================= */
33 /* === M A C R O S ========================================================= */
35 /* === T Y P E D E F S ===================================================== */
37 /* === C L A S S E S & S T R U C T S ======================================= */
60 GUID(const GUID& x):data(x.data)
62 GUID(const int i){assert(!i); data.u_64.a=0;data.u_64.b=0;}
64 GUID(const String& str);
66 static GUID zero() { return GUID(0); }
67 static GUID hasher(const String& str);
68 static GUID hasher(int i);
70 operator bool()const { return data.u_32.a||data.u_32.b||data.u_32.c||data.u_32.d; }
72 uint64_t get_hi()const { return data.u_64.a; }
73 uint64_t get_lo()const { return data.u_64.b; }
75 uint64_t get_hi_hi()const { return data.u_32.a; }
76 uint64_t get_hi_lo()const { return data.u_32.b; }
77 uint64_t get_lo_hi()const { return data.u_32.c; }
78 uint64_t get_lo_lo()const { return data.u_32.d; }
81 String get_string()const;
83 bool operator==(const GUID& rhs)const
84 { return data.u_64.a==rhs.data.u_64.a && data.u_64.b==rhs.data.u_64.b; }
85 bool operator!=(const GUID& rhs)const
86 { return data.u_64.a!=rhs.data.u_64.a || data.u_64.b!=rhs.data.u_64.b; }
87 bool operator<(const GUID& rhs)const
88 { 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); }
89 bool operator>(const GUID& rhs)const
90 { 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); }
91 bool operator<=(const GUID& rhs)const
92 { return operator<(rhs) || operator==(rhs); }
93 bool operator>=(const GUID& rhs)const
94 { return operator>(rhs) || operator==(rhs); }
96 //! Operator '^' (xor)
97 /*! If A ^ B == C, then C ^ B == A and B ^ A == C.
98 ** Also keep in mind that A ^ A == 0 and A ^ B ^ B = A. */
99 GUID& operator^=(const GUID& rhs)
101 data.u_32.a^=rhs.data.u_32.a;
102 data.u_32.b^=rhs.data.u_32.b;
103 data.u_32.c^=rhs.data.u_32.c;
104 data.u_32.d^=rhs.data.u_32.d;
107 GUID operator^(const GUID& rhs)const { return GUID(*this)^=rhs; }
109 //! Operator '%' (alt-xor)
110 /*! A % B != B % A. */
111 GUID& operator%=(const GUID& rhs)
113 data.u_32.a^=rhs.data.u_32.b;
114 data.u_32.b^=rhs.data.u_32.c;
115 data.u_32.c^=rhs.data.u_32.d;
116 data.u_32.d^=rhs.data.u_32.a;
119 GUID operator%(const GUID& rhs)const { return GUID(*this)%=rhs; }
126 size_t operator()(const GUID& guid)const
138 /* === E N D =============================================================== */