From 8b3101f3b871e32490c297d3d853af98a10d1e36 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Thu, 10 Aug 2023 01:38:39 -0500 Subject: [PATCH] crimson/osd: fixing fmtlib-related compilation issues brought about by the change to fmt formatting support. Signed-off-by: Ronen Friedman --- .../staged-fltree/stages/stage_types.h | 72 ++++++++++++------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h index 3c1b32a415be2..9bbfd5d6063b8 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h @@ -7,6 +7,7 @@ #include #include +#include "common/fmt_common.h" #include "crimson/os/seastore/onode_manager/staged-fltree/fwd.h" #include "crimson/os/seastore/onode_manager/staged-fltree/node_types.h" #include "crimson/os/seastore/onode_manager/staged-fltree/value.h" @@ -207,19 +208,18 @@ struct staged_position_t { index_t index; nxt_t nxt; -}; -template -std::ostream& operator<<(std::ostream& os, const staged_position_t& pos) { - if (pos.index == INDEX_END) { - os << "END"; - } else if (pos.index == INDEX_LAST) { - os << "LAST"; - } else { - os << pos.index; - assert(is_valid_index(pos.index)); + + std::string fmt_print() const { + if (index == INDEX_END) { + return fmt::format("END, {}", nxt.fmt_print()); + } + if (index == INDEX_LAST) { + return fmt::format("LAST, {}", nxt.fmt_print()); + } + assert(is_valid_index(index)); + return fmt::format("{}, {}", index, nxt.fmt_print()); } - return os << ", " << pos.nxt; -} +}; template <> struct staged_position_t { @@ -280,19 +280,17 @@ struct staged_position_t { static me_t end() { return {INDEX_END}; } index_t index; -}; -template <> -inline std::ostream& operator<<(std::ostream& os, const staged_position_t& pos) { - if (pos.index == INDEX_END) { - os << "END"; - } else if (pos.index == INDEX_LAST) { - os << "LAST"; - } else { - os << pos.index; - assert(is_valid_index(pos.index)); + std::string fmt_print() const { + if (index == INDEX_END) { + return "END"; + } + if (index == INDEX_LAST) { + return "LAST"; + } + assert(is_valid_index(index)); + return std::to_string(index); } - return os; -} +}; using search_position_t = staged_position_t; @@ -433,10 +431,30 @@ struct node_stats_t { unsigned num_kvs = 0; }; +} // namespace crimson::os::seastore::onode + +namespace std { +template +std::ostream& operator<<( + std::ostream& os, + const crimson::os::seastore::onode::staged_position_t& pos) { + return os << pos.fmt_print(); } +} // namespace std -#if FMT_VERSION >= 90000 + +namespace fmt { template -struct fmt::formatter> : fmt::ostream_formatter {}; -template <> struct fmt::formatter : fmt::ostream_formatter {}; +struct formatter> { + constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } + template + auto format(const crimson::os::seastore::onode::staged_position_t& k, + FormatContext& ctx) const { + return fmt::format_to(ctx.out(), "{}", k.fmt_print()); + } +}; + +#if FMT_VERSION >= 90000 +template <> struct formatter : ostream_formatter {}; #endif +} // namespace fmt -- 2.47.3