Horizon
uuid.hpp
1 #pragma once
2 #ifdef WIN32_UUID
3 #include "uuid_win32.hpp"
4 #else
5 #include <uuid/uuid.h>
6 #endif
7 
8 #include <iostream>
9 
10 namespace horizon {
16 class UUID {
17 public:
18  UUID();
19  static UUID random();
20  UUID(const char *str);
21  UUID(const std::string &str);
22  operator std::string() const
23  {
24  char str[40];
25  uuid_unparse(uu, str);
26  return std::string(str);
27  }
31  operator bool() const
32  {
33  return !uuid_is_null(uu);
34  }
35 
36  friend bool operator==(const UUID &self, const UUID &other);
37  friend bool operator!=(const UUID &self, const UUID &other);
38  friend bool operator<(const UUID &self, const UUID &other);
39  friend bool operator>(const UUID &self, const UUID &other);
40 
41 private:
42  uuid_t uu;
43 };
44 } // namespace horizon
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16