ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
tenant_id Class Referencefinal

A strongly-typed wrapper around a UUID representing a tenant identifier. More...

#include <tenant_id.hpp>

Collaboration diagram for tenant_id:
Collaboration graph

Public Member Functions

bool is_system () const noexcept
 Checks if this tenant_id represents the system tenant.
 
bool is_nil () const noexcept
 Checks if the underlying UUID is nil.
 
const boost::uuids::uuid & to_uuid () const noexcept
 Returns the underlying boost UUID.
 
std::string to_string () const
 Converts the tenant_id to its string representation.
 
bool operator== (const tenant_id &other) const noexcept=default
 Equality comparison operator.
 

Static Public Member Functions

static tenant_id system ()
 Creates a tenant_id representing the system tenant.
 
static std::expected< tenant_id, std::string > from_uuid (const boost::uuids::uuid &uuid)
 Creates a tenant_id from a boost UUID.
 
static std::expected< tenant_id, std::string > from_string (std::string_view str)
 Creates a tenant_id from a string representation.
 

Detailed Description

A strongly-typed wrapper around a UUID representing a tenant identifier.

This class provides type safety for tenant identifiers by:

The class is designed to make it impossible to accidentally create an uninitialized tenant ID that would be confused with the system tenant.

Note
Construction is only possible through factory methods. Direct construction is not allowed.
See also
RFC 9562 - UUIDs

Member Function Documentation

◆ system()

tenant_id system ( )
static

Creates a tenant_id representing the system tenant.

The system tenant uses the max UUID (all ones) as defined in RFC 9562. This value cannot be accidentally created through default construction.

Returns
A tenant_id representing the system tenant.
Here is the caller graph for this function:

◆ from_uuid()

std::expected< tenant_id, std::string > from_uuid ( const boost::uuids::uuid &  uuid)
static

Creates a tenant_id from a boost UUID.

This factory method validates the UUID and rejects nil UUIDs to prevent accidental use of uninitialized values.

Parameters
uuidThe UUID to create the tenant_id from.
Returns
A tenant_id if successful, or an error message if the UUID is nil.
Here is the caller graph for this function:

◆ from_string()

std::expected< tenant_id, std::string > from_string ( std::string_view  str)
static

Creates a tenant_id from a string representation.

This factory method parses the string as a UUID and validates it. Nil UUIDs are rejected.

Parameters
strThe string representation of the UUID.
Returns
A tenant_id if successful, or an error message if parsing fails or the UUID is nil.
Here is the caller graph for this function:

◆ is_system()

bool is_system ( ) const
noexcept

Checks if this tenant_id represents the system tenant.

Returns
true if this is the system tenant (max UUID), false otherwise.

◆ is_nil()

bool is_nil ( ) const
noexcept

Checks if the underlying UUID is nil.

This method is useful for detecting legacy or uninitialized tenant IDs during migration. Under normal circumstances, a tenant_id should never be nil since factory methods reject nil UUIDs.

Returns
true if the underlying UUID is nil, false otherwise.

◆ to_uuid()

const boost::uuids::uuid & to_uuid ( ) const
noexcept

Returns the underlying boost UUID.

Returns
A const reference to the underlying UUID.

◆ to_string()

std::string to_string ( ) const

Converts the tenant_id to its string representation.

Returns
The string representation of the underlying UUID.
Here is the caller graph for this function: