#ifndef __CEPH_OS_HOBJECT_H
#define __CEPH_OS_HOBJECT_H
+#include <fmt/compile.h>
+#include <fmt/format.h>
+
#if FMT_VERSION >= 90000
#include <fmt/ostream.h>
#endif
};
} // namespace std
+namespace fmt {
+template <>
+struct formatter<hobject_t> {
+
+ template <typename FormatContext>
+ static inline auto
+ append_sanitized(FormatContext& ctx, const std::string& in, int sep = 0)
+ {
+ for (const auto i : in) {
+ if (i == '%' || i == ':' || i == '/' || i < 32 || i >= 127) {
+ fmt::format_to(
+ ctx.out(), FMT_COMPILE("%{:02x}"), static_cast<unsigned char>(i));
+ } else {
+ fmt::format_to(ctx.out(), FMT_COMPILE("{:c}"), i);
+ }
+ }
+ if (sep) {
+ fmt::format_to(
+ ctx.out(), FMT_COMPILE("{:c}"), sep);
+ }
+ return ctx.out();
+ }
+
+ constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+ template <typename FormatContext>
+ auto format(const hobject_t& ho, FormatContext& ctx)
+ {
+ if (ho == hobject_t{}) {
+ return fmt::format_to(ctx.out(), "MIN");
+ }
+
+ if (ho.is_max()) {
+ return fmt::format_to(ctx.out(), "MAX");
+ }
+
+ fmt::format_to(
+ ctx.out(), FMT_COMPILE("{}:{:08x}:"), static_cast<uint64_t>(ho.pool),
+ ho.get_bitwise_key_u32());
+ append_sanitized(ctx, ho.nspace, ':');
+ append_sanitized(ctx, ho.get_key(), ':');
+ append_sanitized(ctx, ho.oid.name);
+ return fmt::format_to(ctx.out(), FMT_COMPILE(":{}"), ho.snap);
+ }
+};
+} // namespace fmt
+
+
std::ostream& operator<<(std::ostream& out, const hobject_t& o);
template <typename T>
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-#pragma once
-
-/**
- * \file fmtlib formatters for some hobject.h classes
- */
-#include <fmt/format.h>
-#include <fmt/ranges.h>
-
-#include "common/hobject.h"
-#include "msg/msg_fmt.h"
-
-// \todo reimplement
-static inline void append_out_escaped(const std::string& in, std::string* out)
-{
- for (auto i = in.cbegin(); i != in.cend(); ++i) {
- if (*i == '%' || *i == ':' || *i == '/' || *i < 32 || *i >= 127) {
- char buf[4];
- snprintf(buf, sizeof(buf), "%%%02x", (int)(unsigned char)*i);
- out->append(buf);
- } else {
- out->push_back(*i);
- }
- }
-}
-
-template <> struct fmt::formatter<hobject_t> {
-
- constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
-
- template <typename FormatContext> auto format(const hobject_t& ho, FormatContext& ctx)
- {
- if (ho == hobject_t{}) {
- return fmt::format_to(ctx.out(), "MIN");
- }
-
- if (ho.is_max()) {
- return fmt::format_to(ctx.out(), "MAX");
- }
-
- std::string v;
- append_out_escaped(ho.nspace, &v);
- v.push_back(':');
- append_out_escaped(ho.get_key(), &v);
- v.push_back(':');
- append_out_escaped(ho.oid.name, &v);
-
- return fmt::format_to(ctx.out(), "{}:{:08x}:{}:{}", static_cast<uint64_t>(ho.pool),
- ho.get_bitwise_key_u32(), v, ho.snap);
- }
-};
#include <algorithm>
#include <boost/type_index.hpp>
#include <fmt/ranges.h>
-#include "common/hobject_fmt.h"
+#include "common/hobject.h"
#include "crimson/osd/backfill_state.h"
#include "osd/osd_types_fmt.h"
#include <fmt/format.h>
#include <fmt/ostream.h>
-#include "common/hobject_fmt.h"
+#include "common/hobject.h"
#include "messages/MOSDOp.h"
#include "messages/MOSDOpReply.h"
#include "common/fmt_common.h"
#include "common/hobject.h"
-#include "common/hobject_fmt.h"
#include "crimson/common/log.h"
#include "osd/osd_types_fmt.h"
#include "scrub_validator.h"
}
void dump(ceph::Formatter *f) const;
+ template <typename FormatContext>
+ auto fmt_print_ctx(FormatContext& ctx) const {
+ if (is_new() || _num < 0) {
+ return fmt::format_to(ctx.out(), "{}.?", type_str());
+ } else {
+ return fmt::format_to(ctx.out(), "{}.{}",type_str(), _num);
+ }
+ }
+
static void generate_test_instances(std::list<entity_name_t*>& o);
};
WRITE_CLASS_DENC(entity_name_t)
* \file fmtlib formatters for some types.h classes
*/
-#include "common/hobject_fmt.h"
+#include "common/hobject.h"
#include "osd/osd_types.h"
#include <fmt/chrono.h>
+#include <fmt/ranges.h>
#if FMT_VERSION >= 90000
#include <fmt/ostream.h>
#endif