cpp-common/bt2c: add format_as() template functions for wise enums
[babeltrace.git] / src / cpp-common / bt2c / fmt.hpp
CommitLineData
7cf8258b
SM
1/*
2 * Copyright (c) 2024 EfficiOS, inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#include "common/common.h"
8#include "cpp-common/bt2/message.hpp"
9#include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */
91730cec 10#include "cpp-common/vendor/wise-enum/wise_enum.h"
7cf8258b 11
8f7f6134
SM
12#include "uuid.hpp"
13
91730cec
SM
14namespace internal {
15
16template <typename T>
17using EnableIfIsWiseEnum =
18 typename std::enable_if<wise_enum::is_wise_enum<T>::value, const char *>::type;
19
20} /* namespace internal */
21
7cf8258b
SM
22namespace bt2 {
23
91730cec
SM
24template <typename T>
25::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept
26{
27 return wise_enum::to_string<T>(val);
28}
29
7cf8258b
SM
30inline const char *format_as(const MessageType type)
31{
32 return bt_common_message_type_string(static_cast<bt_message_type>(type));
33}
34
35} /* namespace bt2 */
e05975eb
SM
36
37namespace bt2c {
38
91730cec
SM
39template <typename T>
40::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept
41{
42 return wise_enum::to_string<T>(val);
43}
44
e05975eb
SM
45inline std::string format_as(const UuidView uuid)
46{
47 return uuid.str();
48}
49
50} /* namespace bt2c */
This page took 0.030349 seconds and 4 git commands to generate.