xtd 0.2.0
Loading...
Searching...
No Matches
xtd::guid Struct Referencefinal
Inheritance diagram for xtd::guid:
xtd::object xtd::icomparable< guid > xtd::iequatable< guid > xtd::interface xtd::interface

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 demonstrates the use of xtd::guid struct.
#include <xtd/console>
#include <xtd/guid>
using namespace xtd;
auto main()->int {
for (auto counter = 0; counter < 10; ++counter)
}
// 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 void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
static guid new_guid() noexcept
Initializes a new instance of the xtd::guid structure.
Examples
system_exception.cpp.

Public Fields

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

Public Constructors

 guid ()=default
 Initializes a new instance of the xtd::guid structure.
 
 guid (const std::vector< xtd::byte > &data)
 Initializes a new instance of the xtd::guid structure by using the specified array of bytes.
 
 guid (const std::initializer_list< xtd::byte > &data)
 Initializes a new instance of the xtd::guid structure by using the specified array of bytes.
 
 guid (int32 a, int16 b, int16 c, const std::vector< xtd::byte > &d)
 Initializes a new instance of the xtd::guid structure by using the specified integers and byte array.
 
 guid (uint32 a, uint16 b, uint16 c, const std::vector< xtd::byte > &d)
 Initializes a new instance of the xtd::guid structure by using the specified unsigned integers and byte array.
 
 guid (int32 a, int16 b, int16 c, xtd::byte d, xtd::byte e, xtd::byte f, xtd::byte g, xtd::byte h, xtd::byte i, xtd::byte j, xtd::byte k) noexcept
 Initializes a new instance of the xtd::guid structure by using the specified integers and bytes.
 
 guid (uint32 a, uint16 b, uint16 c, xtd::byte d, xtd::byte e, xtd::byte f, xtd::byte g, xtd::byte h, xtd::byte i, xtd::byte j, xtd::byte k) noexcept
 Initializes a new instance of the xtd::guid structure by using the specified unsigned integers and bytes.
 
 guid (const ustring &guid)
 Initializes a new instance of the xtd::guid structure by using the value represented by the specified string.
 

Public Methods

int32 compare_to (const guid &value) 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.
 
const std::vector< xtd::byte > & 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 Static Methods

static guid new_guid () noexcept
 Initializes a new instance of the xtd::guid structure.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
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.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::icomparable< guid >
- Public Member Functions inherited from xtd::iequatable< guid >
- 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/8]

xtd::guid::guid ( )
default

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

◆ guid() [2/8]

xtd::guid::guid ( const std::vector< xtd::byte > &  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/8]

xtd::guid::guid ( const std::initializer_list< xtd::byte > &  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/8]

xtd::guid::guid ( int32  a,
int16  b,
int16  c,
const std::vector< xtd::byte > &  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.

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/8]

xtd::guid::guid ( uint32  a,
uint16  b,
uint16  c,
const std::vector< xtd::byte > &  d 
)
explicit

Initializes a new instance of the xtd::guid structure by using the specified unsigned 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.

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() [6/8]

xtd::guid::guid ( int32  a,
int16  b,
int16  c,
xtd::byte  d,
xtd::byte  e,
xtd::byte  f,
xtd::byte  g,
xtd::byte  h,
xtd::byte  i,
xtd::byte  j,
xtd::byte  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() [7/8]

xtd::guid::guid ( uint32  a,
uint16  b,
uint16  c,
xtd::byte  d,
xtd::byte  e,
xtd::byte  f,
xtd::byte  g,
xtd::byte  h,
xtd::byte  i,
xtd::byte  j,
xtd::byte  k 
)
noexcept

Initializes a new instance of the xtd::guid structure by using the specified unsigned 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() [8/8]

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

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()

int32 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 >.

◆ equals()

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 >.

◆ 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< xtd::byte > & 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

Gets 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: