| 1 | /* |
| 2 | * Copyright (c) 2024 EfficiOS, inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_CPP_COMMON_BT2C_FMT_HPP |
| 8 | #define BABELTRACE_CPP_COMMON_BT2C_FMT_HPP |
| 9 | |
| 10 | #include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ |
| 11 | #include "cpp-common/vendor/wise-enum/wise_enum.h" |
| 12 | |
| 13 | #include "uuid.hpp" |
| 14 | |
| 15 | namespace internal { |
| 16 | |
| 17 | template <typename T> |
| 18 | using EnableIfIsWiseEnum = |
| 19 | typename std::enable_if<wise_enum::is_wise_enum<T>::value, wise_enum::string_type>::type; |
| 20 | |
| 21 | } /* namespace internal */ |
| 22 | |
| 23 | namespace bt2 { |
| 24 | |
| 25 | template <typename T> |
| 26 | ::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept |
| 27 | { |
| 28 | return wise_enum::to_string<T>(val); |
| 29 | } |
| 30 | |
| 31 | } /* namespace bt2 */ |
| 32 | |
| 33 | namespace bt2c { |
| 34 | |
| 35 | template <typename T> |
| 36 | ::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept |
| 37 | { |
| 38 | return wise_enum::to_string<T>(val); |
| 39 | } |
| 40 | |
| 41 | inline std::string format_as(const UuidView uuid) |
| 42 | { |
| 43 | return uuid.str(); |
| 44 | } |
| 45 | |
| 46 | } /* namespace bt2c */ |
| 47 | |
| 48 | #endif /* BABELTRACE_CPP_COMMON_BT2C_FMT_HPP */ |