.gitignore: add some more IDE / tools related file
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
index fff4aea76a37c7eaeacd871b4d1aef055e4c7379..10a73bb4bd3a021c58a5cd4722d4fa133a7ec3f5 100644 (file)
@@ -8,13 +8,11 @@
 #define BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP
 
 #include <cstdint>
-#include <string>
 
 #include <babeltrace2/babeltrace.h>
 
 #include "logging.hpp"
 
-#include "common/assert.h"
 #include "cpp-common/bt2c/c-string-view.hpp"
 
 #include "borrowed-object-iterator.hpp"
@@ -101,12 +99,38 @@ public:
     }
 
     template <typename T>
-    void data(T& obj) const noexcept
+    SelfComponent data(T& obj) const noexcept
     {
-        bt_self_component_set_data(this->libObjPtr(), static_cast<void *>(&obj));
+        bt_self_component_set_data(this->libObjPtr(),
+                                   const_cast<void *>(static_cast<const void *>(&obj)));
+        return *this;
+    }
+
+    TraceClass::Shared createTraceClass() const
+    {
+        const auto libObjPtr = bt_trace_class_create(this->libObjPtr());
+
+        if (!libObjPtr) {
+            throw MemoryError {};
+        }
+
+        return TraceClass::Shared::createWithoutRef(libObjPtr);
+    }
+
+    ClockClass::Shared createClockClass() const
+    {
+        const auto libObjPtr = bt_clock_class_create(this->libObjPtr());
+
+        if (!libObjPtr) {
+            throw MemoryError {};
+        }
+
+        return ClockClass::Shared::createWithoutRef(libObjPtr);
     }
 };
 
+namespace internal {
+
 template <typename LibObjT>
 class SelfSpecificComponent : public BorrowedObject<LibObjT>
 {
@@ -127,7 +151,8 @@ protected:
     {
         LibPortT *libPortPtr;
 
-        const auto status = func(this->libObjPtr(), name, static_cast<void *>(data), &libPortPtr);
+        const auto status = func(this->libObjPtr(), name,
+                                 const_cast<void *>(static_cast<const void *>(data)), &libPortPtr);
 
         switch (status) {
         case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK:
@@ -163,21 +188,13 @@ 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()};
     }
 };
 
-namespace internal {
-
 template <typename LibSelfCompT, typename LibSelfCompPortPtrT>
 struct SelfComponentPortsSpec;
 
@@ -297,16 +314,17 @@ public:
     }
 
     Port operator[](std::uint64_t index) const noexcept;
-    Port operator[](const char *name) const noexcept;
-    Port operator[](const std::string& name) const noexcept;
+    Port operator[](bt2c::CStringView name) const noexcept;
     Iterator begin() const noexcept;
     Iterator end() const noexcept;
     Port front() const noexcept;
     Port back() const noexcept;
 };
 
-class SelfSourceComponent final : public SelfSpecificComponent<bt_self_component_source>
+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>;
@@ -322,15 +340,20 @@ public:
             bt_self_component_source_as_component_source(this->libObjPtr())};
     }
 
-    template <typename DataT>
-    OutputPorts::Port addOutputPort(const char *name, DataT& data) const;
+    using _ThisSelfSpecificComponent::data;
 
-    OutputPorts::Port addOutputPort(const char *name) const;
+    template <typename T>
+    SelfSourceComponent data(T& obj) const noexcept
+    {
+        this->_selfComponent().data(obj);
+        return *this;
+    }
 
     template <typename DataT>
-    OutputPorts::Port addOutputPort(const std::string& name, DataT& data) const;
+    OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
+
+    OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
 
-    OutputPorts::Port addOutputPort(const std::string& name) const;
     OutputPorts outputPorts() const noexcept;
 
 private:
@@ -338,8 +361,10 @@ private:
     OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
 };
 
-class SelfFilterComponent final : public SelfSpecificComponent<bt_self_component_filter>
+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>;
@@ -357,26 +382,27 @@ public:
             bt_self_component_filter_as_component_filter(this->libObjPtr())};
     }
 
