14 #if (XTD_COMPILER_MSVC & XTD_COMPILER)
15 #pragma comment(lib, "rpcrt4")
19 #include <uuid/uuid.h>
23 #if ((XTD_OS_MSYS|XTD_OS_LINUX|XTD_OS_CYGWIN) & XTD_OS)
31 uuid_copy(_uuid, src._uuid);
34 uuid_copy(_uuid, src);
37 uuid_copy(_uuid, src._uuid);
41 uuid_copy(_uuid, src);
44 bool operator<(
const unique_id& rhs)
const{
45 return -1 == uuid_compare(_uuid, rhs._uuid);
47 bool operator<(
const uuid_t& rhs)
const{
48 return -1 == uuid_compare(_uuid, rhs);
51 static uuid_t null_id = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
56 template <
typename>
friend class _::xstring_format;
68 oFile.open(
"/proc/sys/kernel/random/uuid", std::ios::binary);
69 if (oFile.bad())
throw std::runtime_error(
"Failure generating uuid");
71 std::getline(oFile, sTemp);
73 sscanf(sTemp.c_str(),
"%08hX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
74 (uint32_t*)&_uuid[0], (uint16_t*)&_uuid[4], (uint16_t*)&_uuid[6],
75 &_uuid[8], &_uuid[9], &_uuid[10], &_uuid[11], &_uuid[12], &_uuid[13], &_uuid[14], &_uuid[15]);
78 unique_id(
const uuid_t& oID) {
79 memcpy(_uuid, &oID,
sizeof(uuid_t));
81 unique_id(
const unique_id& src){
82 memcpy(_uuid, src._uuid,
sizeof(uuid_t));
84 unique_id& operator=(
const unique_id& src){
85 memcpy(_uuid, src._uuid,
sizeof(uuid_t));
88 bool operator<(
const unique_id& rhs)
const{
89 return -1 == memcmp(_uuid, rhs._uuid,
sizeof(uuid_t));
91 static const unique_id& nullid(){
92 static uuid_t null_id = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
93 static unique_id oRet(null_id);
100 template <>
class xstring_format<char, const
unique_id&>{
102 inline static string format(
const unique_id& value){
104 sprintf(&oRet[0],
"%08hX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
105 *(uint32_t*)&value._uuid[0], *(uint16_t*)&value._uuid[4], *(uint16_t*)&value._uuid[6],
106 value._uuid[8], value._uuid[9], value._uuid[10], value._uuid[11],
107 value._uuid[12], value._uuid[13], value._uuid[14], value._uuid[15]);
113 #elif ((XTD_OS_WINDOWS & XTD_OS) || (XTD_OS_MINGW & XTD_OS))
116 template <
typename,
typename>
friend class _::xstring_format;
119 xtd::exception::throw_if(UuidCreate(
this), [](RPC_STATUS x){
return (RPC_S_OK != x && RPC_S_UUID_LOCAL_ONLY != x && RPC_S_UUID_NO_ADDRESS != x); });
121 unique_id(
const unique_id& src){
122 std::memcpy(
this, &src,
sizeof(unique_id));
124 unique_id(
const uuid_t& src){
125 std::memcpy(
this, &src,
sizeof(uuid_t));
127 unique_id& operator=(
const unique_id& src){
129 std::memcpy(
this, &src,
sizeof(unique_id));
133 unique_id& operator=(
const uuid_t& src){
135 std::memcpy(
this, &src,
sizeof(uuid_t));
139 bool operator<(
const uuid_t& rhs)
const{
140 return ((Data1 < rhs.Data1) ||
141 (Data2 < rhs.Data2) ||
142 (Data3 < rhs.Data3) ||
143 (Data4[0] < rhs.Data4[0]) ||
144 (Data4[1] < rhs.Data4[1]) ||
145 (Data4[2] < rhs.Data4[2]) ||
146 (Data4[3] < rhs.Data4[3]) ||
147 (Data4[4] < rhs.Data4[4]) ||
148 (Data4[5] < rhs.Data4[5]) ||
149 (Data4[6] < rhs.Data4[6]) ||
150 (Data4[7] < rhs.Data4[7]));
152 bool operator<(
const unique_id& rhs)
const{
153 return *this < static_cast<const uuid_t&>(rhs);
155 static unique_id nullid(){
156 uuid_t oRet = { 0, 0, 0,{ 0, 0, 0, 0, 0, 0, 0, 0 } };
162 template <>
class xstring_format<char, const unique_id&>{
164 inline static string format(
const unique_id& value){
166 sprintf(&oRet[0],
"%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
167 value.Data1, value.Data2, value.Data3,
168 value.Data4[0], value.Data4[1], value.Data4[2], value.Data4[3],
169 value.Data4[4], value.Data4[5], value.Data4[6], value.Data4[7]);
specializations of std::basic_string for advanced and common string handling
host, target and build configurations and settings Various components are purpose built for specific ...
#define throw_if(_test, _expression)
Simplifies use of exception::_throw_if.
generic and special purpose exceptions