From 74b7f5f57f0ed2f572c779d92f1ebd9b143f0428 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 9 Jul 2018 13:03:25 +0200 Subject: [PATCH] uuid handling improved --- src/core/entity.cpp | 17 +++++++++++++++-- src/core/entity.h | 15 +++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/core/entity.cpp b/src/core/entity.cpp index 4c9ece5..ac48025 100644 --- a/src/core/entity.cpp +++ b/src/core/entity.cpp @@ -1,7 +1,20 @@ #include "entity.h" -#include +#include -Entity::Entity() : uuid(boost::uuids::random_generator()()) +#include +#include + +Entity::Entity() {} + +void Entity::createUuid() { + static boost::uuids::random_generator generator{}; + uuid = generator(); +} + +void Entity::createUuidFromString(const std::string& uuid_string) +{ + boost::uuids::string_generator generator{}; + uuid = generator(uuid_string); } \ No newline at end of file diff --git a/src/core/entity.h b/src/core/entity.h index e7afcbe..b36d9a3 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -7,12 +7,15 @@ class Entity { -public: + public: Entity(); - ~Entity(); - const boost::uuids::uuid& getUuid() {return uuid;}; -private: - boost::uuids::uuid uuid; + virtual ~Entity() = 0; + const boost::uuids::uuid& getUuid() { return uuid; }; + void createUuid(); + void createUuidFromString(const std::string& uuid_string); + + private: + boost::uuids::uuid uuid{}; }; -#endif //ENTITY_H \ No newline at end of file +#endif // ENTITY_H \ No newline at end of file