xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
Static Public Attributes | Public Member Functions | Static Public Member Functions | List of all members
xtd::guid Struct Referencefinal

#include <guid.h>

Definition

Represents a globally unique identifier (GUID). A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.

Namespace
xtd
Library
xtd.core
Examples
The following code example demonstrate the use of xtd::guid struct.
#include <xtd/xtd>
#include <iostream>
using namespace std;
using namespace xtd;
int main() {
for (size_t index = 0; index < 10; index++)
cout << ustring::format("{:X}", guid::new_guid()) << endl;
}
// This code can produces the following output:
//
// {0x8b29b084,0x4be2,0x4a1d,{0x93,0x44,0x59,0xea,0x59,0x9b,0x5b,0xaa}}
// {0x27e83739,0x1d25,0x47b0,{0xbc,0x22,0xb7,0x0b,0x96,0x3d,0xf4,0x1b}}
// {0x7516c2d6,0x1c88,0x46d2,{0x9c,0x17,0xd4,0x18,0xb5,0x7d,0x23,0xb4}}
// {0xec556311,0x969b,0x4095,{0x9e,0xce,0x40,0x27,0x73,0x3d,0x55,0xc5}}
// {0x35674f52,0x154e,0x4dce,{0xb1,0xaa,0x58,0x4d,0x79,0x44,0xe0,0xb6}}
// {0xc9a6f085,0x8ea1,0x4825,{0xa8,0x74,0x03,0xdf,0x26,0xba,0xed,0x92}}
// {0xed2922f4,0x664b,0x4c85,{0xb6,0x0d,0x01,0xcd,0x3c,0x20,0xcf,0x1d}}
// {0xbaed4d04,0x772f,0x47a7,{0xac,0x87,0xb3,0xd1,0x3c,0x0f,0x8c,0xdc}}
// {0x0cba6b46,0xce6d,0x41c7,{0x99,0x17,0x0f,0x41,0x5a,0x50,0x0a,0xfb}}
// {0x1e8e6ac6,0x163c,0x43d4,{0x9d,0x36,0x1b,0x3e,0x04,0x13,0x73,0x0c}}
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
static guid new_guid() noexcept
Initializes a new instance of the xtd::guid structure.

Inherits xtd::object, xtd::icomparable< guid >, and xtd::iequatable< guid >.

Static Public Attributes

static const guid empty
 Get A read-only instance of the xtd::guid structure whose value is all zeros.
 

Public Member Functions

 guid ()=default
 Initializes a new instance of the xtd::guid structure.
 
 guid (const std::initializer_list< byte_t > &data)
 Initializes a new instance of the xtd::guid structure by using the specified array of bytes.
 
 guid (const std::vector< byte_t > &data)
 Initializes a new instance of the xtd::guid structure by using the specified array of bytes.
 
 guid (const ustring &guid)
 Initializes a new instance of the xtd::guid structure by using the value represented by the specified string.
 
 guid (int32_t a, int16_t b, int16_t c, byte_t d, byte_t e, byte_t f, byte_t g, byte_t h, byte_t i, byte_t j, byte_t k) noexcept
 Initializes a new instance of the xtd::guid structure by using the specified integers and bytes.
 
 guid (int32_t a, int32_t b, int32_t c, const std::vector< byte_t > &d)
 Initializes a new instance of the xtd::guid structure by using the specified integers and byte array.
 
 guid (uint32_t a, uint16_t b, uint16_t c, byte_t d, byte_t e, byte_t f, byte_t g, byte_t h, byte_t i, byte_t j, byte_t k) noexcept
 Initializes a new instance of the xtd::guid structure by using the specified uint32_integers and bytes.
 
int32_t compare_to (const guid &value) const noexcept override
 Compares the current instance with another object of the same type.
 
int32_t compare_to (const object &obj) const noexcept override
 Compares the current instance with another object of the same type.
 
bool equals (const guid &g) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
bool equals (const object &g) const noexcept override
 Determines whether the specified object is equal to the current object.
 
const std::vector< byte_t > & to_byte_array () const noexcept
 Returns a 16-element byte array that contains the value of this instance.
 
