CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Friends | List of all members
CppCommon::UUID Class Reference

Universally unique identifier (UUID) More...

#include <uuid.h>

Public Member Functions

constexpr UUID ()
 Default constructor. More...
 
template<size_t N>
constexpr UUID (const char(&uuid)[N])
 Initialize UUID with a given string literal. More...
 
constexpr UUID (const char *uuid, size_t size)
 Initialize UUID with a given string literal. More...
 
 UUID (const std::string &uuid)
 Initialize UUID with a given string. More...
 
 UUID (const std::array< uint8_t, 16 > &data)
 Initialize UUID with a given 16 bytes data buffer. More...
 
 UUID (const UUID &)=default
 
 UUID (UUID &&) noexcept=default
 
 ~UUID ()=default
 
UUIDoperator= (const std::string &uuid)
 
UUIDoperator= (const std::array< uint8_t, 16 > &data)
 
UUIDoperator= (const UUID &)=default
 
UUIDoperator= (UUID &&) noexcept=default
 
 operator bool () const noexcept
 Check if the UUID is nil UUID0 (all bits set to zero) More...
 
std::array< uint8_t, 16 > & data () noexcept
 Get the UUID data buffer. More...
 
const std::array< uint8_t, 16 > & data () const noexcept
 Get the UUID data buffer. More...
 
std::string string () const
 Get string from the current UUID in format "00000000-0000-0000-0000-000000000000". More...
 
void swap (UUID &uuid) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static UUID Nil ()
 Generate nil UUID0 (all bits set to zero) More...
 
static UUID Sequential ()
 Generate sequential UUID1 (time based version) More...
 
static UUID Random ()
 Generate random UUID4 (randomly or pseudo-randomly generated version) More...
 
static UUID Secure ()
 Generate secure UUID4 (secure generated version) More...
 

Friends

bool operator== (const UUID &uuid1, const UUID &uuid2)
 
bool operator!= (const UUID &uuid1, const UUID &uuid2)
 
bool operator< (const UUID &uuid1, const UUID &uuid2)
 
bool operator> (const UUID &uuid1, const UUID &uuid2)
 
bool operator<= (const UUID &uuid1, const UUID &uuid2)
 
bool operator>= (const UUID &uuid1, const UUID &uuid2)
 
std::ostream & operator<< (std::ostream &os, const UUID &uuid)
 Output instance into the given output stream. More...
 
void swap (UUID &uuid1, UUID &uuid2) noexcept
 

Detailed Description

Universally unique identifier (UUID)

A universally unique identifier (UUID) is an identifier standard used in software construction. This implementation generates the following UUID types:

A UUID is simply a 128-bit value: "123e4567-e89b-12d3-a456-426655440000"

Not thread-safe.

https://en.wikipedia.org/wiki/Universally_unique_identifier https://www.ietf.org/rfc/rfc4122.txt

Definition at line 35 of file uuid.h.

Constructor & Destructor Documentation

◆ UUID() [1/7]

constexpr CppCommon::UUID::UUID ( )
inlineconstexpr

Default constructor.

Definition at line 39 of file uuid.h.

◆ UUID() [2/7]

template<size_t N>
constexpr CppCommon::UUID::UUID ( const char(&)  uuid[N])
inlineexplicitconstexpr

Initialize UUID with a given string literal.

Parameters
uuid- UUID string literal

Definition at line 45 of file uuid.h.

◆ UUID() [3/7]

constexpr CppCommon::UUID::UUID ( const char *  uuid,
size_t  size 
)
inlineexplicitconstexpr

Initialize UUID with a given string literal.

Parameters
uuid- UUID string literal
size- UUID string literal size

Definition at line 29 of file uuid.inl.

◆ UUID() [4/7]

CppCommon::UUID::UUID ( const std::string &  uuid)
inlineexplicit

Initialize UUID with a given string.

Parameters
uuid- UUID string

Definition at line 56 of file uuid.h.

◆ UUID() [5/7]

CppCommon::UUID::UUID ( const std::array< uint8_t, 16 > &  data)
inlineexplicit

Initialize UUID with a given 16 bytes data buffer.

Parameters
data- UUID 16 bytes data buffer

Definition at line 61 of file uuid.h.

◆ UUID() [6/7]

CppCommon::UUID::UUID ( const UUID )
default

◆ UUID() [7/7]

CppCommon::UUID::UUID ( UUID &&  )
defaultnoexcept

◆ ~UUID()

CppCommon::UUID::~UUID ( )
default

Member Function Documentation

◆ data() [1/2]

const std::array<uint8_t, 16>& CppCommon::UUID::data ( ) const
inlinenoexcept

Get the UUID data buffer.

Definition at line 93 of file uuid.h.

◆ data() [2/2]

std::array<uint8_t, 16>& CppCommon::UUID::data ( )
inlinenoexcept

Get the UUID data buffer.

Definition at line 91 of file uuid.h.

◆ Nil()

static UUID CppCommon::UUID::Nil ( )
inlinestatic

Generate nil UUID0 (all bits set to zero)

Examples
system_uuid.cpp.

Definition at line 99 of file uuid.h.

◆ operator bool()

CppCommon::UUID::operator bool ( ) const
inlineexplicitnoexcept

Check if the UUID is nil UUID0 (all bits set to zero)

Definition at line 88 of file uuid.h.

◆ operator=() [1/4]

UUID& CppCommon::UUID::operator= ( const std::array< uint8_t, 16 > &  data)
inline

Definition at line 68 of file uuid.h.

◆ operator=() [2/4]

UUID& CppCommon::UUID::operator= ( const std::string &  uuid)
inline

Definition at line 66 of file uuid.h.

◆ operator=() [3/4]

UUID& CppCommon::UUID::operator= ( const UUID )
default

◆ operator=() [4/4]

UUID& CppCommon::UUID::operator= ( UUID &&  )
defaultnoexcept

◆ Random()

UUID CppCommon::UUID::Random ( )
static

Generate random UUID4 (randomly or pseudo-randomly generated version)

Examples
system_uuid.cpp.

Definition at line 96 of file uuid.cpp.

◆ Secure()

UUID CppCommon::UUID::Secure ( )
static

Generate secure UUID4 (secure generated version)

Examples
system_uuid.cpp.

Definition at line 152 of file uuid.cpp.

◆ Sequential()

UUID CppCommon::UUID::Sequential ( )
static

Generate sequential UUID1 (time based version)

Examples
system_uuid.cpp.

Definition at line 40 of file uuid.cpp.

◆ string()

std::string CppCommon::UUID::string ( ) const

Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".

Definition at line 22 of file uuid.cpp.

◆ swap()

void CppCommon::UUID::swap ( UUID uuid)
inlinenoexcept

Swap two instances.

Definition at line 67 of file uuid.inl.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 76 of file uuid.h.

◆ operator<

bool operator< ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 78 of file uuid.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const UUID uuid 
)
friend

Output instance into the given output stream.

Definition at line 108 of file uuid.h.

◆ operator<=

bool operator<= ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 82 of file uuid.h.

◆ operator==

bool operator== ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 74 of file uuid.h.

◆ operator>

bool operator> ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 80 of file uuid.h.

◆ operator>=

bool operator>= ( const UUID uuid1,
const UUID uuid2 
)
friend

Definition at line 84 of file uuid.h.

◆ swap

void swap ( UUID uuid1,
UUID uuid2 
)
friend

Definition at line 73 of file uuid.inl.


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