19#ifndef ORES_UTILITY_UUID_TENANT_ID_HPP
20#define ORES_UTILITY_UUID_TENANT_ID_HPP
27#include <boost/uuid/uuid.hpp>
38inline constexpr char nil_uuid_str[] =
"00000000-0000-0000-0000-000000000000";
47inline constexpr char max_uuid_str[] =
"ffffffff-ffff-ffff-ffff-ffffffffffff";
88 static std::expected<tenant_id, std::string>
89 from_uuid(
const boost::uuids::uuid& uuid);
101 static std::expected<tenant_id, std::string>
120 bool is_nil()
const noexcept;
127 const boost::uuids::uuid&
to_uuid()
const noexcept;
147 explicit tenant_id(boost::uuids::uuid uuid);
149 boost::uuids::uuid uuid_;
160 return os <<
id.to_string();
170inline std::ostream&
operator<<(std::ostream& os,
const std::optional<tenant_id>&
id) {
171 if (
id.has_value()) {
172 return os <<
id->to_string();
174 return os <<
"(none)";
UUID generation and handling utilities.
Definition ores.utility.uuid.hpp:28
constexpr char max_uuid_str[]
String representation of the max UUID (all ones).
Definition tenant_id.hpp:47
std::ostream & operator<<(std::ostream &os, const tenant_id &id)
Stream insertion operator for tenant_id.
Definition tenant_id.hpp:159
constexpr char nil_uuid_str[]
String representation of the nil UUID (all zeros).
Definition tenant_id.hpp:38
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66
static std::expected< tenant_id, std::string > from_uuid(const boost::uuids::uuid &uuid)
Creates a tenant_id from a boost UUID.
Definition tenant_id.cpp:47
bool operator==(const tenant_id &other) const noexcept=default
Equality comparison operator.
const boost::uuids::uuid & to_uuid() const noexcept
Returns the underlying boost UUID.
Definition tenant_id.cpp:77
bool is_system() const noexcept
Checks if this tenant_id represents the system tenant.
Definition tenant_id.cpp:68
std::string to_string() const
Converts the tenant_id to its string representation.
Definition tenant_id.cpp:81
bool is_nil() const noexcept
Checks if the underlying UUID is nil.
Definition tenant_id.cpp:73
static std::expected< tenant_id, std::string > from_string(std::string_view str)
Creates a tenant_id from a string representation.
Definition tenant_id.cpp:57
static tenant_id system()
Creates a tenant_id representing the system tenant.
Definition tenant_id.cpp:41