Skip to content

Commit 941d3f2

Browse files
committed
common: fold object_fmt.h into object.h
as fmtlib is now an accepted dependency in all of Ceph. Signed-off-by: Ronen Friedman <[email protected]>
1 parent e462f76 commit 941d3f2

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

src/common/hobject_fmt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <fmt/ranges.h>
1010

1111
#include "common/hobject.h"
12-
#include "include/object_fmt.h"
1312
#include "msg/msg_fmt.h"
1413

1514
// \todo reimplement

src/include/object.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <string>
2424
#include <string_view>
2525

26+
#include <fmt/compile.h>
27+
#include <fmt/format.h>
28+
2629
#include "include/rados.h"
2730
#include "include/unordered_map.h"
2831
#include "common/Formatter.h"
@@ -112,10 +115,10 @@ struct file_object_t {
112115
struct snapid_t {
113116
uint64_t val;
114117
// cppcheck-suppress noExplicitConstructor
115-
snapid_t(uint64_t v=0) : val(v) {}
118+
constexpr snapid_t(uint64_t v=0) : val(v) {}
116119
snapid_t operator+=(snapid_t o) { val += o.val; return *this; }
117120
snapid_t operator++() { ++val; return *this; }
118-
operator uint64_t() const { return val; }
121+
constexpr operator uint64_t() const { return val; }
119122
};
120123

121124
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) {
153156
return out << std::hex << s.val << std::dec;
154157
}
155158

159+
namespace fmt {
160+
template <>
161+
struct formatter<snapid_t> {
162+
163+
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
164+
165+
template <typename FormatContext>
166+
auto format(const snapid_t& snp, FormatContext& ctx) const
167+
{
168+
if (snp == CEPH_NOSNAP) {
169+
return fmt::format_to(ctx.out(), "head");
170+
}
171+
if (snp == CEPH_SNAPDIR) {
172+
return fmt::format_to(ctx.out(), "snapdir");
173+
}
174+
return fmt::format_to(ctx.out(), FMT_COMPILE("{:x}"), snp.val);
175+
}
176+
};
177+
} // namespace fmt
156178

157179
struct sobject_t {
158180
object_t oid;

src/include/object_fmt.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/test/osd/scrubber_generators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "include/buffer.h"
1515
#include "include/buffer_raw.h"
16-
#include "include/object_fmt.h"
16+
#include "include/object.h"
1717
#include "osd/osd_types_fmt.h"
1818
#include "osd/scrubber/pg_scrubber.h"
1919

0 commit comments

Comments
 (0)