]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: fixing fmtlib-related compilation issues 52904/head
authorRonen Friedman <rfriedma@redhat.com>
Thu, 10 Aug 2023 06:38:39 +0000 (01:38 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 16 Aug 2023 10:29:09 +0000 (05:29 -0500)
brought about by the change to fmt formatting support.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/crimson/os/seastore/onode_manager/staged-fltree/stages/stage_types.h

index 3c1b32a415be2b362518c8652a7bd765bfa6a10e..9bbfd5d6063b8d2c4edb95a96ec83e7f5386852a 100644 (file)
@@ -7,6 +7,7 @@
 #include <optional>
 #include <ostream>
 
+#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 <match_stage_t STAGE>
-std::ostream& operator<<(std::ostream& os, const staged_position_t<STAGE>& 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<STAGE_BOTTOM> {
@@ -280,19 +280,17 @@ struct staged_position_t<STAGE_BOTTOM> {
   static me_t end() { return {INDEX_END}; }
 
   index_t index;
-};
-template <>
-inline std::ostream& operator<<(std::ostream& os, const staged_position_t<STAGE_BOTTOM>& 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<STAGE_TOP>;
 
@@ -433,10 +431,30 @@ struct node_stats_t {
   unsigned num_kvs = 0;
 };
 
+} // namespace crimson::os::seastore::onode
+
+namespace std {
+template <crimson::os::seastore::onode::match_stage_t STAGE>
+std::ostream& operator<<(
+    std::ostream& os,
+    const crimson::os::seastore::onode::staged_position_t<STAGE>& pos) {
+  return os << pos.fmt_print();
 }
+} // namespace std
 
-#if FMT_VERSION >= 90000
+
+namespace fmt {
 template <crimson::os::seastore::onode::match_stage_t S>
-struct fmt::formatter<crimson::os::seastore::onode::staged_position_t<S>> : fmt::ostream_formatter {};
-template <> struct fmt::formatter<crimson::os::seastore::onode::MatchHistory> : fmt::ostream_formatter {};
+struct formatter<crimson::os::seastore::onode::staged_position_t<S>> {
+  constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
+  template <typename FormatContext>
+  auto format(const crimson::os::seastore::onode::staged_position_t<S>& k,
+              FormatContext& ctx) const {
+    return fmt::format_to(ctx.out(), "{}", k.fmt_print());
+  }
+};
+
+#if FMT_VERSION >= 90000
+template <> struct formatter<crimson::os::seastore::onode::MatchHistory> : ostream_formatter {};
 #endif
+}  // namespace fmt