cpp-common/bt2: `bt2::internal::BorrowedObj` -> `bt2::BorrowedObj`
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 11 Dec 2023 20:03:04 +0000 (15:03 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 15:57:04 +0000 (10:57 -0500)
`BorrowedObj` is not completely internal: it has public methods which
any concrete borrowed object inherits.

Also, we don't need to hide anything from the end user in this file.

Therefore make this base class not internal.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib3a396a1aa7794608a4ec938f9b141c553e36c97
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11365
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
13 files changed:
src/Makefile.am
src/cpp-common/bt2/borrowed-obj.hpp [new file with mode: 0644]
src/cpp-common/bt2/clock-class.hpp
src/cpp-common/bt2/clock-snapshot.hpp
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field-path.hpp
src/cpp-common/bt2/field.hpp
src/cpp-common/bt2/integer-range-set.hpp
src/cpp-common/bt2/integer-range.hpp
src/cpp-common/bt2/internal/borrowed-obj.hpp [deleted file]
src/cpp-common/bt2/message.hpp
src/cpp-common/bt2/trace-ir.hpp
src/cpp-common/bt2/value.hpp

index 98b89b3309782d13a27715dbab94fe5e681d5523..fc890bb36a595b8f39a3f34465a6a35c8efeb04b 100644 (file)
@@ -12,6 +12,7 @@ SUBDIRS += bindings/python/bt2
 endif
 
 noinst_HEADERS = \
+       cpp-common/bt2/borrowed-obj.hpp \
        cpp-common/bt2/clock-class.hpp \
        cpp-common/bt2/clock-snapshot.hpp \
        cpp-common/bt2/common-iter.hpp \
@@ -21,7 +22,6 @@ noinst_HEADERS = \
        cpp-common/bt2/field-path.hpp \
        cpp-common/bt2/integer-range.hpp \
        cpp-common/bt2/integer-range-set.hpp \
-       cpp-common/bt2/internal/borrowed-obj.hpp \
        cpp-common/bt2/internal/shared-obj.hpp \
        cpp-common/bt2/internal/utils.hpp \
        cpp-common/bt2/logging.hpp \
diff --git a/src/cpp-common/bt2/borrowed-obj.hpp b/src/cpp-common/bt2/borrowed-obj.hpp
new file mode 100644 (file)
index 0000000..b006670
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2019-2020 (c) Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJ_HPP
+#define BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJ_HPP
+
+#include <functional>
+#include <type_traits>
+
+#include "common/assert.h"
+
+namespace bt2 {
+
+/*
+ * An instance of this class wraps a pointer to a libbabeltrace2 object
+ * of type `LibObjT` without managing any reference counting.
+ *
+ * This is an abstract base class for any libbabeltrace2 object wrapper.
+ *
+ * `LibObjT` is the direct libbabeltrace2 object type, for example
+ * `bt_stream_class` or `const bt_value`.
+ *
+ * Methods of a derived class can call libObjPtr() to access the
+ * libbabeltrace2 object pointer.
+ */
+template <typename LibObjT>
+class BorrowedObj
+{
+    static_assert(!std::is_pointer<LibObjT>::value, "`LibObjT` must not be a pointer");
+
+    /*
+     * This makes it possible for a `BorrowedObj<const bt_something>`
+     * instance to get assigned an instance of
+     * `BorrowedObj<bt_something>` ("copy" constructor and "assignment"
+     * operator).
+     *
+     * C++ forbids the other way around.
+     */
+    template <typename>
+    friend class BorrowedObj;
+
+private:
+    /*
+     * Provides `val` which indicates whether or not you can assign this
+     * object from a borrowed object of type `OtherLibObjT`.
+     */
+    template <typename OtherLibObjT>
+    struct _AssignableFromConst final
+    {
+        /*
+         * If `LibObjT` is const (for example, `const bt_value`), then
+         * you may always assign from its non-const equivalent (for
+         * example, `bt_value`). In C (correct):
+         *
+         *     bt_value * const meow = bt_value_bool_create_init(BT_TRUE);
+         *     const bt_value * const mix = meow;
+         *
+         * If `LibObjT` is non-const, then you may not assign from its
+         * const equivalent. In C (not correct):
+         *
+         *     const bt_value * const meow =
+         *         bt_value_array_borrow_element_by_index_const(some_val, 17);
+         *     bt_value * const mix = meow;
+         */
+        static constexpr bool val =
+            std::is_const<LibObjT>::value || !std::is_const<OtherLibObjT>::value;
+    };
+
+protected:
+    /* libbabeltrace2 object pointer */
+    using _LibObjPtr = LibObjT *;
+
+    /* This complete borrowed object */
+    using _ThisBorrowedObj = BorrowedObj<LibObjT>;
+
+    /*
+     * Builds a borrowed object to wrap the libbabeltrace2 object
+     * pointer `libObjPtr`.
+     *
+     * `libObjPtr` must not be `nullptr`.
+     */
+    explicit BorrowedObj(const _LibObjPtr libObjPtr) noexcept : _mLibObjPtr {libObjPtr}
+    {
+        BT_ASSERT(libObjPtr);
+    }
+
+    /* Default copy operations */
+    BorrowedObj(const BorrowedObj&) noexcept = default;
+    BorrowedObj& operator=(const BorrowedObj&) noexcept = default;
+
+    /*
+     * Generic "copy" constructor.
+     *
+     * This converting constructor accepts both an instance of
+     * `_ThisBorrowedObj` and an instance (`other`) of
+     * `BorrowedObj<ConstLibObjT>`, where `ConstLibObjT` is the `const`
+     * version of `LibObjT`, if applicable.
+     *
+     * This makes it possible for a `BorrowedObj<const bt_something>`
+     * instance to be built from an instance of
+     * `BorrowedObj<bt_something>`. C++ forbids the other way around.
+     */
+    template <typename OtherLibObjT>
+    BorrowedObj(const BorrowedObj<OtherLibObjT>& other) noexcept : BorrowedObj {other._mLibObjPtr}
+    {
+        static_assert(_AssignableFromConst<OtherLibObjT>::val,
+                      "Don't assign a non-const wrapper from a const wrapper.");
+    }
+
+    /*
+     * Generic "assignment" operator.
+     *
+     * This operator accepts both an instance of
+     * `_ThisBorrowedObj` and an instance (`other`) of
+     * `BorrowedObj<ConstLibObjT>`, where `ConstLibObjT` is the `const`
+     * version of `LibObjT`, if applicable.
+     *
+     * This makes it possible for a `BorrowedObj<const bt_something>`
+     * instance to get assigned an instance of
+     * `BorrowedObj<bt_something>`. C++ forbids the other way around,
+     * therefore we use `_EnableIfAssignableT` to show a more relevant
+     * context in the compiler error message.
+     */
+    template <typename OtherLibObjT>
+    _ThisBorrowedObj& operator=(const BorrowedObj<OtherLibObjT>& other) noexcept
+    {
+        static_assert(_AssignableFromConst<OtherLibObjT>::val,
+                      "Don't assign a non-const wrapper from a const wrapper.");
+
+        _mLibObjPtr = other._mLibObjPtr;
+        return *this;
+    }
+
+public:
+    /*
+     * Returns a hash of this object, solely based on its raw libbabeltrace2
+     * pointer.
+     */
+    std::size_t hash() const noexcept
+    {
+        return std::hash<_LibObjPtr> {}(_mLibObjPtr);
+    }
+
+    /*
+     * Returns whether or not this object is the exact same as `other`,
+     * solely based on the raw libbabeltrace2 pointers.
+     */
+    bool isSame(const _ThisBorrowedObj& other) const noexcept
+    {
+        return _mLibObjPtr == other._mLibObjPtr;
+    }
+
+    /* Wrapped libbabeltrace2 object pointer */
+    _LibObjPtr libObjPtr() const noexcept
+    {
+        return _mLibObjPtr;
+    }
+
+private:
+    _LibObjPtr _mLibObjPtr;
+};
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_BORROWED_OBJ_HPP */
index b236764510e437808965aab6b8f9b4cee1f989cb..c713ca26c83b534c5e6fdb2fec4ba33262063ed2 100644 (file)
@@ -17,8 +17,8 @@
 #include "cpp-common/string_view.hpp"
 #include "cpp-common/uuid-view.hpp"
 
+#include "borrowed-obj.hpp"
 #include "exc.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 #include "internal/utils.hpp"
 #include "value.hpp"
@@ -92,11 +92,11 @@ private:
 };
 
 template <typename LibObjT>
-class CommonClockClass final : public internal::BorrowedObj<LibObjT>
+class CommonClockClass final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisCommonClockClass = CommonClockClass<LibObjT>;
 
 public:
index 364400b6ff809e54b300c4f2f0f7748b5f63f91b..acd399b1eebd08ff8b04afbcc1cb62d72d1a418d 100644 (file)
 
 #include <babeltrace2/babeltrace.h>
 
+#include "borrowed-obj.hpp"
 #include "exc.hpp"
-#include "internal/borrowed-obj.hpp"
 
 namespace bt2 {
 
-class ConstClockSnapshot final : public internal::BorrowedObj<const bt_clock_snapshot>
+class ConstClockSnapshot final : public BorrowedObj<const bt_clock_snapshot>
 {
 public:
     explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
index 165cfde32d35dad38eb7806ea58ae40ba59d1425..a8bbb3c462c5f8193810d0496e5d5c5bbd1a6d28 100644 (file)
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 
+#include "borrowed-obj.hpp"
 #include "common-iter.hpp"
 #include "exc.hpp"
 #include "field-path.hpp"
 #include "integer-range-set.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 #include "internal/utils.hpp"
 #include "value.hpp"
@@ -161,7 +161,7 @@ enum class FieldClassType
 };
 
 template <typename LibObjT>
-class CommonFieldClass : public internal::BorrowedObj<LibObjT>
+class CommonFieldClass : public BorrowedObj<LibObjT>
 {
     /* Allow appendMember() to call `fc.libObjPtr()` */
     friend class CommonStructureFieldClass<bt_field_class>;
@@ -187,10 +187,10 @@ class CommonFieldClass : public internal::BorrowedObj<LibObjT>
     friend class CommonTraceClass<bt_trace_class>;
 
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
 
 protected:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
 
 public:
@@ -679,11 +679,11 @@ struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_si
 } /* namespace internal */
 
 template <typename LibObjT>
-class ConstEnumerationFieldClassMapping final : public internal::BorrowedObj<LibObjT>
+class ConstEnumerationFieldClassMapping final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
 
 public:
     using RangeSet = typename std::conditional<
@@ -1000,11 +1000,11 @@ struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStructureFieldClassMember final : public internal::BorrowedObj<LibObjT>
+class CommonStructureFieldClassMember final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
 
     using _FieldClass =
         typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
@@ -1925,11 +1925,11 @@ struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> fi
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonVariantFieldClassOption : public internal::BorrowedObj<LibObjT>
+class CommonVariantFieldClassOption : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
 
     using _FieldClass =
         typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
@@ -2076,11 +2076,11 @@ struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
 } /* namespace internal */
 
 template <typename LibObjT>
-class ConstVariantWithIntegerSelectorFieldClassOption : public internal::BorrowedObj<LibObjT>
+class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
 
 public:
index 0a68927cf9dfc2e56fa82b1557b0907777a3cacf..aac6ffd16ca48113debb2429e55c2f75cc46b741 100644 (file)
@@ -13,8 +13,8 @@
 
 #include "common/assert.h"
 
+#include "borrowed-obj.hpp"
 #include "common-iter.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 
 namespace bt2 {
@@ -28,7 +28,7 @@ enum class FieldPathItemType
     CURRENT_OPTION_CONTENT = BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT,
 };
 
-class ConstFieldPathItem : public internal::BorrowedObj<const bt_field_path_item>
+class ConstFieldPathItem : public BorrowedObj<const bt_field_path_item>
 {
 public:
     explicit ConstFieldPathItem(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
@@ -123,7 +123,7 @@ struct FieldPathRefFuncs final
 
 } /* namespace internal */
 
-class ConstFieldPath final : public internal::BorrowedObj<const bt_field_path>
+class ConstFieldPath final : public BorrowedObj<const bt_field_path>
 {
 public:
     using Shared =
index 5a3fdfd93ea106b82436dde1d97b8ef6f11bdeb1..61cdd60a2b894bd8ba3c965405d44f96a5ebad3f 100644 (file)
@@ -16,8 +16,8 @@
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 
+#include "borrowed-obj.hpp"
 #include "field-class.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
 
 namespace bt2 {
@@ -92,13 +92,13 @@ struct CommonFieldSpec<const bt_field> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonField : public internal::BorrowedObj<LibObjT>
+class CommonField : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
 
 protected:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisCommonField = CommonField<LibObjT>;
 
 public:
index a86bcaf9dc872b307bd79803619587bcbfe038ec..1ad8f4c180be7e0c02c98247b349dd4ce9f3506c 100644 (file)
 
 #include <babeltrace2/babeltrace.h>
 
+#include "borrowed-obj.hpp"
 #include "common-iter.hpp"
 #include "exc.hpp"
 #include "integer-range.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
 
 namespace bt2 {
@@ -141,7 +141,7 @@ template <typename LibObjT>
 class CommonTraceClass;
 
 template <typename LibObjT>
-class CommonIntegerRangeSet final : public internal::BorrowedObj<LibObjT>
+class CommonIntegerRangeSet final : public BorrowedObj<LibObjT>
 {
     /* Allow operator==() to call `other.libObjPtr()` */
     friend class CommonIntegerRangeSet<bt_integer_range_set_unsigned>;
@@ -164,8 +164,8 @@ class CommonIntegerRangeSet final : public internal::BorrowedObj<LibObjT>
     friend class CommonTraceClass<bt_trace_class>;
 
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstLibObjT = typename std::add_const<LibObjT>::type;
     using _RefFuncs = internal::IntegerRangeSetRefFuncs<_ConstLibObjT>;
     using _Spec = internal::CommonIntegerRangeSetSpec<_ConstLibObjT>;
index 125707187fc5c390ec05c899da2c322eaaf6ac1a..03ba0b600737513e118b01fa7121dc1ae602da2c 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <babeltrace2/babeltrace.h>
 
-#include "internal/borrowed-obj.hpp"
+#include "borrowed-obj.hpp"
 
 namespace bt2 {
 
@@ -66,11 +66,11 @@ struct ConstIntegerRangeSpec<const bt_integer_range_signed> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class ConstIntegerRange final : public internal::BorrowedObj<LibObjT>
+class ConstIntegerRange final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisConstIntegerRange = ConstIntegerRange<LibObjT>;
 
 public:
diff --git a/src/cpp-common/bt2/internal/borrowed-obj.hpp b/src/cpp-common/bt2/internal/borrowed-obj.hpp
deleted file mode 100644 (file)
index 5d3ab64..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright 2019-2020 (c) Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_BORROWED_OBJ_HPP
-#define BABELTRACE_CPP_COMMON_BT2_INTERNAL_BORROWED_OBJ_HPP
-
-#include <functional>
-#include <type_traits>
-
-#include "common/assert.h"
-
-namespace bt2 {
-namespace internal {
-
-/*
- * An instance of this class wraps a pointer to a libbabeltrace2 object
- * of type `LibObjT` without managing any reference counting.
- *
- * This is an abstract base class for any libbabeltrace2 object wrapper.
- *
- * `LibObjT` is the direct libbabeltrace2 object type, for example
- * `bt_stream_class` or `const bt_value`.
- *
- * Methods of a derived class can call libObjPtr() to access the
- * libbabeltrace2 object pointer.
- */
-template <typename LibObjT>
-class BorrowedObj
-{
-    static_assert(!std::is_pointer<LibObjT>::value, "`LibObjT` must not be a pointer");
-
-    /*
-     * This makes it possible for a `BorrowedObj<const bt_something>`
-     * instance to get assigned an instance of
-     * `BorrowedObj<bt_something>` ("copy" constructor and "assignment"
-     * operator).
-     *
-     * C++ forbids the other way around.
-     */
-    template <typename>
-    friend class BorrowedObj;
-
-private:
-    /*
-     * Provides `val` which indicates whether or not you can assign this
-     * object from a borrowed object of type `OtherLibObjT`.
-     */
-    template <typename OtherLibObjT>
-    struct _AssignableFromConst final
-    {
-        /*
-         * If `LibObjT` is const (for example, `const bt_value`), then
-         * you may always assign from its non-const equivalent (for
-         * example, `bt_value`). In C (correct):
-         *
-         *     bt_value * const meow = bt_value_bool_create_init(BT_TRUE);
-         *     const bt_value * const mix = meow;
-         *
-         * If `LibObjT` is non-const, then you may not assign from its
-         * const equivalent. In C (not correct):
-         *
-         *     const bt_value * const meow =
-         *         bt_value_array_borrow_element_by_index_const(some_val, 17);
-         *     bt_value * const mix = meow;
-         */
-        static constexpr bool val =
-            std::is_const<LibObjT>::value || !std::is_const<OtherLibObjT>::value;
-    };
-
-protected:
-    /* libbabeltrace2 object pointer */
-    using _LibObjPtr = LibObjT *;
-
-    /* This complete borrowed object */
-    using _ThisBorrowedObj = BorrowedObj<LibObjT>;
-
-    /*
-     * Builds a borrowed object to wrap the libbabeltrace2 object
-     * pointer `libObjPtr`.
-     *
-     * `libObjPtr` must not be `nullptr`.
-     */
-    explicit BorrowedObj(const _LibObjPtr libObjPtr) noexcept : _mLibObjPtr {libObjPtr}
-    {
-        BT_ASSERT(libObjPtr);
-    }
-
-    /* Default copy operations */
-    BorrowedObj(const BorrowedObj&) noexcept = default;
-    BorrowedObj& operator=(const BorrowedObj&) noexcept = default;
-
-    /*
-     * Generic "copy" constructor.
-     *
-     * This converting constructor accepts both an instance of
-     * `_ThisBorrowedObj` and an instance (`other`) of
-     * `BorrowedObj<ConstLibObjT>`, where `ConstLibObjT` is the `const`
-     * version of `LibObjT`, if applicable.
-     *
-     * This makes it possible for a `BorrowedObj<const bt_something>`
-     * instance to be built from an instance of
-     * `BorrowedObj<bt_something>`. C++ forbids the other way around.
-     */
-    template <typename OtherLibObjT>
-    BorrowedObj(const BorrowedObj<OtherLibObjT>& other) noexcept : BorrowedObj {other._mLibObjPtr}
-    {
-        static_assert(_AssignableFromConst<OtherLibObjT>::val,
-                      "Don't assign a non-const wrapper from a const wrapper.");
-    }
-
-    /*
-     * Generic "assignment" operator.
-     *
-     * This operator accepts both an instance of
-     * `_ThisBorrowedObj` and an instance (`other`) of
-     * `BorrowedObj<ConstLibObjT>`, where `ConstLibObjT` is the `const`
-     * version of `LibObjT`, if applicable.
-     *
-     * This makes it possible for a `BorrowedObj<const bt_something>`
-     * instance to get assigned an instance of
-     * `BorrowedObj<bt_something>`. C++ forbids the other way around,
-     * therefore we use `_EnableIfAssignableT` to show a more relevant
-     * context in the compiler error message.
-     */
-    template <typename OtherLibObjT>
-    _ThisBorrowedObj& operator=(const BorrowedObj<OtherLibObjT>& other) noexcept
-    {
-        static_assert(_AssignableFromConst<OtherLibObjT>::val,
-                      "Don't assign a non-const wrapper from a const wrapper.");
-
-        _mLibObjPtr = other._mLibObjPtr;
-        return *this;
-    }
-
-public:
-    /*
-     * Returns a hash of this object, solely based on its raw libbabeltrace2
-     * pointer.
-     */
-    std::size_t hash() const noexcept
-    {
-        return std::hash<_LibObjPtr> {}(_mLibObjPtr);
-    }
-
-    /*
-     * Returns whether or not this object is the exact same as `other`,
-     * solely based on the raw libbabeltrace2 pointers.
-     */
-    bool isSame(const _ThisBorrowedObj& other) const noexcept
-    {
-        return _mLibObjPtr == other._mLibObjPtr;
-    }
-
-    /* Wrapped libbabeltrace2 object pointer */
-    _LibObjPtr libObjPtr() const noexcept
-    {
-        return _mLibObjPtr;
-    }
-
-private:
-    _LibObjPtr _mLibObjPtr;
-};
-
-} /* namespace internal */
-} /* namespace bt2 */
-
-#endif /* BABELTRACE_CPP_COMMON_BT2_INTERNAL_BORROWED_OBJ_HPP */
index fe476dc6dd7081fb935971a652a8e9ed6bbe6d80..eb1980a5ab6e1d5d304c624002b687b11e45297c 100644 (file)
@@ -17,7 +17,7 @@
 #include "cpp-common/bt2/trace-ir.hpp"
 #include "cpp-common/optional.hpp"
 
-#include "internal/borrowed-obj.hpp"
+#include "borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 #include "internal/utils.hpp"
 
@@ -79,13 +79,13 @@ enum class MessageType
 };
 
 template <typename LibObjT>
-class CommonMessage : public internal::BorrowedObj<LibObjT>
+class CommonMessage : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
 
 protected:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisCommonMessage = CommonMessage<LibObjT>;
 
 public:
index f27a87aee01e7b11ddc1bafd1d4c4b6090c38e2b..3a936782d79580f5733523e46fd92c21c3698f33 100644 (file)
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 
+#include "borrowed-obj.hpp"
 #include "clock-class.hpp"
 #include "field-class.hpp"
 #include "field.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
 #include "value.hpp"
 
@@ -123,11 +123,11 @@ struct CommonEventSpec<const bt_event> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonEvent final : public internal::BorrowedObj<LibObjT>
+class CommonEvent final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonEventSpec<const bt_event>;
     using _Spec = internal::CommonEventSpec<LibObjT>;
 
@@ -307,11 +307,11 @@ struct CommonPacketSpec<const bt_packet> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonPacket final : public internal::BorrowedObj<LibObjT>
+class CommonPacket final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
     using _Spec = internal::CommonPacketSpec<LibObjT>;
     using _ThisCommonPacket = CommonPacket<LibObjT>;
@@ -481,11 +481,11 @@ struct CommonStreamSpec<const bt_stream> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStream final : public internal::BorrowedObj<LibObjT>
+class CommonStream final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
     using _Spec = internal::CommonStreamSpec<LibObjT>;
     using _ThisCommonStream = CommonStream<LibObjT>;
@@ -711,14 +711,14 @@ struct CommonTraceSpec<const bt_trace> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonTrace final : public internal::BorrowedObj<LibObjT>
+class CommonTrace final : public BorrowedObj<LibObjT>
 {
     /* Allow instantiate() to call `trace.libObjPtr()` */
     friend class CommonStreamClass<bt_stream_class>;
 
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
     using _Spec = internal::CommonTraceSpec<LibObjT>;
     using _ThisCommonTrace = CommonTrace<LibObjT>;
@@ -1047,11 +1047,11 @@ struct CommonEventClassSpec<const bt_event_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonEventClass final : public internal::BorrowedObj<LibObjT>
+class CommonEventClass final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
     using _Spec = internal::CommonEventClassSpec<LibObjT>;
     using _ThisCommonEventClass = CommonEventClass<LibObjT>;
@@ -1423,11 +1423,11 @@ struct CommonStreamClassSpec<const bt_stream_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
+class CommonStreamClass final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
     using _Spec = internal::CommonStreamClassSpec<LibObjT>;
     using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
@@ -1916,11 +1916,11 @@ struct CommonTraceClassSpec<const bt_trace_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
+class CommonTraceClass final : public BorrowedObj<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
     using _Spec = internal::CommonTraceClassSpec<LibObjT>;
     using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
index 0dfe9dc614d42b8598b80365089700a3958d2ddf..9f30b74b35253255b902350411bc97ca4745ff6e 100644 (file)
@@ -18,9 +18,9 @@
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 
+#include "borrowed-obj.hpp"
 #include "common-iter.hpp"
 #include "exc.hpp"
-#include "internal/borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 #include "internal/utils.hpp"
 
@@ -100,7 +100,7 @@ template <typename LibObjT>
 class CommonStream;
 
 template <typename LibObjT>
-class CommonValue : public internal::BorrowedObj<LibObjT>
+class CommonValue : public BorrowedObj<LibObjT>
 {
     /* Allow append() to call `val.libObjPtr()` */
     friend class CommonArrayValue<bt_value>;
@@ -121,10 +121,10 @@ class CommonValue : public internal::BorrowedObj<LibObjT>
     friend class CommonValue<const bt_value>;
 
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
 
 protected:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObj<LibObjT>::_LibObjPtr;
     using _ThisCommonValue = CommonValue<LibObjT>;
 
 public:
This page took 0.03727 seconds and 4 git commands to generate.