From 206cdb1c774da60587e609f4d8e0727da0057402 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Oct 2024 08:26:08 +0100 Subject: [PATCH] include/object: un-inline methods to reduce header dependencies Signed-off-by: Max Kellermann --- src/CMakeLists.txt | 1 + src/crimson/CMakeLists.txt | 1 + src/include/object.cc | 70 ++++++++++++++++++++++++++++++++++++++ src/include/object.h | 59 ++++++++------------------------ 4 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 src/include/object.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82ee7987c79..88964a1f685 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index dd524001a70..e53846843ec 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -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 index 00000000000..2be187c3e62 --- /dev/null +++ b/src/include/object.cc @@ -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 + * + * 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 + +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& 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& 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; +} diff --git a/src/include/object.h b/src/include/object.h index 7adf9413efd..81e8ab2d9d0 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -16,9 +16,8 @@ #define CEPH_OBJECT_H #include -#include +#include #include -#include #include #include #include @@ -27,12 +26,13 @@ #include #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& o) { - o.push_back(new object_t); - o.push_back(new object_t("myobject")); - } + static void generate_test_instances(std::list& 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 { @@ -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 { } }; -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& 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& 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 { size_t operator()(const sobject_t &r) const { -- 2.39.5