UuidInterface Class Reference

#include <uuid.h>

Detailed Description

Creates an uuid object. The object will be constructed with no valid uuid. After calling CreateId() a new id is generated.

Examples how to create ids:

Uuid a; // creates an empty id.
Uuid b(MAXON_SOURCE_LOCATION); // creates a new unique id.
Uuid c("00000000-0000-0000-0000-000000000000"_s); // creates a new id with the given identifier.
a.CreateId(); // creates a new unique id.
a.Set("00000000-0000-0000-0000-000000000000"_s); // sets the given identifier.
String uuid = Uuid::CreateUuidString(); // creates a new id and returns it as a string.
Definition: c4d_string.h:39
Py_UNICODE c
Definition: unicodeobject.h:1200
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67

from: http://www.ietf.org/rfc/rfc4122.txt

One of the main reasons for using UUIDs is that no centralized authority is required to administer them (although one format uses IEEE 802 node identifiers, others do not). As a result, generation on demand can be completely automated, and used for a variety of purposes. The UUID generation algorithm described here supports very high allocation rates of up to 10 million per second per machine if necessary, so that they could even be used as transaction IDs.

UUIDs are of a fixed size (128 bits) which is reasonably small compared to other alternatives. This lends itself well to sorting, ordering, and hashing of all sorts, storing in databases, simple allocation, and ease of programming in general.

Since UUIDs are unique and persistent, they make excellent Uniform Resource Names. The unique ability to generate a new UUID without a registration process allows for UUIDs to be one of the URNs with the lowest minting cost.

@MAXON_ANNOTATION{refclass=false}

Public Member Functions

MAXON_METHOD Bool IsEmpty () const
 
MAXON_FUNCTION Bool IsPopulated () const
 
MAXON_METHOD Result< void > CreateId ()
 
MAXON_METHOD Result< void > Set (const String &uuid)
 
MAXON_METHOD Result< void > Set (const UChar *uuid, Int uuidSize)
 
MAXON_METHOD Result< void > Get (UChar *uuid, Int uuidSize) const
 
MAXON_METHOD String ToString (const FormatStatement *formatStatement=nullptr) const
 
MAXON_METHOD COMPARERESULT Compare (const UuidInterface *uuid) const
 
MAXON_METHOD HashInt GetHashCode () const
 
MAXON_METHOD UniqueHash GetUniqueHashCode () const
 

Static Public Member Functions

static MAXON_METHOD UuidInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const String &uuid)
 
static MAXON_METHOD UuidInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const UChar *uuid, Int uuidSize)
 
static MAXON_METHOD Result< void > DescribeIO (const DataSerializeInterface &stream)
 
static MAXON_METHOD Result< StringCreateUuidString ()
 
static MAXON_METHOD Result< void > CreateUuid (UChar(&uuid)[16])
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (UuidInterface, MAXON_REFERENCE_COPY_ON_WRITE, "net.maxon.interface.uuid")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( UuidInterface  ,
MAXON_REFERENCE_COPY_ON_WRITE  ,
"net.maxon.interface.uuid"   
)
private

◆ Alloc() [1/2]

static MAXON_METHOD UuidInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
const String uuid 
)
static
Parameters
[in]allocLocationSource location.
[in]uuidString with a valid uuid.

◆ Alloc() [2/2]

static MAXON_METHOD UuidInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
const UChar uuid,
Int  uuidSize 
)
static
Parameters
[in]allocLocationSource location.
[in]uuidPointer to memory of a uuid in big endian format.
[in]uuidSizeSize of the memory block that receives the uuid.

◆ IsEmpty()

MAXON_METHOD Bool IsEmpty ( ) const

Returns whether the object is empty or not. A Uuid is empty if it hasn't been constructed yet, or if a copy operation on the object failed, or if it just contains 0-values.

◆ IsPopulated()

MAXON_FUNCTION Bool IsPopulated ( ) const

Returns whether the object is populated or not. Always the opposite of IsEmpty().

◆ CreateId()

MAXON_METHOD Result<void> CreateId ( )

Creates a new uuid.

◆ Set() [1/2]

MAXON_METHOD Result<void> Set ( const String uuid)

Sets a given uuid string. The id must be of the format "00000000-0000-0000-0000-000000000000".

Parameters
[in]uuidString with a valid uuid.
Returns
OK on success. Returns IllegalArgumentError if the id could not be parsed.

◆ Set() [2/2]

MAXON_METHOD Result<void> Set ( const UChar uuid,
Int  uuidSize 
)

Sets a given memory block of a uuid. The id must be 16 bytes long. Please note that native window functions return little endian for the first 3 components which is different to this call.

Parameters
[in]uuidPointer to memory of a uuid in big endian format.
[in]uuidSizeSize of the memory block that keeps the uuid.
Returns
OK on success. Returns IllegalArgumentError if the id could not be parsed.

◆ Get()

MAXON_METHOD Result<void> Get ( UChar uuid,
Int  uuidSize 
) const

Gets a given memory block of a uuid. The id must be 16 bytes long. Please note that native window functions return little endian for the first 3 components which is different to this call.

Parameters
[in]uuidPointer to memory of a uuid in big endian format.
[in]uuidSizeSize of the memory block that receives the uuid.
Returns
OK on success.

◆ ToString()

MAXON_METHOD String ToString ( const FormatStatement formatStatement = nullptr) const

Converts the uuid into a string. The format will be "00000000-0000-0000-0000-000000000000" and the letters will be uppercase.

Parameters
[in]formatStatementFormat statement for string formating.
Returns
String representation of the uuid.

◆ Compare()

MAXON_METHOD COMPARERESULT Compare ( const UuidInterface uuid) const

Compares the uuid against another uuid.

Parameters
[in]uuidThe uuid to compare with.
Returns
See COMPARERESULT.

◆ GetHashCode()

MAXON_METHOD HashInt GetHashCode ( ) const

Returns the hash code of the uuid. The return value is 0 if the object IsEmpty().

◆ GetUniqueHashCode()

MAXON_METHOD UniqueHash GetUniqueHashCode ( ) const

Returns the 128-bit hash value of this @CLASS. The implementation ensures uniform distribution, so for practical purposes you can safely assume that two objects are equal if their hash values are equal.

Returns
Hash value of this @CLASS.

◆ DescribeIO()

static MAXON_METHOD Result<void> DescribeIO ( const DataSerializeInterface stream)
static

Describes all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.

◆ CreateUuidString()

static MAXON_METHOD Result<String> CreateUuidString ( )
static

Creates a new uuid and returns the string of it.

◆ CreateUuid()

static MAXON_METHOD Result<void> CreateUuid ( UChar(&)  uuid[16])
static

Creates a new uuid and writes it to the raw buffer.

Parameters
[out]uuidThe raw 128 bits of the uuid are written to this buffer.