]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
include/object: un-inline methods to reduce header dependencies
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 29 Oct 2024 07:26:08 +0000 (08:26 +0100)
committerMax Kellermann <max.kellermann@ionos.com>
Tue, 5 Aug 2025 08:28:01 +0000 (10:28 +0200)
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/CMakeLists.txt
src/crimson/CMakeLists.txt
src/include/object.cc [new file with mode: 0644]
src/include/object.h

index 82ee7987c794277fb82d6e3dbec6cc97ca95f1af..88964a1f685e26c6b0886619b3e0684c494eac3f 100644 (file)
@@ -501,6 +501,7 @@ set(libcommon_files
   global/global_context.cc
   xxHash/xxhash.c
   include/invoke_date.cc
+  include/object.cc
   include/utime.cc
   include/uuid.cc
   common/error_code.cc
index dd524001a7021367bcb6526971970453716b5f8d..e53846843ecc0361d493fd70d5ba5104765f4368 100644 (file)
@@ -98,6 +98,7 @@ add_library(crimson-common STATIC
   ${PROJECT_SOURCE_DIR}/src/crush/CrushTester.cc
   ${PROJECT_SOURCE_DIR}/src/global/global_context.cc
   ${PROJECT_SOURCE_DIR}/src/global/pidfile.cc
+  ${PROJECT_SOURCE_DIR}/src/include/object.cc
   ${PROJECT_SOURCE_DIR}/src/include/utime.cc
   ${PROJECT_SOURCE_DIR}/src/include/uuid.cc
   ${PROJECT_SOURCE_DIR}/src/librbd/Features.cc
diff --git a/src/include/object.cc b/src/include/object.cc
new file mode 100644 (file)
index 0000000..2be187c
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#include "object.h"
+#include "common/Formatter.h"
+
+#include <cstdio>
+
+void object_t::encode(ceph::buffer::list &bl) const {
+  using ceph::encode;
+  encode(name, bl);
+}
+
+void object_t::decode(ceph::buffer::list::const_iterator &bl) {
+  using ceph::decode;
+  decode(name, bl);
+}
+
+void object_t::dump(ceph::Formatter *f) const {
+  f->dump_string("name", name);
+}
+
+void object_t::generate_test_instances(std::list<object_t*>& o) {
+  o.push_back(new object_t);
+  o.push_back(new object_t("myobject"));
+}
+
+std::ostream& operator<<(std::ostream& out, const object_t& o) {
+  return out << o.name;
+}
+
+const char *file_object_t::c_str() const {
+  if (!buf[0])
+    snprintf(buf, sizeof(buf), "%llx.%08llx", (long long unsigned)ino, (long long unsigned)bno);
+  return buf;
+}
+
+std::ostream& operator<<(std::ostream& out, const snapid_t& s) {
+  if (s == CEPH_NOSNAP)
+    return out << "head";
+  else if (s == CEPH_SNAPDIR)
+    return out << "snapdir";
+  else
+    return out << std::hex << s.val << std::dec;
+}
+
+void sobject_t::dump(ceph::Formatter *f) const {
+  f->dump_stream("oid") << oid;
+  f->dump_stream("snap") << snap;
+}
+
+void sobject_t::generate_test_instances(std::list<sobject_t*>& o) {
+  o.push_back(new sobject_t);
+  o.push_back(new sobject_t(object_t("myobject"), 123));
+}
+
+std::ostream& operator<<(std::ostream& out, const sobject_t &o) {
+  return out << o.oid << "/" << o.snap;
+}
index 7adf9413efd8ccc01d002507c537b8768161d169..81e8ab2d9d090c4ea98ec1a37bf24cf27719400d 100644 (file)
@@ -16,9 +16,8 @@
 #define CEPH_OBJECT_H
 
 #include <cstdint>
-#include <cstdio>
+#include <iosfwd>
 #include <list>
-#include <ostream>
 #include <string>
 #include <string>
 #include <string_view>
 #include <fmt/format.h>
 
 #include "include/rados.h"
-#include "common/Formatter.h"
 
 #include "hash.h"
 #include "encoding.h"
 #include "ceph_hash.h"
 
+namespace ceph { class Formatter; }
+
 struct object_t {
   std::string name;
 
@@ -53,29 +53,16 @@ struct object_t {
     name.clear();
   }
 
-  void encode(ceph::buffer::list &bl) const {
-    using ceph::encode;
-    encode(name, bl);
-  }
-  void decode(ceph::buffer::list::const_iterator &bl) {
-    using ceph::decode;
-    decode(name, bl);
-  }
+  void encode(ceph::buffer::list &bl) const;
+  void decode(ceph::buffer::list::const_iterator &bl);
 
-  void dump(ceph::Formatter *f) const {
-    f->dump_string("name", name);
-  }
+  void dump(ceph::Formatter *f) const;
 
-  static void generate_test_instances(std::list<object_t*>& o) {
-    o.push_back(new object_t);
-    o.push_back(new object_t("myobject"));
-  }
+  static void generate_test_instances(std::list<object_t*>& o);
 };
 WRITE_CLASS_ENCODER(object_t)
 
-inline std::ostream& operator<<(std::ostream& out, const object_t& o) {
-  return out << o.name;
-}
+std::ostream& operator<<(std::ostream& out, const object_t& o);
 
 namespace std {
 template<> struct hash<object_t> {
@@ -96,11 +83,7 @@ struct file_object_t {
     buf[0] = 0;
   }
   
-  const char *c_str() const {
-    if (!buf[0])
-      snprintf(buf, sizeof(buf), "%llx.%08llx", (long long unsigned)ino, (long long unsigned)bno);
-    return buf;
-  }
+  const char *c_str() const;
 
   operator object_t() {
     return object_t(c_str());
@@ -146,14 +129,7 @@ struct denc_traits<snapid_t> {
   }
 };
 
-inline std::ostream& operator<<(std::ostream& out, const snapid_t& s) {
-  if (s == CEPH_NOSNAP)
-    return out << "head";
-  else if (s == CEPH_SNAPDIR)
-    return out << "snapdir";
-  else
-    return out << std::hex << s.val << std::dec;
-}
+std::ostream& operator<<(std::ostream& out, const snapid_t& s);
 
 namespace fmt {
 template <>
@@ -201,20 +177,13 @@ struct sobject_t {
     decode(oid, bl);
     decode(snap, bl);
   }
-  void dump(ceph::Formatter *f) const {
-    f->dump_stream("oid") << oid;
-    f->dump_stream("snap") << snap;
-  }
-  static void generate_test_instances(std::list<sobject_t*>& o) {
-    o.push_back(new sobject_t);
-    o.push_back(new sobject_t(object_t("myobject"), 123));
-  }
+  void dump(ceph::Formatter *f) const;
+  static void generate_test_instances(std::list<sobject_t*>& o);
 };
 WRITE_CLASS_ENCODER(sobject_t)
 
-inline std::ostream& operator<<(std::ostream& out, const sobject_t &o) {
-  return out << o.oid << "/" << o.snap;
-}
+std::ostream& operator<<(std::ostream& out, const sobject_t &o);
+
 namespace std {
 template<> struct hash<sobject_t> {
   size_t operator()(const sobject_t &r) const {