-    template <typename DataT>
-    InputPorts::Port addInputPort(const char *name, DataT& data) const;
+    using _ThisSelfSpecificComponent::data;
 
-    InputPorts::Port addInputPort(const char *name) const;
+    template <typename T>
+    SelfFilterComponent data(T& obj) const noexcept
+    {
+        this->_selfComponent().data(obj);
+        return *this;
+    }
 
     template <typename DataT>
-    InputPorts::Port addInputPort(const std::string& name, DataT& data) const;
+    InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
+
+    InputPorts::Port addInputPort(bt2c::CStringView name) const;
 
-    InputPorts::Port addInputPort(const std::string& name) const;
     InputPorts inputPorts() const noexcept;
 
     template <typename DataT>
-    OutputPorts::Port addOutputPort(const char *name, DataT& data) const;
+    OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
 
-    OutputPorts::Port addOutputPort(const char *name) const;
+    OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
 
-    template <typename DataT>
-    OutputPorts::Port addOutputPort(const std::string& name, DataT& data) const;
-
-    OutputPorts::Port addOutputPort(const std::string& name) const;
     OutputPorts outputPorts() const noexcept;
 
 private:
@@ -387,8 +413,10 @@ private:
     OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
 };
 
-class SelfSinkComponent final : public SelfSpecificComponent<bt_self_component_sink>
+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>;
@@ -403,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
@@ -411,14 +448,10 @@ public:
     }
 
     template <typename DataT>
-    InputPorts::Port addInputPort(const char *name, DataT& data) const;
+    InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
 
-    InputPorts::Port addInputPort(const char *name) const;
+    InputPorts::Port addInputPort(bt2c::CStringView name) const;
 
-    template <typename DataT>
-    InputPorts::Port addInputPort(const std::string& name, DataT& data) const;
-
-    InputPorts::Port addInputPort(const std::string& name) const;
     InputPorts inputPorts() const noexcept;
 
 private:
@@ -535,7 +568,7 @@ public:
     template <typename T>
     T& data() const noexcept
     {
-        *static_cast<T *>(bt_self_component_port_get_data(this->_libSelfCompPortPtr()));
+        return *static_cast<T *>(bt_self_component_port_get_data(this->_libSelfCompPortPtr()));
     }
 
 private:
@@ -556,19 +589,11 @@ SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
-    const char * const name) const noexcept
+    const bt2c::CStringView name) const noexcept
 {
     return Port {_Spec::portByName(this->libObjPtr(), name)};
 }
 
-template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
-typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
-SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
-    const std::string& name) const noexcept
-{
-    return (*this)[name.data()];
-}
-
 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::begin() const noexcept
@@ -611,31 +636,18 @@ SelfSourceComponent::OutputPorts::Port SelfSourceComponent::_addOutputPort(const
 }
 
 template <typename DataT>
-SelfSourceComponent::OutputPorts::Port SelfSourceComponent::addOutputPort(const char * const name,
-                                                                          DataT& data) const
+SelfSourceComponent::OutputPorts::Port
+SelfSourceComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
 {
     return this->_addOutputPort(name, &data);
 }
 
 inline SelfSourceComponent::OutputPorts::Port
-SelfSourceComponent::addOutputPort(const char * const name) const
+SelfSourceComponent::addOutputPort(const bt2c::CStringView name) const
 {
     return this->_addOutputPort<void>(name, nullptr);
 }
 
