45 lines
991 B
C++
45 lines
991 B
C++
#ifndef MATADOR_UUID_HPP
|
|
#define MATADOR_UUID_HPP
|
|
|
|
#include <array>
|
|
#include <string>
|
|
#include <cstdint>
|
|
|
|
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;
|
|
};
|
|
|
|
#endif //MATADOR_UUID_HPP
|