From 7cf8258bc7c82e1ef4745549d5a729c88f931b62 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 8 Feb 2024 15:36:41 -0500 Subject: [PATCH] cpp-common/bt2c: add `format_as` function for `bt2::MessageType` 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 --- src/Makefile.am | 1 + src/cpp-common/bt2c/fmt.hpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/cpp-common/bt2c/fmt.hpp diff --git a/src/Makefile.am b/src/Makefile.am index 30b27a40..4cdbdd1b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 00000000..8db4b1b6 --- /dev/null +++ b/src/cpp-common/bt2c/fmt.hpp @@ -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(type)); +} + +} /* namespace bt2 */ -- 2.34.1