13 #ifndef __STOUT_UUID_HPP__ 14 #define __STOUT_UUID_HPP__ 21 #include <boost/uuid/random_generator.hpp> 22 #include <boost/uuid/string_generator.hpp> 23 #include <boost/uuid/uuid.hpp> 24 #include <boost/uuid/uuid_io.hpp> 35 struct UUID : boost::uuids::uuid
40 static thread_local boost::uuids::random_generator* generator =
nullptr;
42 if (generator ==
nullptr) {
43 generator =
new boost::uuids::random_generator();
46 return UUID((*generator)());
51 const std::string
error =
"Not a valid UUID";
53 if (s.size() != UUID::static_size()) {
57 boost::uuids::uuid uuid;
58 memcpy(&uuid, s.data(), s.size());
60 if (uuid.version() == UUID::version_unknown) {
73 boost::uuids::string_generator gen;
74 boost::uuids::uuid uuid = gen(s);
76 }
catch (
const std::runtime_error& e) {
77 return Error(e.what());
83 assert(
sizeof(data) ==
size());
84 return std::string(reinterpret_cast<const char*>(data),
sizeof(data));
89 return to_string(*
this);
93 explicit UUID(
const boost::uuids::uuid& uuid)
94 : boost::uuids::uuid(uuid) {}
102 struct hash<
id::UUID>
110 return boost::uuids::hash_value(uuid);
116 #endif // __STOUT_UUID_HPP__ std::string toBytes() const
Definition: uuid.hpp:81
Definition: errorbase.hpp:36
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
id::UUID argument_type
Definition: uuid.hpp:106
result_type operator()(const argument_type &uuid) const
Definition: uuid.hpp:108
Definition: type_utils.hpp:619
static UUID random()
Definition: uuid.hpp:38
size_t result_type
Definition: uuid.hpp:104
static Try< UUID > fromBytes(const std::string &s)
Definition: uuid.hpp:49
std::string error(const std::string &msg, uint32_t code)
std::string toString() const
Definition: uuid.hpp:87
static Try< UUID > fromString(const std::string &s)
Definition: uuid.hpp:67