cpp-common/bt2c: add `format_as` function for `bt2::MessageType`
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 8 Feb 2024 20:36:41 +0000 (15:36 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 9 Feb 2024 19:07:31 +0000 (14:07 -0500)
Add a `format_as` that lets {fmt} format variables of type
`bt2::MessageType` directly.  Re-use `bt_common_message_type_string` to
avoid duplicating that code.

Change-Id: I81152a152284b156535813fd8fa5d61a3dd7219f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
src/Makefile.am
src/cpp-common/bt2c/fmt.hpp [new file with mode: 0644]

index 30b27a407bde56a9cd4e93795eaae9bec1a21209..4cdbdd1b915afcb328058888749cd03175ee57a1 100644 (file)
@@ -149,6 +149,7 @@ cpp_common_libcpp_common_la_SOURCES = \
        cpp-common/bt2c/dummy.cpp \
        cpp-common/bt2c/endian.hpp \
        cpp-common/bt2c/exc.hpp \
+       cpp-common/bt2c/fmt.hpp \
        cpp-common/bt2c/glib-up.hpp \
        cpp-common/bt2c/libc-up.hpp \
        cpp-common/bt2c/logging.hpp \
diff --git a/src/cpp-common/bt2c/fmt.hpp b/src/cpp-common/bt2c/fmt.hpp
new file mode 100644 (file)
index 0000000..8db4b1b
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2024 EfficiOS, inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include "common/common.h"
+#include "cpp-common/bt2/message.hpp"
+#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */
+
+namespace bt2 {
+
+inline const char *format_as(const MessageType type)
+{
+    return bt_common_message_type_string(static_cast<bt_message_type>(type));
+}
+
+} /* namespace bt2 */
This page took 0.027292 seconds and 4 git commands to generate.