X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fself-component-port.hpp;h=10a73bb4bd3a021c58a5cd4722d4fa133a7ec3f5;hb=292762ab236187b1c4546febedf0f450ba3acf77;hp=6b6cff147d977f1ef31bc5f551b1e39e8740af65;hpb=f5018066bbb4618c3d6549c718c3648895a28385;p=babeltrace.git diff --git a/src/cpp-common/bt2/self-component-port.hpp b/src/cpp-common/bt2/self-component-port.hpp index 6b6cff14..10a73bb4 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,12 +99,14 @@ 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 + TraceClass::Shared createTraceClass() const { const auto libObjPtr = bt_trace_class_create(this->libObjPtr()); @@ -113,10 +114,10 @@ public: throw MemoryError {}; } - return bt2::TraceClass::Shared::createWithoutRef(libObjPtr); + return TraceClass::Shared::createWithoutRef(libObjPtr); } - bt2::ClockClass::Shared createClockClass() const + ClockClass::Shared createClockClass() const { const auto libObjPtr = bt_clock_class_create(this->libObjPtr()); @@ -124,10 +125,12 @@ public: throw MemoryError {}; } - return bt2::ClockClass::Shared::createWithoutRef(libObjPtr); + return ClockClass::Shared::createWithoutRef(libObjPtr); } }; +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 @@ -539,7 +568,7 @@ public: template T& data() const noexcept { - *static_cast(bt_self_component_port_get_data(this->_libSelfCompPortPtr())); + return *static_cast(bt_self_component_port_get_data(this->_libSelfCompPortPtr())); } private: @@ -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 {};