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::iformatable xtd::interface xtd::comparison_operators< type_t, comparable_t > xtd::interface xtd::equality_operators< type_t, equatable_t > 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 produce 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.hpp: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 string &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::string to_string () const noexcept override
 Returns a string representation of the value of this instance in registry format.
 
string to_string (const string &format) const
 Returns a string representation of the value of this xtd::guid instance, according to the provided format specifier.
 
string to_string (const string &format, const std::locale &loc) const override
 Returns a string representation of the value of this xtd::guid instance, according to the provided format specifier, and locale.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

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.
 
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 >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::icomparable< guid >
- Public Member Functions inherited from xtd::iequatable< guid >
- Public Member Functions inherited from xtd::iformatable
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &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 string 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() [1/3]

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

◆ 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/3]

xtd::string 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 string::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/3]

string xtd::guid::to_string ( const string 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}

◆ to_string() [3/3]

string xtd::guid::to_string ( const string format,
const std::locale &  loc 
) const
overridevirtual

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

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.
locAn std::locale object that contains locale information (see std::locale).
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}

Implements xtd::iformatable.

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

◆ equals() [2/3]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true

Reimplemented from xtd::object.

◆ equals() [3/3]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

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: