X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fself-component-port.hpp;h=e1ab809859461f618510b9e9526ee2637e057aee;hb=2a24eba8b45ab4bd62dfb2cd95f31e4c2a7a91a8;hp=2551064ecbd1cdcbf17e53abc95343ac2229ac4f;hpb=421aa72924715ca75a53861eae3a453eade299a1;p=babeltrace.git diff --git a/src/cpp-common/bt2/self-component-port.hpp b/src/cpp-common/bt2/self-component-port.hpp index 2551064e..e1ab8098 100644 --- a/src/cpp-common/bt2/self-component-port.hpp +++ b/src/cpp-common/bt2/self-component-port.hpp @@ -13,7 +13,6 @@ #include "logging.hpp" -#include "common/assert.h" #include "cpp-common/bt2c/c-string-view.hpp" #include "borrowed-object-iterator.hpp" @@ -100,9 +99,11 @@ public: } template - void data(T& obj) const noexcept + SelfComponent data(T& obj) const noexcept { - bt_self_component_set_data(this->libObjPtr(), static_cast(&obj)); + bt_self_component_set_data(this->libObjPtr(), + const_cast(static_cast(&obj))); + return *this; } bt2::TraceClass::Shared createTraceClass() const @@ -128,6 +129,8 @@ public: } }; +namespace internal { + template class SelfSpecificComponent : public BorrowedObject { @@ -148,7 +151,8 @@ protected: { LibPortT *libPortPtr; - const auto status = func(this->libObjPtr(), name, static_cast(data), &libPortPtr); + const auto status = func(this->libObjPtr(), name, + const_cast(static_cast(data)), &libPortPtr); switch (status) { case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK: @@ -184,21 +188,13 @@ public: return this->_selfComponent().template data(); } - template - void data(T& obj) const noexcept - { - this->_selfComponent().data(obj); - } - -private: +protected: SelfComponent _selfComponent() const noexcept { return SelfComponent {this->libObjPtr()}; } }; -namespace internal { - template struct SelfComponentPortsSpec; @@ -325,8 +321,10 @@ public: Port back() const noexcept; }; -class SelfSourceComponent final : public SelfSpecificComponent +class SelfSourceComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using OutputPorts = SelfComponentPorts; @@ -342,6 +340,15 @@ public: bt_self_component_source_as_component_source(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfSourceComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + template OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const; @@ -354,8 +361,10 @@ private: OutputPorts::Port _addOutputPort(const char *name, DataT *data) const; }; -class SelfFilterComponent final : public SelfSpecificComponent +class SelfFilterComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using InputPorts = SelfComponentPorts; @@ -373,6 +382,15 @@ public: bt_self_component_filter_as_component_filter(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfFilterComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + template InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const; @@ -395,8 +413,10 @@ private: OutputPorts::Port _addOutputPort(const char *name, DataT *data) const; }; -class SelfSinkComponent final : public SelfSpecificComponent +class SelfSinkComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using InputPorts = SelfComponentPorts; @@ -411,6 +431,15 @@ public: return ConstSinkComponent {bt_self_component_sink_as_component_sink(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfSinkComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + MessageIterator::Shared createMessageIterator(InputPorts::Port port) const; bool isInterrupted() const noexcept @@ -686,7 +715,6 @@ SelfSinkComponent::createMessageIterator(const InputPorts::Port port) const switch (status) { case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK: - BT_ASSERT(libMsgIterPtr); return MessageIterator::Shared::createWithoutRef(libMsgIterPtr); case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_MEMORY_ERROR: throw MemoryError {};