summaryrefslogtreecommitdiffstats
path: root/src/common/ref.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/common/ref.h
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/ref.h')
-rw-r--r--src/common/ref.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/ref.h b/src/common/ref.h
new file mode 100644
index 000000000..055c9a07a
--- /dev/null
+++ b/src/common/ref.h
@@ -0,0 +1,34 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef COMMON_REF_H
+#define COMMON_REF_H
+
+#include <boost/intrusive_ptr.hpp>
+
+namespace ceph {
+template<typename T> using ref_t = boost::intrusive_ptr<T>;
+template<typename T> using cref_t = boost::intrusive_ptr<const T>;
+template<class T, class U>
+ref_t<T> ref_cast(const ref_t<U>& r) noexcept {
+ return static_cast<T*>(r.get());
+}
+template<class T, class U>
+ref_t<T> ref_cast(ref_t<U>&& r) noexcept {
+ return {static_cast<T*>(r.detach()), false};
+}
+template<class T, class U>
+cref_t<T> ref_cast(const cref_t<U>& r) noexcept {
+ return static_cast<const T*>(r.get());
+}
+template<class T, typename... Args>
+ceph::ref_t<T> make_ref(Args&&... args) {
+ return {new T(std::forward<Args>(args)...), false};
+}
+}
+
+// Friends cannot be partial specializations: https://en.cppreference.com/w/cpp/language/friend
+#define FRIEND_MAKE_REF(C) \
+template<class T, typename... Args> friend ceph::ref_t<T> ceph::make_ref(Args&&... args)
+
+#endif