KSS Utility
C++ general utilities
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
uuid.hpp
Go to the documentation of this file.
1 //
2 // uuid.hpp
3 // kssutil
4 //
5 // Created by Steven W. Klassen on 2013-08-28.
6 // Copyright (c) 2013 Klassen Software Solutions. All rights reserved.
7 //
8 // Permission is hereby granted to use, modify, and publish this file without restriction
9 // other than to recognize that others are allowed to do the same.
10 //
11 
17 #ifndef kssutil_uuid_hpp
18 #define kssutil_uuid_hpp
19 
20 
21 #include <stdexcept>
22 #include <string>
23 #include <uuid/uuid.h>
24 #include "add_rel_ops.hpp"
25 
26 
27 namespace kss { namespace util {
28 
39  class UUID : public AddRelOps<UUID> {
40  public:
41  UUID();
42  UUID(const UUID& uid);
43  UUID(UUID&&) = default;
44  explicit UUID(uuid_t uid);
45  explicit UUID(const std::string& suid);
46 
50  explicit operator bool() const noexcept {
51  return (uuid_is_null(_uid) == 0);
52  }
53 
58  explicit operator std::string() const noexcept;
59 
63  const uuid_t& value() const noexcept {
64  return _uid;
65  }
66 
71  void copyInto(uuid_t* uid) const;
72 
73  // Setters.
74  UUID& operator=(const UUID& uid) noexcept;
75  UUID& operator=(UUID&& uid) = default;
76  UUID& operator=(uuid_t uid) noexcept;
77 
78  // Comparators. Note that the "missing" comparators are added via add_rel_ops.
79  bool operator==(const UUID& uid) const noexcept { return (uuid_compare(_uid, uid._uid) == 0); }
80  bool operator<(const UUID& uid) const noexcept { return (uuid_compare(_uid, uid._uid) < 0); }
81 
85  void clear() noexcept;
86 
90  static UUID generate() noexcept;
91 
95  static UUID null() noexcept;
96 
97  private:
98  uuid_t _uid;
99  };
100 
101 }}
102 
103 #endif
UUID & operator=(const UUID &uid) noexcept
bool operator==(const UUID &uid) const noexcept
Definition: uuid.hpp:79
static UUID null() noexcept
Auto-generation of relational operators.
const uuid_t & value() const noexcept
Definition: uuid.hpp:63
C++ wrapper around the uuid_t type.
Definition: uuid.hpp:39
void copyInto(uuid_t *uid) const
Add the operators !=, &lt;=, &gt; and &gt;= assuming the existance of == and &lt;.
Definition: add_rel_ops.hpp:31
bool operator<(const UUID &uid) const noexcept
Definition: uuid.hpp:80
void clear() noexcept
static UUID generate() noexcept