1 /* === S Y N F I 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-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_GUID_H
26 #define __SYNFIG_GUID_H
28 /* === H E A D E R S ======================================================= */
34 /* === M A C R O S ========================================================= */
36 /* === T Y P E D E F S ===================================================== */
38 /* === C L A S S E S & S T R U C T S ======================================= */
61 GUID(const GUID& x):data(x.data)
63 GUID(const int i){assert(!i); data.u_64.a=0;data.u_64.b=0;}
65 GUID(const String& str);
67 static GUID zero() { return GUID(0); }
68 static GUID hasher(const String& str);
69 static GUID hasher(int i);
71 operator bool()const { return data.u_32.a||data.u_32.b||data.u_32.c||data.u_32.d; }
73 uint64_t get_hi()const { return data.u_64.a; }
74 uint64_t get_lo()const { return data.u_64.b; }
76 uint64_t get_hi_hi()const { return data.u_32.a; }
77 uint64_t get_hi_lo()const { return data.u_32.b; }
78 uint64_t get_lo_hi()const { return data.u_32.c; }
79 uint64_t get_lo_lo()const { return data.u_32.d; }
82 String get_string()const;
84 bool operator==(const GUID& rhs)const
85 { return data.u_64.a==rhs.data.u_64.a && data.u_64.b==rhs.data.u_64.b; }
86 bool operator!=(const GUID& rhs)const
87 { return data.u_64.a!=rhs.data.u_64.a || data.u_64.b!=rhs.data.u_64.b; }
88 bool operator<(const GUID& rhs)const
89 { 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); }
90 bool operator>(const GUID& rhs)const
91 { 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); }
92 bool operator<=(const GUID& rhs)const
93 { return operator<(rhs) || operator==(rhs); }
94 bool operator>=(const GUID& rhs)const
95 { return operator>(rhs) || operator==(rhs); }
97 //! Operator '^' (xor)
98 /*! If A ^ B == C, then C ^ B == A and B ^ A == C.
99 ** Also keep in mind that A ^ A == 0 and A ^ B ^ B = A. */
100 GUID& operator^=(const GUID& rhs)
102 data.u_32.a^=rhs.data.u_32.a;
103 data.u_32.b^=rhs.data.u_32.b;
104 data.u_32.c^=rhs.data.u_32.c;
105 data.u_32.d^=rhs.data.u_32.d;
108 GUID operator^(const GUID& rhs)const { return GUID(*this)^=rhs; }
110 //! Operator '%' (alt-xor)
111 /*! A % B != B % A. */
112 GUID& operator%=(const GUID& rhs)
114 data.u_32.a^=rhs.data.u_32.b;
115 data.u_32.b^=rhs.data.u_32.c;
116 data.u_32.c^=rhs.data.u_32.d;
117 data.u_32.d^=rhs.data.u_32.a;
120 GUID operator%(const GUID& rhs)const { return GUID(*this)%=rhs; }
127 size_t operator()(const GUID& guid)const
139 /* === E N D =============================================================== */