]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/hobject.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / common / hobject.h
index ef27e6f580ce6680f80f8fd33207e1759ef8e626..34191ccf5ec88b86a661f12073642cdb5190d613 100644 (file)
 #ifndef __CEPH_OS_HOBJECT_H
 #define __CEPH_OS_HOBJECT_H
 
+#if FMT_VERSION >= 90000
+#include <fmt/ostream.h>
+#endif
+
 #include "include/types.h"
-#include "include/cmp.h"
 
 #include "json_spirit/json_spirit_value.h"
 #include "include/ceph_assert.h"   // spirit clobbers it!
@@ -305,20 +308,26 @@ public:
   void dump(ceph::Formatter *f) const;
   static void generate_test_instances(std::list<hobject_t*>& o);
   friend int cmp(const hobject_t& l, const hobject_t& r);
-  friend bool operator>(const hobject_t& l, const hobject_t& r) {
-    return cmp(l, r) > 0;
-  }
-  friend bool operator>=(const hobject_t& l, const hobject_t& r) {
-    return cmp(l, r) >= 0;
-  }
-  friend bool operator<(const hobject_t& l, const hobject_t& r) {
-    return cmp(l, r) < 0;
+  auto operator<=>(const hobject_t &rhs) const noexcept {
+    auto cmp = max <=> rhs.max;
+    if (cmp != 0) return cmp;
+    cmp = pool <=> rhs.pool;
+    if (cmp != 0) return cmp;
+    cmp = get_bitwise_key() <=> rhs.get_bitwise_key();
+    if (cmp != 0) return cmp;
+    cmp = nspace <=> rhs.nspace;
+    if (cmp != 0) return cmp;
+    if (!(get_key().empty() && rhs.get_key().empty())) {
+      cmp = get_effective_key() <=> rhs.get_effective_key();
+      if (cmp != 0) return cmp;
+    }
+    cmp = oid <=> rhs.oid;
+    if (cmp != 0) return cmp;
+    return snap <=> rhs.snap;
   }
-  friend bool operator<=(const hobject_t& l, const hobject_t& r) {
-    return cmp(l, r) <= 0;
+  bool operator==(const hobject_t& rhs) const noexcept {
+    return operator<=>(rhs) == 0;
   }
-  friend bool operator==(const hobject_t&, const hobject_t&);
-  friend bool operator!=(const hobject_t&, const hobject_t&);
   friend struct ghobject_t;
 };
 WRITE_CLASS_ENCODER(hobject_t)
@@ -334,8 +343,6 @@ template<> struct hash<hobject_t> {
 
 std::ostream& operator<<(std::ostream& out, const hobject_t& o);
 
-WRITE_EQ_OPERATORS_7(hobject_t, hash, oid, get_key(), snap, pool, max, nspace)
-
 template <typename T>
 struct always_false {
   using value = std::false_type;
@@ -379,39 +386,30 @@ static inline int cmp(const T&, const hobject_t&r) {
 typedef version_t gen_t;
 
 struct ghobject_t {
-  hobject_t hobj;
-  gen_t generation;
-  shard_id_t shard_id;
-  bool max;
-
-public:
   static const gen_t NO_GEN = UINT64_MAX;
 
-  ghobject_t()
-    : generation(NO_GEN),
-      shard_id(shard_id_t::NO_SHARD),
-      max(false) {}
+  bool max = false;
+  shard_id_t shard_id = shard_id_t::NO_SHARD;
+  hobject_t hobj;
+  gen_t generation = NO_GEN;
+
+  ghobject_t() = default;
 
   explicit ghobject_t(const hobject_t &obj)
-    : hobj(obj),
-      generation(NO_GEN),
-      shard_id(shard_id_t::NO_SHARD),
-      max(false) {}
+    : hobj(obj) {}
 
   ghobject_t(const hobject_t &obj, gen_t gen, shard_id_t shard)
-    : hobj(obj),
-      generation(gen),
-      shard_id(shard),
-      max(false) {}
+    : shard_id(shard),
+      hobj(obj),
+      generation(gen) {}
 
   // used by Crimson
   ghobject_t(shard_id_t shard, int64_t pool, uint32_t reversed_hash,
              const std::string& nspace, const std::string& oid,
              snapid_t snap, gen_t gen)
-    : hobj(oid, snap, reversed_hash, pool, nspace),
-      generation(gen),
-      shard_id(shard),
-      max(false) {}
+    : shard_id(shard),
+      hobj(oid, snap, reversed_hash, pool, nspace),
+      generation(gen) {}
 
   static ghobject_t make_pgmeta(int64_t pool, uint32_t hash, shard_id_t shard) {
     hobject_t h(object_t(), std::string(), CEPH_NOSNAP, hash, pool, std::string());
@@ -487,21 +485,8 @@ public:
   void dump(ceph::Formatter *f) const;
   static void generate_test_instances(std::list<ghobject_t*>& o);
   friend int cmp(const ghobject_t& l, const ghobject_t& r);
-  friend bool operator>(const ghobject_t& l, const ghobject_t& r) {
-    return cmp(l, r) > 0;
-  }
-  friend bool operator>=(const ghobject_t& l, const ghobject_t& r) {
-    return cmp(l, r) >= 0;
-  }
-  friend bool operator<(const ghobject_t& l, const ghobject_t& r) {
-    return cmp(l, r) < 0;
-  }
-  friend bool operator<=(const ghobject_t& l, const ghobject_t& r) {
-    return cmp(l, r) <= 0;
-  }
-  friend bool operator==(const ghobject_t&, const ghobject_t&);
-  friend bool operator!=(const ghobject_t&, const ghobject_t&);
-
+  auto operator<=>(const ghobject_t&) const = default;
+  bool operator==(const ghobject_t&) const = default;
 };
 WRITE_CLASS_ENCODER(ghobject_t)
 
@@ -520,7 +505,9 @@ namespace std {
 
 std::ostream& operator<<(std::ostream& out, const ghobject_t& o);
 
-WRITE_EQ_OPERATORS_4(ghobject_t, max, shard_id, hobj, generation)
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<ghobject_t> : fmt::ostream_formatter {};
+#endif
 
 extern int cmp(const ghobject_t& l, const ghobject_t& r);