From: Simon Marchi Date: Thu, 9 Jun 2022 15:23:33 +0000 (-0400) Subject: cpp-common: add GStringUP X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=73f0a62302bb4e2d5a9ba3521591c4f5272a8534;p=babeltrace.git 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 --- 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 */