C++ Actor Framework 1.0.0
Loading...
Searching...
No Matches
caf::uuid Class Reference

A universally unique identifier according to RFC 4122. More...

#include <uuid.hpp>

Inheritance diagram for caf::uuid:
caf::detail::comparable< uuid >

Public Types

enum  variant_field {
  reserved ,
  rfc4122 ,
  microsoft
}
 Denotes the variant (type) that determines the layout of the UUID. More...
 
enum  version_field {
  time_based = 1 ,
  dce_compatible = 2 ,
  md5_based = 3 ,
  randomized = 4 ,
  sha1_based = 5
}
 Denotes the version, i.e., which algorithm was used to create this UUID. More...
 
using array_type = std::array<std::byte, 16>
 

Public Member Functions

 uuid () noexcept
 Creates the nil UUID with all 128 bits set to zero.
 
 uuid (const uuid &) noexcept=default
 
uuidoperator= (const uuid &) noexcept=default
 
 uuid (const array_type &bytes) noexcept
 
const array_type & bytes () const noexcept
 
array_type & bytes () noexcept
 
 operator bool () const noexcept
 Returns true if this UUID is not nil, false otherwise.
 
bool operator! () const noexcept
 Returns true if this UUID is nil, false otherwise.
 
variant_field variant () const noexcept
 Returns the variant (type) that determines the layout of the UUID.
 
version_field version () const noexcept
 Returns the version (sub type) that identifies the algorithm used to generate this UUID.
 
uint64_t timestamp () const noexcept
 The 60-bit timestamp of a time-based UUID.
 
uint16_t clock_sequence () const noexcept
 The 14-bit unsigned integer helps to avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.
 
uint64_t node () const noexcept
 48-bit value, representing a network address (time_based UUIDs), a hash (md5_based and sha1_based UUIDs), or a random bit sequence (randomized UUIDs).
 
size_t hash () const noexcept
 Returns a platform-specific hash value for this UUID.
 
int compare (const uuid &other) const noexcept
 Lexicographically compares this and other.
 

Static Public Member Functions

static uuid random () noexcept
 Creates a random UUID.
 
static uuid random (unsigned seed) noexcept
 Creates a random UUID with a predefined seed.
 
static uuid nil () noexcept
 Convenience function for creating an UUID with all 128 bits set to zero.
 
static bool can_parse (std::string_view str) noexcept
 Returns whether parse would produce a valid UUID.
 

Related Symbols

(Note that these are not member symbols.)

CAF_CORE_EXPORT error parse (std::string_view str, uuid &dest)
 
CAF_CORE_EXPORT std::string to_string (const uuid &x)
 
CAF_CORE_EXPORT expected< uuidmake_uuid (std::string_view str)
 
template<class Inspector >
bool inspect (Inspector &f, uuid &x)
 

Detailed Description

A universally unique identifier according to RFC 4122.

While this implementation can read all UUID versions, it can only create random-generated ones.

Member Enumeration Documentation

◆ variant_field

Denotes the variant (type) that determines the layout of the UUID.

The interpretation of all other bits in a UUID depend on this field.

◆ version_field

Denotes the version, i.e., which algorithm was used to create this UUID.

Enumerator
time_based 

Time-based algorithm.

dce_compatible 

DCE security version with embedded POSIX UIDs.

md5_based 

Name-based algorithm using MD5 hashing.

randomized 

Random or pseudo-random algorithm.

sha1_based 

Name-based algorithm using SHA-1 hashing.

Member Function Documentation

◆ clock_sequence()

uint16_t caf::uuid::clock_sequence ( ) const
noexcept

The 14-bit unsigned integer helps to avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.

Precondition
version() == time_based

◆ compare()

int caf::uuid::compare ( const uuid & other) const
noexcept

Lexicographically compares this and other.

Returns
a negative value if *this < other, zero if *this == other and a positive number if *this > other.

◆ operator bool()

caf::uuid::operator bool ( ) const
noexcept

Returns true if this UUID is not nil, false otherwise.

A UUID is nil if all bits are 0.

◆ timestamp()

uint64_t caf::uuid::timestamp ( ) const
noexcept

The 60-bit timestamp of a time-based UUID.

Usually represents a count of 100- nanosecond intervals since 00:00:00.00, 15 October 1582 in UTC.

Precondition
version() == time_based

◆ variant()

uuid::variant_field caf::uuid::variant ( ) const
noexcept

Returns the variant (type) that determines the layout of the UUID.

Precondition
not nil()

◆ version()

uuid::version_field caf::uuid::version ( ) const
noexcept

Returns the version (sub type) that identifies the algorithm used to generate this UUID.

The algorithms defined in RFC 4122 are:

  1. Time-based
  2. DCE security with embedded POSIX UIDs
  3. Name-based, using MD5 hashing
  4. Random or pseudo-random
  5. Name-based, using SHA-1 hashing
    Precondition
    not nil()

The documentation for this class was generated from the following files: