Commit | Line | Data |
---|---|---|
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 |
14 | namespace internal { |
15 | ||
16 | template <typename T> | |
17 | using EnableIfIsWiseEnum = | |
18 | typename std::enable_if<wise_enum::is_wise_enum<T>::value, const char *>::type; | |
19 | ||
20 | } /* namespace internal */ | |
21 | ||
7cf8258b SM |
22 | namespace bt2 { |
23 | ||
91730cec SM |
24 | template <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 |
30 | inline 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 | |
37 | namespace bt2c { | |
38 | ||
91730cec SM |
39 | template <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 |
45 | inline std::string format_as(const UuidView uuid) |
46 | { | |
47 | return uuid.str(); | |
48 | } | |
49 | ||
50 | } /* namespace bt2c */ |