Provide a value-semantic type for Globally Unique Identifiers.
This component provides a value-semantic type for Globally Unique Identifiers (GUIDs), bdlb::Guid
, with format as described by RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt
). All equality and comparison methods are defined for these GUIDs. Note that this component does not provide the facilities to generate GUIDs, and thus makes no guarantees of uniqueness or randomness.
Suppose we are building a utility to create globally unique names which may be based on a common base name, such as a code-generator.
First, let us define the core types needed, the first of which is a utility to allocate GUIDs.
struct MyGuidGeneratorUtil {
};
inline
int my_GuidGeneratorUtil::generate(
bdlb::Guid *guid)
{
{ 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x51, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x52, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x53, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x54, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x55, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
{ 0x5c, 0x9d, 0x4e, 0x56, 0x0d, 0xf1, 0x11, 0xe4,
0x91, 0x91, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 },
};
const bsl::size_t NUM_GUIDS = sizeof GUIDS / sizeof *GUIDS;
static bsl::size_t nextGuidIdx = 0;
int rval = -1;
if (nextGuidIdx++ < NUM_GUIDS) {
rval = 0;
}
return rval;
}
Definition bdlb_guid.h:201
@ k_GUID_NUM_BYTES
Definition bdlb_guid.h:205
Next, we create a utility to create unique strings.
Finally, we implement a program to generate unique names for a code auto-generator.