]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: fold object_fmt.h into object.h
authorRonen Friedman <rfriedma@redhat.com>
Thu, 15 Feb 2024 18:28:11 +0000 (12:28 -0600)
committerRonen Friedman <rfriedma@redhat.com>
Wed, 21 Feb 2024 14:07:06 +0000 (08:07 -0600)
as fmtlib is now an accepted dependency in all of Ceph.

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/hobject_fmt.h
src/include/object.h
src/include/object_fmt.h [deleted file]
src/test/osd/scrubber_generators.h

index 622611121ae6fb680a9d83cd505987dcd37c8ac7..a2a730e1c5fc9c5ec88cbd4ff46abe54272a84a1 100644 (file)
@@ -9,7 +9,6 @@
 #include <fmt/ranges.h>
 
 #include "common/hobject.h"
-#include "include/object_fmt.h"
 #include "msg/msg_fmt.h"
 
 // \todo reimplement
index 2e5fb471c139e1a52e3281f7728336173bb8364d..4e6001d09e609780f01317ac3e563e887703972a 100644 (file)
@@ -23,6 +23,9 @@
 #include <string>
 #include <string_view>
 
+#include <fmt/compile.h>
+#include <fmt/format.h>
+
 #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<snapid_t> {
+
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  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 (file)
index 25fbc67..0000000
+++ /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 <fmt/compile.h>
-#include <fmt/format.h>
-
-#include "object.h"
-
-
-template <>
-struct fmt::formatter<snapid_t> {
-
-  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
-
-  template <typename FormatContext>
-  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);
-  }
-};
index d0cbb22c4c8061fdfbf91556bbf52de3cd6531c1..43b123250cc1e4a7cdd4ccdce37f4cd54425ab43 100644 (file)
@@ -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"