xtd::ustring to_string () const noexcept override
 Returns a string representation of the value of this instance in registry format.
 
ustring to_string (ustring format) const
 Returns a string representation of the value of this xtd::guid instance, according to the provided format specifier.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance.
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object.
 
virtual int32_t compare_to (const guid &obj) const noexcept=0
 Compares the current instance with another object of the same type.
 
virtual int32_t compare_to (const object &obj) const noexcept
 Compares the current instance with another object of the same type.
 
virtual bool equals (const guid &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
virtual bool equals (const object &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 

Static Public Member Functions

static guid new_guid () noexcept
 Initializes a new instance of the xtd::guid structure.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ guid() [1/7]

xtd::guid::guid ( )
default

Initializes a new instance of the xtd::guid structure.

◆ guid() [2/7]

xtd::guid::guid ( const std::vector< byte_t > &  data)
explicit

Initializes a new instance of the xtd::guid structure by using the specified array of bytes.

Parameters
bytesA 16-element byte array containing values with which to initialize the GUID.
Exceptions
xtd::argument_exceptionbytes is not 16 bytes long.

◆ guid() [3/7]

xtd::guid::guid ( const std::initializer_list< byte_t > &  data)
explicit

Initializes a new instance of the xtd::guid structure by using the specified array of bytes.

Parameters
bytesA 16-element byte array containing values with which to initialize the GUID.
Exceptions
xtd::argument_exceptionbytes is not 16 bytes long.

◆ guid() [4/7]

xtd::guid::guid ( int32_t  a,
int32_t  b,
int32_t  c,
const std::vector< byte_t > &  d 
)
explicit

Initializes a new instance of the xtd::guid structure by using the specified integers and byte array.

Parameters
aThe first 4 bytes of the GUID.
bThe next 2 bytes of the GUID.
cThe next 2 bytes of the GUID.
dThe remaining 8 bytes of the GUID.
Exceptions
xtd::argument_exceptionbytes is not 8 bytes long.

◆ guid() [5/7]

xtd::guid::guid ( int32_t  a,
int16_t  b,
int16_t  c,
byte_t  d,
byte_t  e,
byte_t  f,
byte_t  g,
byte_t  h,
byte_t  i,
byte_t  j,
byte_t  k 
)
noexcept

Initializes a new instance of the xtd::guid structure by using the specified integers and bytes.

Parameters
aThe first 4 bytes of the GUID.
bThe next 2 bytes of the GUID.
cThe next 2 bytes of the GUID.
dThe next byte of the GUID.
eThe next byte of the GUID.
fThe next byte of the GUID.
gThe next byte of the GUID.
hThe next byte of the GUID.
iThe next byte of the GUID.
jThe next byte of the GUID.
kThe next byte of the GUID.

◆ guid() [6/7]

xtd::guid::guid ( uint32_t  a,
uint16_t  b,
uint16_t  c,
byte_t  d,
byte_t  e,
byte_t  f,
byte_t  g,
byte_t  h,
byte_t  i,
byte_t  j,
byte_t  k 
)
noexcept

Initializes a new instance of the xtd::guid structure by using the specified uint32_integers and bytes.

Parameters
aThe first 4 bytes of the GUID.
bThe next 2 bytes of the GUID.
cThe next 2 bytes of the GUID.
dThe next byte of the GUID.
eThe next byte of the GUID.
fThe next byte of the GUID.
gThe next byte of the GUID.
hThe next byte of the GUID.
iThe next byte of the GUID.
jThe next byte of the GUID.
kThe next byte of the GUID.

◆ guid() [7/7]

xtd::guid::guid ( const ustring guid)

Initializes a new instance of the xtd::guid structure by using the value represented by the specified string.

Parameters
guidA string that contains a GUID in one of the following formats ("d" represents a hexadecimal digit whose case is ignored): 32 contiguous digits: dddddddddddddddddddddddddddddddd -or- Groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses: dddddddd-dddd-dddd-dddd-dddddddddddd -or- {dddddddd-dddd-dddd-dddd-dddddddddddd} -or- (dddddddd-dddd-dddd-dddd-dddddddddddd) -or- Groups of 8, 4, and 4 digits, and a subset of eight groups of 2 digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces: {0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} All braces, commas, and "0x" prefixes are required. All embedded spaces are ignored. All leading zeros in a group are ignored. The digits shown in a group are the maximum number of meaningful digits that can appear in that group. You can specify from 1 to the number of digits shown for a group. The specified digits are assumed to be the low-order digits of the group.
Exceptions
xtd::format_exceptionThe format of gui is invalid.
Remarks
The alphabetic hexadecimal digits in the g parameter can be uppercase or lowercase. For example, the following strings represent the same GUID:
"ca761232ed4211cebacd00aa0057b223"
"CA761232-ED42-11CE-BACD-00AA0057B223"
"{CA761232-ED42-11CE-BACD-00AA0057B223}"
"(CA761232-ED42-11CE-BACD-00AA0057B223)"
"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}"

Member Function Documentation

◆ compare_to() [1/2]

int32_t xtd::guid::compare_to ( const guid value) const
overridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Implements xtd::icomparable< guid >.

◆ compare_to() [2/2]

int32_t xtd::guid::compare_to ( const object obj) const
overridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Reimplemented from xtd::icomparable< guid >.

◆ equals() [1/2]

bool xtd::guid::equals ( const guid ) const
overridevirtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implements xtd::iequatable< guid >.

◆ equals() [2/2]

bool xtd::guid::equals ( const object obj) const
overridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.

Reimplemented from xtd::object.

◆ new_guid()

static guid xtd::guid::new_guid ( )
staticnoexcept

Initializes a new instance of the xtd::guid structure.

Returns
A new GUID object.
Remarks
This is a convenient static method that you can call to get a new guid.
The chance that the value of the new guid will be all zeros or equal to any other guid is very low. You can determine whether a GUID consists of all zeros by comparing it to guid::empty().

◆ to_byte_array()

const std::vector< byte_t > & xtd::guid::to_byte_array ( ) const
noexcept

Returns a 16-element byte array that contains the value of this instance.

Returns
A 16-element byte array.

◆ to_string() [1/2]

xtd::ustring xtd::guid::to_string ( ) const
overridevirtualnoexcept

Returns a string representation of the value of this instance in registry format.

Returns
The value of this xtd::guid, formatted by using the "D" format specifier as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal digits from a through f to uppercase, call the ustring::to_string method on the returned string.
Remarks
This method provides a default GUID format that is sufficient for typical use; however, other versions of this method that take a format parameter provide a few common format variations.

Reimplemented from xtd::object.

◆ to_string() [2/2]

ustring xtd::guid::to_string ( ustring  format) const

Returns a string representation of the value of this xtd::guid instance, according to the provided format specifier.

Parameters
formatA single format specifier that indicates how to format the value of this xtd::guid. The format parameter can be "N", "D", "B", "P", or "X". If format is null or an empty string (""), "D" is used.
Returns
The value of this xtd::guid, represented as a series of lowercase hexadecimal digits in the specified format.
Exceptions
xtd::format_exceptionThe value of format is not null, an empty string (""), "N", "D", "B", "P", or "X".
Remarks
The following table shows the accepted format specifiers for the format parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.
Specifier Format of return value
N 32 digits:
00000000000000000000000000000000
D 32 digits separated by hyphens:
00000000-0000-0000-0000-000000000000
B 32 digits separated by hyphens, enclosed in braces:
{00000000-0000-0000-0000-000000000000}
P 32 digits separated by hyphens, enclosed in parentheses:
(00000000-0000-0000-0000-000000000000)
X Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:
{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}

Member Data Documentation

◆ empty

const guid xtd::guid::empty
static

Get A read-only instance of the xtd::guid structure whose value is all zeros.

Returns
xtd::guid A read-only instance of the xtd::guid structure whose value is all zeros.
Remarks
You can compare a GUID with the value of the xtd::guid.Empty field to determine whether a GUID is non-zero. The following example uses the Equality operator to compare two GUID values with xtd::guid.Empty to determine whether they consist exclusively of zeros.

The documentation for this struct was generated from the following file: