From 941d3f2aac87160f9d09de3e2f1ddea1e51e7275 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Thu, 15 Feb 2024 12:28:11 -0600 Subject: [PATCH] common: fold object_fmt.h into object.h as fmtlib is now an accepted dependency in all of Ceph. Signed-off-by: Ronen Friedman --- src/common/hobject_fmt.h | 1 - src/include/object.h | 26 ++++++++++++++++++++++++-- src/include/object_fmt.h | 30 ------------------------------ src/test/osd/scrubber_generators.h | 2 +- 4 files changed, 25 insertions(+), 34 deletions(-) delete mode 100644 src/include/object_fmt.h diff --git a/src/common/hobject_fmt.h b/src/common/hobject_fmt.h index 622611121ae..a2a730e1c5f 100644 --- a/src/common/hobject_fmt.h +++ b/src/common/hobject_fmt.h @@ -9,7 +9,6 @@ #include #include "common/hobject.h" -#include "include/object_fmt.h" #include "msg/msg_fmt.h" // \todo reimplement diff --git a/src/include/object.h b/src/include/object.h index 2e5fb471c13..4e6001d09e6 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -23,6 +23,9 @@ #include #include +#include +#include + #include "include/rados.h" #include "include/unordered_map.h" #include "common/Formatter.h" @@ -112,10 +115,10 @@ struct file_object_t { struct snapid_t { uint64_t val; // cppcheck-suppress noExplicitConstructor - snapid_t(uint64_t v=0) : val(v) {} + constexpr snapid_t(uint64_t v=0) : val(v) {} snapid_t operator+=(snapid_t o) { val += o.val; return *this; } snapid_t operator++() { ++val; return *this; } - operator uint64_t() const { return val; } + constexpr operator uint64_t() const { return val; } }; inline void encode(snapid_t i, ceph::buffer::list &bl) { @@ -153,6 +156,25 @@ inline std::ostream& operator<<(std::ostream& out, const snapid_t& s) { return out << std::hex << s.val << std::dec; } +namespace fmt { +template <> +struct formatter { + + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + + template + auto format(const snapid_t& snp, FormatContext& ctx) const + { + if (snp == CEPH_NOSNAP) { + return fmt::format_to(ctx.out(), "head"); + } + if (snp == CEPH_SNAPDIR) { + return fmt::format_to(ctx.out(), "snapdir"); + } + return fmt::format_to(ctx.out(), FMT_COMPILE("{:x}"), snp.val); + } +}; +} // namespace fmt struct sobject_t { object_t oid; diff --git a/src/include/object_fmt.h b/src/include/object_fmt.h deleted file mode 100644 index 25fbc6714c8..00000000000 --- a/src/include/object_fmt.h +++ /dev/null @@ -1,30 +0,0 @@ -// -*- 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 object.h structs - */ -#include -#include - -#include "object.h" - - -template <> -struct fmt::formatter { - - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const snapid_t& snp, FormatContext& ctx) const - { - if (snp == CEPH_NOSNAP) { - return fmt::format_to(ctx.out(), "head"); - } - if (snp == CEPH_SNAPDIR) { - return fmt::format_to(ctx.out(), "snapdir"); - } - return fmt::format_to(ctx.out(), FMT_COMPILE("{:x}"), snp.val); - } -}; diff --git a/src/test/osd/scrubber_generators.h b/src/test/osd/scrubber_generators.h index d0cbb22c4c8..43b123250cc 100644 --- a/src/test/osd/scrubber_generators.h +++ b/src/test/osd/scrubber_generators.h @@ -13,7 +13,7 @@ #include "include/buffer.h" #include "include/buffer_raw.h" -#include "include/object_fmt.h" +#include "include/object.h" #include "osd/osd_types_fmt.h" #include "osd/scrubber/pg_scrubber.h" -- 2.39.5