progress on session_insert_builder
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#ifndef MATADOR_UUID_HPP
|
||||
#define MATADOR_UUID_HPP
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace matador::utils {
|
||||
|
||||
class uuid {
|
||||
public:
|
||||
using uuid_array = std::array<uint32_t, 4>;
|
||||
|
||||
// Default constructor initializes to zero
|
||||
uuid() = default;
|
||||
|
||||
// Static UUID v4 generator
|
||||
static uuid generate();
|
||||
|
||||
// Returns UUID as a string
|
||||
[[nodiscard]] std::string str() const;
|
||||
|
||||
// Access to internal data
|
||||
[[nodiscard]] const uuid_array& data() const;
|
||||
|
||||
// Reset UUID to zero
|
||||
void clear() { _data.fill(0); }
|
||||
|
||||
// Comparisons
|
||||
friend bool operator==(const uuid& lhs, const uuid& rhs);
|
||||
friend bool operator!=(const uuid& lhs, const uuid& rhs);
|
||||
friend bool operator<(const uuid& lhs, const uuid& rhs);
|
||||
|
||||
private:
|
||||
uuid_array _data{0, 0, 0, 0};
|
||||
};
|
||||
}
|
||||
|
||||
// Hash specialization to allow use in unordered containers
|
||||
template <>
|
||||
struct std::hash<matador::utils::uuid> {
|
||||
std::size_t operator()(const matador::utils::uuid& u) const noexcept {
|
||||
std::size_t h = 0;
|
||||
for (uint32_t val : u.data()) {
|
||||
h ^= std::hash<uint32_t>{}(val) + 0x9e3779b9 + (h << 6) + (h >> 2);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //MATADOR_UUID_HPP
|
||||
|
||||
Reference in New Issue
Block a user