Declare variables as inline

Declare empty_guid and guid_encoder as inline to fix multiple defined
symbol errors when compiling with clang++.
This commit is contained in:
Jason 2022-01-04 07:26:47 -08:00
parent 9357e5280c
commit 5f739d3e26

View File

@ -69,8 +69,7 @@ namespace uuids
template <typename TChar>
constexpr inline bool is_hex(TChar const ch)
{
return
(ch >= static_cast<TChar>('0') && ch <= static_cast<TChar>('9')) ||
return (ch >= static_cast<TChar>('0') && ch <= static_cast<TChar>('9')) ||
(ch >= static_cast<TChar>('a') && ch <= static_cast<TChar>('f')) ||
(ch >= static_cast<TChar>('A') && ch <= static_cast<TChar>('F'));
}
@ -78,7 +77,8 @@ namespace uuids
template <typename TChar>
constexpr std::basic_string_view<TChar> to_string_view(TChar const *str)
{
if (str) return str;
if (str)
return str;
return {};
}
@ -149,16 +149,21 @@ namespace uuids
{
size_t const bitCount = this->m_byteCount * 8;
process_byte(0x80);
if (this->m_blockByteIndex > 56) {
while (m_blockByteIndex != 0) {
if (this->m_blockByteIndex > 56)
{
while (m_blockByteIndex != 0)
{
process_byte(0);
}
while (m_blockByteIndex < 56) {
while (m_blockByteIndex < 56)
{
process_byte(0);
}
}
else {
while (m_blockByteIndex < 56) {
else
{
while (m_blockByteIndex < 56)
{
process_byte(0);
}
}
@ -212,13 +217,15 @@ namespace uuids
void process_block()
{
uint32_t w[80];
for (size_t i = 0; i < 16; i++) {
for (size_t i = 0; i < 16; i++)
{
w[i] = static_cast<uint32_t>(m_block[i * 4 + 0] << 24);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 1] << 16);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 2] << 8);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 3]);
}
for (size_t i = 16; i < 80; i++) {
for (size_t i = 16; i < 80; i++)
{
w[i] = left_rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]), 1);
}
@ -233,19 +240,23 @@ namespace uuids
uint32_t f = 0;
uint32_t k = 0;
if (i < 20) {
if (i < 20)
{
f = (b & c) | (~b & d);
k = 0x5A827999;
}
else if (i < 40) {
else if (i < 40)
{
f = b ^ c ^ d;
k = 0x6ED9EBA1;
}
else if (i < 60) {
else if (i < 60)
{
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
}
else {
else
{
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
@ -272,16 +283,16 @@ namespace uuids
};
template <typename CharT>
constexpr CharT empty_guid[37] = "00000000-0000-0000-0000-000000000000";
inline constexpr CharT empty_guid[37] = "00000000-0000-0000-0000-000000000000";
template <>
constexpr wchar_t empty_guid<wchar_t>[37] = L"00000000-0000-0000-0000-000000000000";
inline constexpr wchar_t empty_guid<wchar_t>[37] = L"00000000-0000-0000-0000-000000000000";
template <typename CharT>
constexpr CharT guid_encoder[17] = "0123456789abcdef";
inline constexpr CharT guid_encoder[17] = "0123456789abcdef";
template <>
constexpr wchar_t guid_encoder<wchar_t>[17] = L"0123456789abcdef";
inline constexpr wchar_t guid_encoder<wchar_t>[17] = L"0123456789abcdef";
}
// --------------------------------------------------------------------------------------------------------------------------
@ -411,7 +422,9 @@ namespace uuids
constexpr bool is_nil() const noexcept
{
for (size_t i = 0; i < data.size(); ++i) if (data[i] != 0) return false;
for (size_t i = 0; i < data.size(); ++i)
if (data[i] != 0)
return false;
return true;
}
@ -443,7 +456,8 @@ namespace uuids
for (size_t i = hasBraces; i < str.size() - hasBraces; ++i)
{
if (str[i] == '-') continue;
if (str[i] == '-')
continue;
if (index >= 16 || !detail::is_hex(str[i]))
{
@ -479,7 +493,8 @@ namespace uuids
std::array<uint8_t, 16> data{{0}};
if (str.empty()) return {};
if (str.empty())
return {};
if (str.front() == '{')
hasBraces = 1;
@ -488,7 +503,8 @@ namespace uuids
for (size_t i = hasBraces; i < str.size() - hasBraces; ++i)
{
if (str[i] == '-') continue;
if (str[i] == '-')
continue;
if (index >= 16 || !detail::is_hex(str[i]))
{
@ -622,8 +638,7 @@ namespace uuids
}
std::array<uint8_t, 16> bytes =
{ {
static_cast<unsigned char>((newId.Data1 >> 24) & 0xFF),
{{static_cast<unsigned char>((newId.Data1 >> 24) & 0xFF),
static_cast<unsigned char>((newId.Data1 >> 16) & 0xFF),
static_cast<unsigned char>((newId.Data1 >> 8) & 0xFF),
static_cast<unsigned char>((newId.Data1) & 0xFF),
@ -641,8 +656,7 @@ namespace uuids
newId.Data4[4],
newId.Data4[5],
newId.Data4[6],
newId.Data4[7]
} };
newId.Data4[7]}};
return uuid{std::begin(bytes), std::end(bytes)};
@ -652,8 +666,7 @@ namespace uuids
uuid_generate(id);
std::array<uint8_t, 16> bytes =
{ {
id[0],
{{id[0],
id[1],
id[2],
id[3],
@ -668,8 +681,7 @@ namespace uuids
id[12],
id[13],
id[14],
id[15]
} };
id[15]}};
return uuid{std::begin(bytes), std::end(bytes)};
@ -679,8 +691,7 @@ namespace uuids
CFRelease(newId);
std::array<uint8_t, 16> arrbytes =
{ {
bytes.byte0,
{{bytes.byte0,
bytes.byte1,
bytes.byte2,
bytes.byte3,
@ -695,8 +706,7 @@ namespace uuids
bytes.byte12,
bytes.byte13,
bytes.byte14,
bytes.byte15
} };
bytes.byte15}};
return uuid{std::begin(arrbytes), std::end(arrbytes)};
#else
return uuid{};
@ -711,10 +721,8 @@ namespace uuids
public:
using engine_type = UniformRandomNumberGenerator;
explicit basic_uuid_random_generator(engine_type& gen) :
generator(&gen, [](auto) {}) {}
explicit basic_uuid_random_generator(engine_type* gen) :
generator(gen, [](auto) {}) {}
explicit basic_uuid_random_generator(engine_type &gen) : generator(&gen, [](auto) {}) {}
explicit basic_uuid_random_generator(engine_type *gen) : generator(gen, [](auto) {}) {}
uuid operator()()
{
@ -745,7 +753,8 @@ namespace uuids
public:
explicit uuid_name_generator(uuid const &namespace_uuid) noexcept
: nsuuid(namespace_uuid)
{}
{
}
template <typename StringType>
uuid operator()(StringType const &name)
@ -820,11 +829,13 @@ namespace uuids
#ifdef _WIN32
DWORD len = 0;
auto ret = GetAdaptersInfo(nullptr, &len);
if (ret != ERROR_BUFFER_OVERFLOW) return false;
if (ret != ERROR_BUFFER_OVERFLOW)
return false;
std::vector<unsigned char> buf(len);
auto pips = reinterpret_cast<PIP_ADAPTER_INFO>(&buf.front());
ret = GetAdaptersInfo(pips, &len);
if (ret != ERROR_SUCCESS) return false;
if (ret != ERROR_SUCCESS)
return false;
mac_address addr;
std::copy(pips->Address, pips->Address + 6, std::begin(addr));
device_address = addr;