cpp-common/bt2/field-path.hpp \
cpp-common/bt2/integer-range.hpp \
cpp-common/bt2/integer-range-set.hpp \
- cpp-common/bt2/internal/shared-obj.hpp \
cpp-common/bt2/internal/utils.hpp \
cpp-common/bt2/logging.hpp \
cpp-common/bt2/message.hpp \
+ cpp-common/bt2/shared-obj.hpp \
cpp-common/bt2/trace-ir.hpp \
cpp-common/bt2/type-traits.hpp \
cpp-common/bt2/value.hpp \
#include "borrowed-object.hpp"
#include "exc.hpp"
-#include "internal/shared-obj.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
#include "value.hpp"
namespace bt2 {
using _ThisCommonClockClass = CommonClockClass<LibObjT>;
public:
- using Shared =
- internal::SharedObj<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
+ using Shared = SharedObj<_ThisCommonClockClass, LibObjT, internal::ClockClassRefFuncs>;
using UserAttributes =
typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
#include "exc.hpp"
#include "field-path.hpp"
#include "integer-range-set.hpp"
-#include "internal/shared-obj.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
#include "value.hpp"
namespace bt2 {
}
};
-template <typename ObjT, typename LibObjT>
-using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
-
template <typename LibObjT>
struct CommonFieldClassSpec;
} /* namespace internal */
+template <typename ObjT, typename LibObjT>
+using SharedFieldClass = SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
+
template <typename LibObjT>
class CommonBitArrayFieldClass;
using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
using UserAttributes =
typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
public:
- using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
+ using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonIntegerFieldClass {libObjPtr}
using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
public:
- using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
+ using Shared = SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
using Mapping = MappingT;
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
public:
- using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
using Member =
typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
StructureFieldClassMember>::type;
using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonArrayFieldClass {libObjPtr}
using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared =
- internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonArrayFieldClass {libObjPtr}
using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonOptionFieldClass {libObjPtr}
LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
public:
- using Shared =
- internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonOptionWithSelectorFieldClass {libObjPtr}
CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
public:
- using Shared =
- internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
+ using Shared = SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
using RangeSet = RangeSetT;
using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
using Option =
typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared =
- internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
+ using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonVariantFieldClass {libObjPtr}
using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
+ using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonVariantFieldClass {libObjPtr}
using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
public:
- using Shared =
- internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
+ using Shared = SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
using Option = OptionT;
using Iterator =
#include "borrowed-object.hpp"
#include "common-iter.hpp"
-#include "internal/shared-obj.hpp"
+#include "shared-obj.hpp"
namespace bt2 {
class ConstFieldPath final : public BorrowedObject<const bt_field_path>
{
public:
- using Shared =
- internal::SharedObj<ConstFieldPath, const bt_field_path, internal::FieldPathRefFuncs>;
+ using Shared = SharedObj<ConstFieldPath, const bt_field_path, internal::FieldPathRefFuncs>;
using Iterator = CommonIterator<ConstFieldPath, ConstFieldPathItem>;
#include "exc.hpp"
#include "integer-range.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
namespace bt2 {
using _ThisCommonIntegerRangeSet = CommonIntegerRangeSet<LibObjT>;
public:
- using Shared = internal::SharedObj<_ThisCommonIntegerRangeSet, LibObjT, _RefFuncs>;
+ using Shared = SharedObj<_ThisCommonIntegerRangeSet, LibObjT, _RefFuncs>;
using Range = typename std::conditional<
std::is_same<_ConstLibObjT, const bt_integer_range_set_unsigned>::value,
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Philippe Proulx <pproulx@efficios.com>
- *
- * SPDX-License-Identifier: MIT
- */
-
-#ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_SHARED_OBJ_HPP
-#define BABELTRACE_CPP_COMMON_BT2_INTERNAL_SHARED_OBJ_HPP
-
-#include "common/assert.h"
-#include "cpp-common/optional.hpp"
-
-namespace bt2 {
-namespace internal {
-
-/*
- * An instance of this class wraps an optional instance of `ObjT` and
- * manages the reference counting of the underlying libbabeltrace2
- * object.
- *
- * When you move a shared object, it becomes invalid, in that
- * operator*() and operator->() will either fail to assert in debug mode
- * or trigger a segmentation fault.
- *
- * `LibObjT` is the direct libbabeltrace2 object type, for example
- * `bt_stream_class` or `const bt_value`.
- *
- * RefFuncsT::get() must accept a `const LibObjT *` value and increment
- * its reference count.
- *
- * RefFuncsT::put() must accept a `const LibObjT *` value and decrement
- * its reference count.
- */
-template <typename ObjT, typename LibObjT, typename RefFuncsT>
-class SharedObj final
-{
- /*
- * This makes it possible for a
- * `SharedObj<Something, bt_something, ...>` instance to get
- * assigned an instance of
- * `SharedObj<SpecificSomething, bt_something, ...>` (copy/move
- * constructors and assignment operators), given that
- * `SpecificSomething` inherits `Something`.
- */
- template <typename, typename, typename>
- friend class SharedObj;
-
-private:
- /*
- * Builds a shared object from `obj` without getting a reference.
- */
- explicit SharedObj(const ObjT& obj) noexcept : _mObj {obj}
- {
- }
-
- /*
- * Common generic "copy" constructor.
- *
- * This constructor is meant to be delegated to by the copy
- * constructor and the generic "copy" constructor.
- *
- * The second parameter, of type `int`, makes it possible to
- * delegate by deduction as you can't explicit the template
- * parameters when delegating to a constructor template.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other, int) noexcept :
- _mObj {other._mObj}
- {
- this->_getRef();
- }
-
- /*
- * Common generic "move" constructor.
- *
- * See the comment of the common generic "copy" constructor above.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other, int) noexcept :
- _mObj {other._mObj}
- {
- /* Reset moved-from object */
- other._reset();
- }
-
-public:
- /*
- * Builds a shared object from `obj` without getting a reference.
- */
- static SharedObj createWithoutRef(const ObjT& obj) noexcept
- {
- return SharedObj {obj};
- }
-
- /*
- * Builds a shared object from `libObjPtr` without getting a
- * reference.
- */
- static SharedObj createWithoutRef(LibObjT * const libObjPtr) noexcept
- {
- return SharedObj::createWithoutRef(ObjT {libObjPtr});
- }
-
- /*
- * Builds a shared object from `obj`, immediately getting a new
- * reference.
- */
- static SharedObj createWithRef(const ObjT& obj) noexcept
- {
- SharedObj sharedObj {obj};
-
- sharedObj._getRef();
- return sharedObj;
- }
-
- /*
- * Builds a shared object from `libObjPtr`, immediately getting a new
- * reference.
- */
- static SharedObj createWithRef(LibObjT * const libObjPtr) noexcept
- {
- return SharedObj::createWithRef(ObjT {libObjPtr});
- }
-
- /*
- * Copy constructor.
- */
- SharedObj(const SharedObj& other) noexcept : SharedObj {other, 0}
- {
- }
-
- /*
- * Move constructor.
- */
- SharedObj(SharedObj&& other) noexcept : SharedObj {std::move(other), 0}
- {
- }
-
- /*
- * Copy assignment operator.
- */
- SharedObj& operator=(const SharedObj& other) noexcept
- {
- /* Use generic "copy" assignment operator */
- return this->operator=<ObjT, LibObjT>(other);
- }
-
- /*
- * Move assignment operator.
- */
- SharedObj& operator=(SharedObj&& other) noexcept
- {
- /* Use generic "move" assignment operator */
- return this->operator=<ObjT, LibObjT>(std::move(other));
- }
-
- /*
- * Generic "copy" constructor.
- *
- * See the `friend class SharedObj` comment above.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept :
- SharedObj {other, 0}
- {
- }
-
- /*
- * Generic "move" constructor.
- *
- * See the `friend class SharedObj` comment above.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept :
- SharedObj {std::move(other), 0}
- {
- }
-
- /*
- * Generic "copy" assignment operator.
- *
- * See the `friend class SharedObj` comment above.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj& operator=(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept
- {
- /* Put current object's reference */
- this->_putRef();
-
- /* Set new current object and get a reference */
- _mObj = other._mObj;
- this->_getRef();
-
- return *this;
- }
-
- /*
- * Generic "move" assignment operator.
- *
- * See the `friend class SharedObj` comment above.
- */
- template <typename OtherObjT, typename OtherLibObjT>
- SharedObj& operator=(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept
- {
- /* Put current object's reference */
- this->_putRef();
-
- /* Set new current object */
- _mObj = other._mObj;
-
- /* Reset moved-from object */
- other._reset();
-
- return *this;
- }
-
- ~SharedObj()
- {
- this->_putRef();
- }
-
- ObjT& operator*() noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return *_mObj;
- }
-
- const ObjT& operator*() const noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return *_mObj;
- }
-
- ObjT *operator->() noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return &*_mObj;
- }
-
- const ObjT *operator->() const noexcept
- {
- BT_ASSERT_DBG(_mObj);
- return &*_mObj;
- }
-
- /*
- * Transfers the reference of the object which this shared object
- * wrapper manages and returns it, making the caller become an active
- * owner.
- *
- * This method makes this object invalid.
- */
- ObjT release() noexcept
- {
- BT_ASSERT_DBG(_mObj);
- const auto obj = *_mObj;
- this->_reset();
- return obj;
- }
-
-private:
- /*
- * Resets this shared object.
- *
- * To be used when moving it.
- */
- void _reset() noexcept
- {
- _mObj.reset();
- }
-
- /*
- * Gets a new reference using the configured libbabeltrace2
- * reference incrementation function.
- */
- void _getRef() const noexcept
- {
- if (_mObj) {
- RefFuncsT::get(_mObj->libObjPtr());
- }
- }
-
- /*
- * Puts a reference using the configured libbabeltrace2 reference
- * decrementation function.
- */
- void _putRef() const noexcept
- {
- if (_mObj) {
- RefFuncsT::put(_mObj->libObjPtr());
- }
- }
-
- nonstd::optional<ObjT> _mObj;
-};
-
-} /* namespace internal */
-} /* namespace bt2 */
-
-#endif /* BABELTRACE_CPP_COMMON_BT2_INTERNAL_SHARED_OBJ_HPP */
#include "cpp-common/optional.hpp"
#include "borrowed-object.hpp"
-#include "internal/shared-obj.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
namespace bt2 {
namespace internal {
}
};
-template <typename ObjT, typename LibObjT>
-using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
-
} /* namespace internal */
+template <typename ObjT, typename LibObjT>
+using SharedMessage = SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
+
template <typename LibObjT>
class CommonStreamBeginningMessage;
using _ThisCommonMessage = CommonMessage<LibObjT>;
public:
- using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
{
CommonStream<bt_stream>>::type;
public:
- using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonStream<bt_stream>>::type;
public:
- using Shared = internal::SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonPacket<bt_packet>>::type;
public:
- using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonPacket<bt_packet>>::type;
public:
- using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonEvent<bt_event>>::type;
public:
- using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonStream<bt_stream>>::type;
public:
- using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
CommonStream<bt_stream>>::type;
public:
- using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
using typename CommonMessage<LibObjT>::_ThisCommonMessage;
public:
- using Shared =
- internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
+ using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
_ThisCommonMessage {libObjPtr}
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_SHARED_OBJ_HPP
+#define BABELTRACE_CPP_COMMON_BT2_SHARED_OBJ_HPP
+
+#include "common/assert.h"
+#include "cpp-common/optional.hpp"
+
+namespace bt2 {
+
+/*
+ * An instance of this class wraps an optional instance of `ObjT` and
+ * manages the reference counting of the underlying libbabeltrace2
+ * object.
+ *
+ * When you move a shared object, it becomes invalid, in that
+ * operator*() and operator->() will either fail to assert in debug mode
+ * or trigger a segmentation fault.
+ *
+ * `LibObjT` is the direct libbabeltrace2 object type, for example
+ * `bt_stream_class` or `const bt_value`.
+ *
+ * RefFuncsT::get() must accept a `const LibObjT *` value and increment
+ * its reference count.
+ *
+ * RefFuncsT::put() must accept a `const LibObjT *` value and decrement
+ * its reference count.
+ */
+template <typename ObjT, typename LibObjT, typename RefFuncsT>
+class SharedObj final
+{
+ /*
+ * This makes it possible for a
+ * `SharedObj<Something, bt_something, ...>` instance to get
+ * assigned an instance of
+ * `SharedObj<SpecificSomething, bt_something, ...>` (copy/move
+ * constructors and assignment operators), given that
+ * `SpecificSomething` inherits `Something`.
+ */
+ template <typename, typename, typename>
+ friend class SharedObj;
+
+private:
+ /*
+ * Builds a shared object from `obj` without getting a reference.
+ */
+ explicit SharedObj(const ObjT& obj) noexcept : _mObj {obj}
+ {
+ }
+
+ /*
+ * Common generic "copy" constructor.
+ *
+ * This constructor is meant to be delegated to by the copy
+ * constructor and the generic "copy" constructor.
+ *
+ * The second parameter, of type `int`, makes it possible to
+ * delegate by deduction as you can't explicit the template
+ * parameters when delegating to a constructor template.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other, int) noexcept :
+ _mObj {other._mObj}
+ {
+ this->_getRef();
+ }
+
+ /*
+ * Common generic "move" constructor.
+ *
+ * See the comment of the common generic "copy" constructor above.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other, int) noexcept :
+ _mObj {other._mObj}
+ {
+ /* Reset moved-from object */
+ other._reset();
+ }
+
+public:
+ /*
+ * Builds a shared object from `obj` without getting a reference.
+ */
+ static SharedObj createWithoutRef(const ObjT& obj) noexcept
+ {
+ return SharedObj {obj};
+ }
+
+ /*
+ * Builds a shared object from `libObjPtr` without getting a
+ * reference.
+ */
+ static SharedObj createWithoutRef(LibObjT * const libObjPtr) noexcept
+ {
+ return SharedObj::createWithoutRef(ObjT {libObjPtr});
+ }
+
+ /*
+ * Builds a shared object from `obj`, immediately getting a new
+ * reference.
+ */
+ static SharedObj createWithRef(const ObjT& obj) noexcept
+ {
+ SharedObj sharedObj {obj};
+
+ sharedObj._getRef();
+ return sharedObj;
+ }
+
+ /*
+ * Builds a shared object from `libObjPtr`, immediately getting a new
+ * reference.
+ */
+ static SharedObj createWithRef(LibObjT * const libObjPtr) noexcept
+ {
+ return SharedObj::createWithRef(ObjT {libObjPtr});
+ }
+
+ /*
+ * Copy constructor.
+ */
+ SharedObj(const SharedObj& other) noexcept : SharedObj {other, 0}
+ {
+ }
+
+ /*
+ * Move constructor.
+ */
+ SharedObj(SharedObj&& other) noexcept : SharedObj {std::move(other), 0}
+ {
+ }
+
+ /*
+ * Copy assignment operator.
+ */
+ SharedObj& operator=(const SharedObj& other) noexcept
+ {
+ /* Use generic "copy" assignment operator */
+ return this->operator=<ObjT, LibObjT>(other);
+ }
+
+ /*
+ * Move assignment operator.
+ */
+ SharedObj& operator=(SharedObj&& other) noexcept
+ {
+ /* Use generic "move" assignment operator */
+ return this->operator=<ObjT, LibObjT>(std::move(other));
+ }
+
+ /*
+ * Generic "copy" constructor.
+ *
+ * See the `friend class SharedObj` comment above.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept :
+ SharedObj {other, 0}
+ {
+ }
+
+ /*
+ * Generic "move" constructor.
+ *
+ * See the `friend class SharedObj` comment above.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept :
+ SharedObj {std::move(other), 0}
+ {
+ }
+
+ /*
+ * Generic "copy" assignment operator.
+ *
+ * See the `friend class SharedObj` comment above.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj& operator=(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept
+ {
+ /* Put current object's reference */
+ this->_putRef();
+
+ /* Set new current object and get a reference */
+ _mObj = other._mObj;
+ this->_getRef();
+
+ return *this;
+ }
+
+ /*
+ * Generic "move" assignment operator.
+ *
+ * See the `friend class SharedObj` comment above.
+ */
+ template <typename OtherObjT, typename OtherLibObjT>
+ SharedObj& operator=(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept
+ {
+ /* Put current object's reference */
+ this->_putRef();
+
+ /* Set new current object */
+ _mObj = other._mObj;
+
+ /* Reset moved-from object */
+ other._reset();
+
+ return *this;
+ }
+
+ ~SharedObj()
+ {
+ this->_putRef();
+ }
+
+ ObjT& operator*() noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ return *_mObj;
+ }
+
+ const ObjT& operator*() const noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ return *_mObj;
+ }
+
+ ObjT *operator->() noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ return &*_mObj;
+ }
+
+ const ObjT *operator->() const noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ return &*_mObj;
+ }
+
+ /*
+ * Transfers the reference of the object which this shared object
+ * wrapper manages and returns it, making the caller become an active
+ * owner.
+ *
+ * This method makes this object invalid.
+ */
+ ObjT release() noexcept
+ {
+ BT_ASSERT_DBG(_mObj);
+ const auto obj = *_mObj;
+ this->_reset();
+ return obj;
+ }
+
+private:
+ /*
+ * Resets this shared object.
+ *
+ * To be used when moving it.
+ */
+ void _reset() noexcept
+ {
+ _mObj.reset();
+ }
+
+ /*
+ * Gets a new reference using the configured libbabeltrace2
+ * reference incrementation function.
+ */
+ void _getRef() const noexcept
+ {
+ if (_mObj) {
+ RefFuncsT::get(_mObj->libObjPtr());
+ }
+ }
+
+ /*
+ * Puts a reference using the configured libbabeltrace2 reference
+ * decrementation function.
+ */
+ void _putRef() const noexcept
+ {
+ if (_mObj) {
+ RefFuncsT::put(_mObj->libObjPtr());
+ }
+ }
+
+ nonstd::optional<ObjT> _mObj;
+};
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_SHARED_OBJ_HPP */
#include "field-class.hpp"
#include "field.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
#include "value.hpp"
namespace bt2 {
ConstStructureField, StructureField>::type;
public:
- using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
+ using Shared = SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
{
CommonTrace<bt_trace>>::type;
public:
- using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
+ using Shared = SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
using Class = typename std::conditional<std::is_const<LibObjT>::value,
CommonStreamClass<const bt_stream_class>,
CommonStream<bt_stream>>::type;
public:
- using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
+ using Shared = SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
using Class = typename std::conditional<std::is_const<LibObjT>::value,
CommonTraceClass<const bt_trace_class>,
StructureFieldClass>::type;
public:
- using Shared =
- internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
+ using Shared = SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
using UserAttributes =
typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
public:
- using Shared =
- internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
+ using Shared = SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
using UserAttributes =
typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
CommonStreamClass<bt_stream_class>>::type;
public:
- using Shared =
- internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
+ using Shared = SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
using UserAttributes =
typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
#include "borrowed-object.hpp"
#include "common-iter.hpp"
#include "exc.hpp"
-#include "internal/shared-obj.hpp"
#include "internal/utils.hpp"
+#include "shared-obj.hpp"
namespace bt2 {
namespace internal {
}
};
-template <typename ObjT, typename LibObjT>
-using SharedValue = internal::SharedObj<ObjT, LibObjT, internal::ValueRefFuncs>;
-
} /* namespace internal */
+template <typename ObjT, typename LibObjT>
+using SharedValue = SharedObj<ObjT, LibObjT, internal::ValueRefFuncs>;
+
template <typename LibObjT>
class CommonNullValue;
using _ThisCommonValue = CommonValue<LibObjT>;
public:
- using Shared = internal::SharedValue<CommonValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonValue<LibObjT>, LibObjT>;
explicit CommonValue(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
{
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonNullValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonNullValue<LibObjT>, LibObjT>;
CommonNullValue() noexcept : _ThisCommonValue {bt_value_null}
{
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonBoolValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonBoolValue<LibObjT>, LibObjT>;
using Value = bool;
explicit CommonBoolValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonUnsignedIntegerValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonUnsignedIntegerValue<LibObjT>, LibObjT>;
using Value = std::uint64_t;
explicit CommonUnsignedIntegerValue(const _LibObjPtr libObjPtr) noexcept :
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonSignedIntegerValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonSignedIntegerValue<LibObjT>, LibObjT>;
using Value = std::int64_t;
explicit CommonSignedIntegerValue(const _LibObjPtr libObjPtr) noexcept :
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonRealValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonRealValue<LibObjT>, LibObjT>;
using Value = double;
explicit CommonRealValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonStringValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonStringValue<LibObjT>, LibObjT>;
explicit CommonStringValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
{
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonArrayValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonArrayValue<LibObjT>, LibObjT>;
using Iterator = CommonIterator<CommonArrayValue<LibObjT>, CommonValue<LibObjT>>;
explicit CommonArrayValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
using typename CommonValue<LibObjT>::_ThisCommonValue;
public:
- using Shared = internal::SharedValue<CommonMapValue<LibObjT>, LibObjT>;
+ using Shared = SharedValue<CommonMapValue<LibObjT>, LibObjT>;
explicit CommonMapValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
{