From: Simon Marchi Date: Thu, 4 Apr 2024 03:02:27 +0000 (-0400) Subject: cpp-common/bt2: make `MessageType` a wise enum X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=928d766dec605f4024ff0de898eda2f3f141d3cb cpp-common/bt2: make `MessageType` a wise enum Change-Id: I46182e774ae480b20461ce44add48cea47bb0f3a Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12244 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index 93f8acd6..77321778 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -16,6 +16,7 @@ #include "cpp-common/bt2/clock-snapshot.hpp" #include "cpp-common/bt2/trace-ir.hpp" #include "cpp-common/bt2s/optional.hpp" +#include "cpp-common/vendor/wise-enum/wise_enum.h" #include "borrowed-object.hpp" #include "internal/utils.hpp" @@ -68,17 +69,19 @@ class CommonDiscardedPacketsMessage; template class CommonMessageIteratorInactivityMessage; -enum class MessageType -{ - StreamBeginning = BT_MESSAGE_TYPE_STREAM_BEGINNING, - StreamEnd = BT_MESSAGE_TYPE_STREAM_END, - Event = BT_MESSAGE_TYPE_EVENT, - PacketBeginning = BT_MESSAGE_TYPE_PACKET_BEGINNING, - PacketEnd = BT_MESSAGE_TYPE_PACKET_END, - DiscardedEvents = BT_MESSAGE_TYPE_DISCARDED_EVENTS, - DiscardedPackets = BT_MESSAGE_TYPE_DISCARDED_PACKETS, - MessageIteratorInactivity = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY, -}; +/* clang-format off */ + +WISE_ENUM_CLASS(MessageType, + (StreamBeginning, BT_MESSAGE_TYPE_STREAM_BEGINNING), + (StreamEnd, BT_MESSAGE_TYPE_STREAM_END), + (Event, BT_MESSAGE_TYPE_EVENT), + (PacketBeginning, BT_MESSAGE_TYPE_PACKET_BEGINNING), + (PacketEnd, BT_MESSAGE_TYPE_PACKET_END), + (DiscardedEvents, BT_MESSAGE_TYPE_DISCARDED_EVENTS), + (DiscardedPackets, BT_MESSAGE_TYPE_DISCARDED_PACKETS), + (MessageIteratorInactivity, BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY)); + +/* clang-format on */ template class CommonMessage : public BorrowedObject diff --git a/src/cpp-common/bt2c/fmt.hpp b/src/cpp-common/bt2c/fmt.hpp index 4633ebca..a78d7a61 100644 --- a/src/cpp-common/bt2c/fmt.hpp +++ b/src/cpp-common/bt2c/fmt.hpp @@ -4,8 +4,6 @@ * SPDX-License-Identifier: MIT */ -#include "common/common.h" -#include "cpp-common/bt2/message.hpp" #include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ #include "cpp-common/vendor/wise-enum/wise_enum.h" @@ -27,11 +25,6 @@ template return wise_enum::to_string(val); } -inline const char *format_as(const MessageType type) -{ - return bt_common_message_type_string(static_cast(type)); -} - } /* namespace bt2 */ namespace bt2c {