cpp-common/bt2: move `SelfSpecificComponent` to `internal` namespace
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
index e41dd09c8cde3d3259236861244c9f627f99f3c3..e2bbe80742af9a3350cebe23caf2b27c2a211316 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "logging.hpp"
 
-#include "common/assert.h"
 #include "cpp-common/bt2c/c-string-view.hpp"
 
 #include "borrowed-object-iterator.hpp"
@@ -102,10 +101,35 @@ public:
     template <typename T>
     void 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)));
+    }
+
+    bt2::TraceClass::Shared createTraceClass() const
+    {
+        const auto libObjPtr = bt_trace_class_create(this->libObjPtr());
+
+        if (!libObjPtr) {
+            throw MemoryError {};
+        }
+
+        return bt2::TraceClass::Shared::createWithoutRef(libObjPtr);
+    }
+
+    bt2::ClockClass::Shared createClockClass() const
+    {
+        const auto libObjPtr = bt_clock_class_create(this->libObjPtr());
+
+        if (!libObjPtr) {
+            throw MemoryError {};
+        }
+
+        return bt2::ClockClass::Shared::createWithoutRef(libObjPtr);
     }
 };
 
+namespace internal {
+
 template <typename LibObjT>
 class SelfSpecificComponent : public BorrowedObject<LibObjT>
 {
@@ -126,7 +150,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:
@@ -175,8 +200,6 @@ private:
     }
 };
 
-namespace internal {
-
 template <typename LibSelfCompT, typename LibSelfCompPortPtrT>
 struct SelfComponentPortsSpec;
 
@@ -303,7 +326,7 @@ public:
     Port back() const noexcept;
 };
 
-class SelfSourceComponent final : public SelfSpecificComponent<bt_self_component_source>
+class SelfSourceComponent final : public internal::SelfSpecificComponent<bt_self_component_source>
 {
 public:
     using OutputPorts = SelfComponentPorts<bt_self_component_source, bt_self_component_port_output,
@@ -332,7 +355,7 @@ 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>
 {
 public:
     using InputPorts = SelfComponentPorts<bt_self_component_filter, bt_self_component_port_input,
@@ -373,7 +396,7 @@ 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>
 {
 public:
     using InputPorts = SelfComponentPorts<bt_self_component_sink, bt_self_component_port_input,
@@ -517,7 +540,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:
@@ -664,7 +687,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 {};
This page took 0.026041 seconds and 4 git commands to generate.