cpp-common/bt2: make setters return `*this`
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
index e2bbe80742af9a3350cebe23caf2b27c2a211316..e1ab809859461f618510b9e9526ee2637e057aee 100644 (file)
@@ -99,10 +99,11 @@ public:
     }
 
     template <typename T>
-    void data(T& obj) const noexcept
+    SelfComponent data(T& obj) const noexcept
     {
         bt_self_component_set_data(this->libObjPtr(),
                                    const_cast<void *>(static_cast<const void *>(&obj)));
+        return *this;
     }
 
     bt2::TraceClass::Shared createTraceClass() const
@@ -187,13 +188,7 @@ public:
         return this->_selfComponent().template data<T>();
     }
 
-    template <typename T>
-    void data(T& obj) const noexcept
-    {
-        this->_selfComponent().data(obj);
-    }
-
-private:
+protected:
     SelfComponent _selfComponent() const noexcept
     {
         return SelfComponent {this->libObjPtr()};
@@ -328,6 +323,8 @@ public:
 
 class SelfSourceComponent final : public internal::SelfSpecificComponent<bt_self_component_source>
 {
+    using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_source>;
+
 public:
     using OutputPorts = SelfComponentPorts<bt_self_component_source, bt_self_component_port_output,
                                            const bt_port_output>;
@@ -343,6 +340,15 @@ public:
             bt_self_component_source_as_component_source(this->libObjPtr())};
     }
 
+    using _ThisSelfSpecificComponent::data;
+
+    template <typename T>
+    SelfSourceComponent data(T& obj) const noexcept
+    {
+        this->_selfComponent().data(obj);
+        return *this;
+    }
+
     template <typename DataT>
     OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
 
@@ -357,6 +363,8 @@ private:
 
 class SelfFilterComponent final : public internal::SelfSpecificComponent<bt_self_component_filter>
 {
+    using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_filter>;
+
 public:
     using InputPorts = SelfComponentPorts<bt_self_component_filter, bt_self_component_port_input,
                                           const bt_port_input>;
@@ -374,6 +382,15 @@ public:
             bt_self_component_filter_as_component_filter(this->libObjPtr())};
     }
 
+    using _ThisSelfSpecificComponent::data;
+
+    template <typename T>
+    SelfFilterComponent data(T& obj) const noexcept
+    {
+        this->_selfComponent().data(obj);
+        return *this;
+    }
+
     template <typename DataT>
     InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
 
@@ -398,6 +415,8 @@ private:
 
 class SelfSinkComponent final : public internal::SelfSpecificComponent<bt_self_component_sink>
 {
+    using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_sink>;
+
 public:
     using InputPorts = SelfComponentPorts<bt_self_component_sink, bt_self_component_port_input,
                                           const bt_port_input>;
@@ -412,6 +431,15 @@ public:
         return ConstSinkComponent {bt_self_component_sink_as_component_sink(this->libObjPtr())};
     }
 
+    using _ThisSelfSpecificComponent::data;
+
+    template <typename T>
+    SelfSinkComponent data(T& obj) const noexcept
+    {
+        this->_selfComponent().data(obj);
+        return *this;
+    }
+
     MessageIterator::Shared createMessageIterator(InputPorts::Port port) const;
 
     bool isInterrupted() const noexcept
This page took 0.024113 seconds and 4 git commands to generate.