More grammar work, all idl files are now parsed entirely again.
[fail.git] / src / core / uuid.h
blobaf0a206923831918bddcf658969830127e693e35
1 #ifndef FAIL_UUID_H_
2 #define FAIL_UUID_H_
4 #include <uuid/uuid.h>
6 namespace fail
8 // A more useful uuid type than the one from libuuid.
9 // It uses two uint64 for representation (allowing fast
10 // comparisons and copying), and provide the necessary
11 // operator overloads to use them transparently.
12 struct FLCORE_EXPORT uuid
14 uint64_t hi;
15 uint64_t lo;
17 operator bool() const
19 return hi || lo;
22 bool operator==( const uuid& other ) const
24 return hi == other.hi && lo == other.lo;
27 bool operator!=( const uuid& other ) const
29 return hi != other.hi || lo != other.lo;
32 // define operator < so it can be used as a key in a map or a set
33 bool operator<( const uuid& other ) const
35 if( hi < other.hi )
36 return true;
38 if( hi == other.hi )
39 return lo < other.lo;
41 return false;
44 friend std::ostream& operator<<( std::ostream& out, const uuid& uuid_ )
46 union
48 uuid fail_uuid;
49 uuid_t uuidlib_uuid;
50 } uuid_union;
51 uuid_union.fail_uuid = uuid_;
53 char tmp[128]; // Hrmpf... C APIs.
54 uuid_unparse( uuid_union.uuidlib_uuid, tmp );
55 out << tmp;
57 return out;
60 static inline uuid Generate()
62 union
64 uuid fail_uuid;
65 uuid_t uuidlib_uuid;
66 } result;
68 uuid_generate( result.uuidlib_uuid );
69 return result.fail_uuid;
74 #endif