From: Jérémie Galarneau Date: Thu, 2 Jun 2022 15:00:40 +0000 (-0400) Subject: common: uuid: add `uuid_to_str` which returns an std::string X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=23083fa05cee494d938b0db84140dd661a30c4dc;p=lttng-tools.git common: uuid: add `uuid_to_str` which returns an std::string Signed-off-by: Jérémie Galarneau Change-Id: Id915ba7dbe8128d492d92faa05bbf12770a49f8d --- diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index a820a8a41..d4f0fb2bf 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp @@ -26,6 +26,18 @@ void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str) sprintf(uuid_str, LTTNG_UUID_FMT, LTTNG_UUID_FMT_VALUES(uuid)); } +std::string lttng::utils::uuid_to_str(const lttng_uuid& uuid) +{ + std::string uuid_str(LTTNG_UUID_STR_LEN, '\0'); + + ::lttng_uuid_to_str(uuid, &uuid_str[0]); + + /* Don't include '\0' in the C++ string. */ + uuid_str.resize(uuid_str.size() - 1); + + return uuid_str; +} + int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out) { int ret = 0; diff --git a/src/common/uuid.hpp b/src/common/uuid.hpp index 0cd3966be..586c2ad67 100644 --- a/src/common/uuid.hpp +++ b/src/common/uuid.hpp @@ -13,6 +13,7 @@ #include #include #include +#include /* * Includes final \0. @@ -49,6 +50,12 @@ int lttng_uuid_from_str(const char *str_in, lttng_uuid& uuid_out); */ void lttng_uuid_to_str(const lttng_uuid& uuid, char *uuid_str); +namespace lttng { +namespace utils { +std::string uuid_to_str(const lttng_uuid& uuid); +} /* namespace utils */ +} /* namespace lttng */ + bool lttng_uuid_is_equal(const lttng_uuid& a, const lttng_uuid& b); bool lttng_uuid_is_nil(const lttng_uuid& uuid);