PGuid Class Reference

Detailed Description

The PGuid class represents a Globally Unique Identifier (GUID); PGuid instances are immutable (thread-safe).

A GUID is a 16-byte (128-bit) number generated by some algorithm that is meant to guarantee that the GUID will be unique in the distributed computing environment where it is used.

Definition at line 28 of file PGuid.h.

#include <PGuid.h>

Constructor & Destructor Documentation

◆ PGuid() [1/6]

PGuid::PGuid ( )

Constructs the null GUID "{00000000-0000-0000-0000-000000000000}".

See also
IsNull()

◆ PGuid() [2/6]

PGuid::PGuid ( const PGuid other)

Constructs a shared copy of other.

◆ PGuid() [3/6]

PGuid::PGuid ( const char *  str)
explicit

Constructs a GUID object from the string text, which must be formatted as five hex fields separated by '-': "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" or xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where 'x' is a hex digit (letters can be lowercase or uppercase).

The curly braces shown here are optional, but it is normal to include them. If the conversion fails, an invalid GUID is created.

Note: trailing characters are ignored.

See also
Invalid()
IsValid()

◆ PGuid() [4/6]

PGuid::PGuid ( const PString str)
explicit

Constructs a GUID object from the string text, which must be formatted as five hex fields separated by '-': "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where 'x' is a hex digit (letters can be lowercase or uppercase).

The curly braces shown here are optional, but it is normal to include them. If the conversion fails, an invalid GUID is created.

Note: trailing characters are ignored.

See also
Invalid()
IsValid()

◆ PGuid() [5/6]

PGuid::PGuid ( const papillon::uint8  buffer[16])

Constructs a GUID from the binary representation of the GUID (a raw buffer of 16-bytes), as specified by RFC 4122.

◆ PGuid() [6/6]

PGuid::PGuid ( papillon::uint64  storeId,
papillon::uint64  objectId 
)

Constructs a GUID from a store id (64-bits) and an object id (64-bits).

◆ ~PGuid()

virtual PGuid::~PGuid ( )
virtual

Destroys this object.

Member Function Documentation

◆ CreateEntityId()

static PGuid PGuid::CreateEntityId ( papillon::uint64  storeId = UndefinedPartId())
static

Returns a new Global Unique Identifier (GUID) attached to the specified store and with an object id part set randomly.

◆ CreateFrom2Ids()

static PGuid PGuid::CreateFrom2Ids ( const PGuid guid1,
const PGuid guid2 
)
static

Creates a GUID from two other GUIDs.

◆ CreateFromMD5()

static PGuid PGuid::CreateFromMD5 ( const PString str)
static

Creates a GUID from an MD5 string.

This is a direct loss-less conversion since the MD5 string is also 128 bits just like the GUID. Returns a null GUID if the string passed in is not a valid 32 character hex string.

◆ CreateUniqueId()

static PGuid PGuid::CreateUniqueId ( )
static

Returns a new Global Unique Identifier (GUID); thread-safe.

This function can be used safely by multiple threads at the same time, i.e. several different threads will get different random ids.

◆ GetObjectId()

papillon::uint64 PGuid::GetObjectId ( ) const

Returns the object id from this guid (the last 8-bytes of this 128-bits id reinterpreted as an uint64).

◆ GetStoreId()

papillon::uint64 PGuid::GetStoreId ( ) const

Returns the store id from this guid (the first 8-bytes of this 128-bits id reinterpreted as an uint64).

◆ Invalid()

static const PGuid& PGuid::Invalid ( )
inlinestatic

Returns the constant holding the invalid GUID (i.e.

{deaddead-dead-dead-dead-deaddeaddead}).

See also
IsValid()
IsInvalid()

Definition at line 59 of file PGuid.h.

◆ IsInvalid()

bool PGuid::IsInvalid ( ) const

Returns true if this is the invalid GUID {deaddead-dead-dead-dead-deaddeaddead}; otherwise returns false.

◆ IsNull()

bool PGuid::IsNull ( ) const

Returns true if this is the null GUID {00000000-0000-0000-0000-000000000000}; otherwise returns false.

◆ IsNullObjectId()

bool PGuid::IsNullObjectId ( ) const

Returns true if the object id is null (0), false otherwise.

◆ IsNullStoreId()

bool PGuid::IsNullStoreId ( ) const

Returns true if the store id is null (0), false otherwise.

◆ IsUndefined()

bool PGuid::IsUndefined ( ) const

Returns true if this is the undefined GUID {ffffffff-ffff-ffff-ffff-ffffffffffff}; otherwise returns false.

◆ IsUndefinedObjectId()

bool PGuid::IsUndefinedObjectId ( ) const

Returns true if the object id is undefined (see UndefinedPartId()), false otherwise.

◆ IsUndefinedStoreId()

bool PGuid::IsUndefinedStoreId ( ) const

Returns true if the store id is undefined (see UndefinedPartId()), false otherwise.

◆ IsValid()

bool PGuid::IsValid ( ) const

Returns true if this is a valid GUID, i.e.

any guid different from {deaddead-dead-dead-dead-deaddeaddead}; otherwise returns false.

◆ Null()

static const PGuid& PGuid::Null ( )
inlinestatic

Returns the constant holding the null GUID (i.e.

{00000000-0000-0000-0000-000000000000}).

See also
IsNull()

Definition at line 44 of file PGuid.h.

◆ operator!=()

bool PGuid::operator!= ( const PGuid other) const

Returns true if this GUID is different from other; otherwise returns false.

◆ operator<()

bool PGuid::operator< ( const PGuid other) const

Compares this GUID with another one (order relation to be able to sort GUID).

◆ operator=()

PGuid& PGuid::operator= ( const PGuid other)

Performs a shared copy of other to this object.

◆ operator==()

bool PGuid::operator== ( const PGuid other) const

Returns true if this GUID is equal to other; otherwise returns false.

◆ ToByteArray()

PByteArray PGuid::ToByteArray ( ) const

Returns a byte-array representation (16 bytes) of this id.

◆ ToStringUnderscores()

PString PGuid::ToStringUnderscores ( ) const

Returns a string representation of this GUID using underscores as separators: "00000000_0000_0000_0000_000000000000".

◆ Undefined()

static const PGuid& PGuid::Undefined ( )
inlinestatic

Returns the constant holding the undefined GUID (i.e.

{ffffffff-ffff-ffff-ffff-ffffffffffff}).

See also
IsUndefined()

Definition at line 51 of file PGuid.h.

◆ UndefinedPartId()

static papillon::uint64 PGuid::UndefinedPartId ( )
inlinestatic

Returns the constant holding the undefined 64-bit id, which can be Store id or Object id.

See also
IsUndefinedStoreId()
IsUndefinedObjectId()

Definition at line 37 of file PGuid.h.

Friends And Related Function Documentation

◆ PGuidImpl

friend class PGuidImpl
friend

Definition at line 233 of file PGuid.h.