progress on session_insert_builder
This commit is contained in:
@@ -8,6 +8,7 @@ add_library(matador-core STATIC
|
||||
../../include/matador/object/object_info.hpp
|
||||
../../include/matador/object/object_proxy.hpp
|
||||
../../include/matador/object/object_ptr.hpp
|
||||
../../include/matador/object/primary_key_resolver.hpp
|
||||
../../include/matador/object/schema.hpp
|
||||
../../include/matador/object/schema_node.hpp
|
||||
../../include/matador/object/schema_node_iterator.hpp
|
||||
@@ -39,6 +40,7 @@ add_library(matador-core STATIC
|
||||
../../include/matador/utils/singleton.hpp
|
||||
../../include/matador/utils/string.hpp
|
||||
../../include/matador/utils/types.hpp
|
||||
../../include/matador/utils/uuid.hpp
|
||||
../../include/matador/utils/value.hpp
|
||||
../../include/matador/utils/version.hpp
|
||||
object/attribute_definition_generator.cpp
|
||||
@@ -46,6 +48,7 @@ add_library(matador-core STATIC
|
||||
object/basic_object_info.cpp
|
||||
object/error_code.cpp
|
||||
object/object_definition.cpp
|
||||
object/primary_key_resolver.cpp
|
||||
object/schema.cpp
|
||||
object/schema_node.cpp
|
||||
object/schema_node_iterator.cpp
|
||||
@@ -59,10 +62,9 @@ add_library(matador-core STATIC
|
||||
utils/os.cpp
|
||||
utils/string.cpp
|
||||
utils/types.cpp
|
||||
utils/uuid.cpp
|
||||
utils/value.cpp
|
||||
utils/version.cpp
|
||||
../../include/matador/object/primary_key_resolver.hpp
|
||||
object/primary_key_resolver.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "matador/utils/uuid.hpp"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace matador::utils {
|
||||
|
||||
uuid uuid::generate() {
|
||||
std::random_device rd;
|
||||
std::mt19937_64 gen(rd());
|
||||
std::uniform_int_distribution<uint64_t> dist;
|
||||
|
||||
uint64_t high = dist(gen);
|
||||
uint64_t low = dist(gen);
|
||||
|
||||
// Set version to 4 (UUID v4)
|
||||
high &= 0xFFFFFFFFFFFF0FFFULL;
|
||||
high |= 0x0000000000004000ULL;
|
||||
|
||||
// Set variant to 10xx (RFC 4122)
|
||||
low &= 0x3FFFFFFFFFFFFFFFULL;
|
||||
low |= 0x8000000000000000ULL;
|
||||
|
||||
uuid result;
|
||||
result._data[0] = static_cast<uint32_t>(high >> 32);
|
||||
result._data[1] = static_cast<uint32_t>(high & 0xFFFFFFFF);
|
||||
result._data[2] = static_cast<uint32_t>(low >> 32);
|
||||
result._data[3] = static_cast<uint32_t>(low & 0xFFFFFFFF);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string uuid::str() const {
|
||||
const char* hex = "0123456789abcdef";
|
||||
char out[36]; // UUID string format is 36 characters
|
||||
int pos = 0;
|
||||
|
||||
auto write_hex = [&](uint32_t value, int digits) {
|
||||
for (int i = digits - 1; i >= 0; --i) {
|
||||
out[pos + i] = hex[value & 0xF];
|
||||
value >>= 4;
|
||||
}
|
||||
pos += digits;
|
||||
};
|
||||
|
||||
write_hex(_data[0] >> 16, 8);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[0] & 0xFFFF, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[1] >> 16, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[1] & 0xFFFF, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[2] >> 16, 4);
|
||||
write_hex(_data[2] & 0xFFFF, 4);
|
||||
write_hex(_data[3], 4);
|
||||
|
||||
return {out, 36};
|
||||
}
|
||||
|
||||
const uuid::uuid_array& uuid::data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool operator==( const uuid& lhs, const uuid& rhs ) {
|
||||
return lhs._data == rhs._data;
|
||||
}
|
||||
|
||||
bool operator!=( const uuid& lhs, const uuid& rhs ) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
bool operator<( const uuid& lhs, const uuid& rhs ) {
|
||||
return lhs._data < rhs._data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user