xref: /haiku/headers/private/support/Uuid.h (revision 9f81ca838ce7b92b5689e57d3f86765db4705a7b)
1*10551127SIngo Weinhold /*
2*10551127SIngo Weinhold  * Copyright 2013, Haiku, Inc.
3*10551127SIngo Weinhold  * Distributed under the terms of the MIT License.
4*10551127SIngo Weinhold  */
5*10551127SIngo Weinhold #ifndef _UUID_H_
6*10551127SIngo Weinhold #define _UUID_H_
7*10551127SIngo Weinhold 
8*10551127SIngo Weinhold 
9*10551127SIngo Weinhold #include <String.h>
10*10551127SIngo Weinhold 
11*10551127SIngo Weinhold 
12*10551127SIngo Weinhold namespace BPrivate {
13*10551127SIngo Weinhold 
14*10551127SIngo Weinhold 
15*10551127SIngo Weinhold class BUuid {
16*10551127SIngo Weinhold public:
17*10551127SIngo Weinhold 								BUuid();
18*10551127SIngo Weinhold 								BUuid(const BUuid& other);
19*10551127SIngo Weinhold 								~BUuid();
20*10551127SIngo Weinhold 
21*10551127SIngo Weinhold 			bool				IsNil() const;
22*10551127SIngo Weinhold 
23*10551127SIngo Weinhold 			BUuid&				SetToRandom();
24*10551127SIngo Weinhold 
25*10551127SIngo Weinhold 			BString				ToString() const;
26*10551127SIngo Weinhold 
27*10551127SIngo Weinhold 			int					Compare(const BUuid& other) const;
28*10551127SIngo Weinhold 
29*10551127SIngo Weinhold 	inline	bool				operator==(const BUuid& other) const;
30*10551127SIngo Weinhold 	inline	bool				operator!=(const BUuid& other) const;
31*10551127SIngo Weinhold 
32*10551127SIngo Weinhold 	inline	bool				operator<(const BUuid& other) const;
33*10551127SIngo Weinhold 	inline	bool				operator>(const BUuid& other) const;
34*10551127SIngo Weinhold 	inline	bool				operator<=(const BUuid& other) const;
35*10551127SIngo Weinhold 	inline	bool				operator>=(const BUuid& other) const;
36*10551127SIngo Weinhold 
37*10551127SIngo Weinhold 			BUuid&				operator=(const BUuid& other);
38*10551127SIngo Weinhold 
39*10551127SIngo Weinhold private:
40*10551127SIngo Weinhold 			bool				_SetToDevRandom();
41*10551127SIngo Weinhold 			void				_SetToRandomFallback();
42*10551127SIngo Weinhold 
43*10551127SIngo Weinhold private:
44*10551127SIngo Weinhold 			uint8				fValue[16];
45*10551127SIngo Weinhold };
46*10551127SIngo Weinhold 
47*10551127SIngo Weinhold 
48*10551127SIngo Weinhold inline bool
49*10551127SIngo Weinhold BUuid::operator==(const BUuid& other) const
50*10551127SIngo Weinhold {
51*10551127SIngo Weinhold 	return Compare(other) == 0;
52*10551127SIngo Weinhold }
53*10551127SIngo Weinhold 
54*10551127SIngo Weinhold 
55*10551127SIngo Weinhold inline bool
56*10551127SIngo Weinhold BUuid::operator!=(const BUuid& other) const
57*10551127SIngo Weinhold {
58*10551127SIngo Weinhold 	return Compare(other) != 0;
59*10551127SIngo Weinhold }
60*10551127SIngo Weinhold 
61*10551127SIngo Weinhold 
62*10551127SIngo Weinhold inline bool
63*10551127SIngo Weinhold BUuid::operator<(const BUuid& other) const
64*10551127SIngo Weinhold {
65*10551127SIngo Weinhold 	return Compare(other) < 0;
66*10551127SIngo Weinhold }
67*10551127SIngo Weinhold 
68*10551127SIngo Weinhold 
69*10551127SIngo Weinhold inline bool
70*10551127SIngo Weinhold BUuid::operator>(const BUuid& other) const
71*10551127SIngo Weinhold {
72*10551127SIngo Weinhold 	return Compare(other) > 0;
73*10551127SIngo Weinhold }
74*10551127SIngo Weinhold 
75*10551127SIngo Weinhold 
76*10551127SIngo Weinhold inline bool
77*10551127SIngo Weinhold BUuid::operator<=(const BUuid& other) const
78*10551127SIngo Weinhold {
79*10551127SIngo Weinhold 	return Compare(other) <= 0;
80*10551127SIngo Weinhold }
81*10551127SIngo Weinhold 
82*10551127SIngo Weinhold 
83*10551127SIngo Weinhold inline bool
84*10551127SIngo Weinhold BUuid::operator>=(const BUuid& other) const
85*10551127SIngo Weinhold {
86*10551127SIngo Weinhold 	return Compare(other) >= 0;
87*10551127SIngo Weinhold }
88*10551127SIngo Weinhold 
89*10551127SIngo Weinhold 
90*10551127SIngo Weinhold }	// namespace BPrivate
91*10551127SIngo Weinhold 
92*10551127SIngo Weinhold 
93*10551127SIngo Weinhold using BPrivate::BUuid;
94*10551127SIngo Weinhold 
95*10551127SIngo Weinhold 
96*10551127SIngo Weinhold #endif	// _UUID_H_
97