From 73f0a62302bb4e2d5a9ba3521591c4f5272a8534 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 9 Jun 2022 11:23:33 -0400 Subject: [PATCH] cpp-common: add GStringUP Add a type to automatically manage the lifetime of GString objects. Change-Id: I60e08f7d62c290c0194ed0cd62b0d0491b9af2bd Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8288 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/10844 CI-Build: Philippe Proulx Tested-by: jenkins --- src/cpp-common/glib-up.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cpp-common/glib-up.hpp b/src/cpp-common/glib-up.hpp index 92bbde09..4ff0ed85 100644 --- a/src/cpp-common/glib-up.hpp +++ b/src/cpp-common/glib-up.hpp @@ -25,6 +25,20 @@ struct GCharDeleter final using GCharUP = std::unique_ptr; +namespace internal { + +struct GStringDeleter final +{ + void operator()(GString * const str) + { + g_string_free(str, TRUE); + } +}; + +} /* namespace internal */ + +using GStringUP = std::unique_ptr; + } /* namespace bt2_common */ #endif /* BABELTRACE_CPP_COMMON_GLIB_UP_HPP */ -- 2.34.1