// Copyright (c) OpenMMLab. All rights reserved. #ifndef MMDEPLOY_SRC_UTILS_FORMATTER_H_ #define MMDEPLOY_SRC_UTILS_FORMATTER_H_ #include "core/logger.h" #if FMT_VERSION >= 50000 #include "spdlog/fmt/bundled/ranges.h" #endif namespace mmdeploy { class Value; std::string format_value(const Value& value); } // namespace mmdeploy namespace fmt { #if FMT_VERSION >= 50000 template <> struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template auto format(const mmdeploy::Value& value, Context& ctx) { return format_to(ctx.out(), "{}", mmdeploy::format_value(value)); } }; #else inline void format_arg(BasicFormatter &f, const char *, const mmdeploy::Value &d) { f.writer() << mmdeploy::format_value(d); } template >, bool> = true> void format_arg(BasicFormatter &f, const char *, const T &v) { f.writer() << (int)v; } template auto format_arg(BasicFormatter &f, const char *, const T &v) -> std::void_t { f.writer() << "["; bool first = true; for (const auto &x : v) { f.writer() << (first ? "" : ", ") << fmt::format("{}", x); first = false; } f.writer() << "]"; } #endif } // namespace fmt #endif // MMDEPLOY_SRC_UTILS_FORMATTER_H_