#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"
}
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>
{
{
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:
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;
}
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>;
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:
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>;
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:
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>;
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
}
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:
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:
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
}
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()};
}
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()};
}
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()};
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 {};
}
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()};