Chapter 28. Unique identifiers

#include <x/uuid.H>

x::uuid newid;

x::uuid::charbuf newidStr;

newid.to_string(newidStr);

x::uuid is a unique id generator class. Each instance of x::uuid creates a new unique identifier. The class defines a comparison function, instances of x::uuid may be used as key values in associative containers.

x::uuid has a single member: val. This is an opaque array of uint16_t that contains a unique sequence of values, in binary. The to_string member function converts the unique id value to a zero-terminated string containing Ascii characters. x::uuid::charbuf is an array of characters long enough to hold the generated string.

The unique ID value is formed by combining the running thread ID, a counter, the system clock, and the MAC address of the first network interface found, if one is present. The resulting ID values should be globally unique.

std::vector<unsigned char> mac(x::uuid::getmac()->mac);

getmac() returns a reference to a singleton object that contains one member, mac the MAC address used in the unique ID generator. The vector will be empty if a network interface with a suitable MAC address was not available.