#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"
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> {
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>;
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