-template <typename DataT>
-SelfSourceComponent::OutputPorts::Port SelfSourceComponent::addOutputPort(const std::string& name,
-                                                                          DataT& data) const
-{
-    return this->_addOutputPort(name.data(), &data);
-}
-
-inline SelfSourceComponent::OutputPorts::Port
-SelfSourceComponent::addOutputPort(const std::string& name) const
-{
-    return this->_addOutputPort<void>(name.data(), nullptr);
-}
-
 inline SelfSourceComponent::OutputPorts SelfSourceComponent::outputPorts() const noexcept
 {
     return OutputPorts {this->libObjPtr()};
@@ -650,31 +662,18 @@ SelfFilterComponent::OutputPorts::Port SelfFilterComponent::_addOutputPort(const
 }
 
 template <typename DataT>
-SelfFilterComponent::OutputPorts::Port SelfFilterComponent::addOutputPort(const char * const name,
-                                                                          DataT& data) const
+SelfFilterComponent::OutputPorts::Port
+SelfFilterComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
 {
     return this->_addOutputPort(name, &data);
 }
 
 inline SelfFilterComponent::OutputPorts::Port
-SelfFilterComponent::addOutputPort(const char * const name) const
+SelfFilterComponent::addOutputPort(const bt2c::CStringView name) const
 {
     return this->_addOutputPort<void>(name, nullptr);
 }
 
-template <typename DataT>
-SelfFilterComponent::OutputPorts::Port SelfFilterComponent::addOutputPort(const std::string& name,
-                                                                          DataT& data) const
-{
-    return this->_addOutputPort(name.data(), &data);
-}
-
-inline SelfFilterComponent::OutputPorts::Port
-SelfFilterComponent::addOutputPort(const std::string& name) const
-{
-    return this->_addOutputPort<void>(name.data(), nullptr);
-}
-
 inline SelfFilterComponent::OutputPorts SelfFilterComponent::outputPorts() const noexcept
 {
     return OutputPorts {this->libObjPtr()};
@@ -689,31 +688,18 @@ SelfFilterComponent::InputPorts::Port SelfFilterComponent::_addInputPort(const c
 }
 
 template <typename DataT>
-SelfFilterComponent::InputPorts::Port SelfFilterComponent::addInputPort(const char * const name,
-                                                                        DataT& data) const
+SelfFilterComponent::InputPorts::Port
+SelfFilterComponent::addInputPort(const bt2c::CStringView name, DataT& data) const
 {
     return this->_addInputPort(name, &data);
 }
 
 inline SelfFilterComponent::InputPorts::Port
-SelfFilterComponent::addInputPort(const char * const name) const
+SelfFilterComponent::addInputPort(const bt2c::CStringView name) const
 {
     return this->_addInputPort<void>(name, nullptr);
 }
 
-template <typename DataT>
-SelfFilterComponent::InputPorts::Port SelfFilterComponent::addInputPort(const std::string& name,
-                                                                        DataT& data) const
-{
-    return this->_addInputPort(name.data(), &data);
-}
-
-inline SelfFilterComponent::InputPorts::Port
-SelfFilterComponent::addInputPort(const std::string& name) const
-{
-    return this->_addInputPort<void>(name.data(), nullptr);
-}
-
 inline SelfFilterComponent::InputPorts SelfFilterComponent::inputPorts() const noexcept
 {
     return InputPorts {this->libObjPtr()};
@@ -729,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 {};
@@ -749,31 +734,18 @@ SelfSinkComponent::InputPorts::Port SelfSinkComponent::_addInputPort(const char
 }
 
 template <typename DataT>
-SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const char * const name,
+SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const bt2c::CStringView name,
                                                                     DataT& data) const
 {
     return this->_addInputPort(name, &data);
 }
 
 inline SelfSinkComponent::InputPorts::Port
-SelfSinkComponent::addInputPort(const char * const name) const
+SelfSinkComponent::addInputPort(const bt2c::CStringView name) const
 {
     return this->_addInputPort<void>(name, nullptr);
 }
 
-template <typename DataT>
-SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const std::string& name,
-                                                                    DataT& data) const
-{
-    return this->_addInputPort(name.data(), &data);
-}
-
-inline SelfSinkComponent::InputPorts::Port
-SelfSinkComponent::addInputPort(const std::string& name) const
-{
-    return this->_addInputPort<void>(name.data(), nullptr);
-}
-
 inline SelfSinkComponent::InputPorts SelfSinkComponent::inputPorts() const noexcept
 {
     return InputPorts {this->libObjPtr()};
This page took 0.028458 seconds and 4 git commands to generate.