Skip to content
Snippets Groups Projects
Commit 60702179 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

[librender] use custom uuid generator

parent 370c1bcc
Branches
Tags
No related merge requests found
......@@ -183,7 +183,7 @@ set(resources
# std::uuid dependency
# Note, follow the progress of integration of uuid generator in the C++ std lib. When supported by std, remove this dependency
set(UUID_BUILD_TESTS OFF)
set(UUID_SYSTEM_GENERATOR ON)
set(UUID_SYSTEM_GENERATOR OFF)
set(UUID_USING_CXX20_SPAN OFF) # change this when going to C++20 as language standard for Radium libs
add_subdirectory(Dependencies/stduuid)
add_library(std::uuid ALIAS stduuid)
......@@ -356,6 +356,7 @@ target_link_libraries(
PUBLIC
Radium::Core
NodeEditor::nodes
std::uuid
${Qt_LIBRARIES}
${libName} # make this PRIVATE ?
)
......
......@@ -3,15 +3,32 @@
#include <Core/Utils/Log.hpp>
using namespace Ra::Core::Utils;
bool Node::s_uuidGeneratorInitialized {false};
uuids::uuid_random_generator* Node::s_uidGenerator{nullptr};
void Node::createUuidGenerator() {
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
s_uidGenerator = new uuids::uuid_random_generator(generator);
s_uuidGeneratorInitialized = true;
}
/// Generates the uuid of the node
void Node::generateUuid() {
m_uuid = uuids::uuid_system_generator{}();
if (!s_uuidGeneratorInitialized) {
createUuidGenerator();
}
m_uuid = (*s_uidGenerator)();
}
/// Gets the UUID of the node as a string
std::string Node::getUuid() const {
if ( m_uuid.is_nil() ) {
// generates the uuid (need to remove const attribute ...
const_cast<Node*>(this)->generateUuid();
std::string guuid = "{" + uuids::to_string(m_uuid) + "}";
std::cout << "###*** UUId generated for node" << getName() << " : " << guuid << std::endl;
}
std::string struuid = "{" + uuids::to_string(m_uuid) + "}";
return struuid;
......
......@@ -231,4 +231,9 @@ class NodeBasedRenderer_LIBRARY_API Node
/// Additional data on the node, added by application or gui or ...
nlohmann::json m_extraJsonData;
/// generator for uuid
static bool s_uuidGeneratorInitialized;
static uuids::uuid_random_generator* s_uidGenerator;
static void createUuidGenerator();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment