#define BABELTRACE_CPP_COMMON_BT2_COMPONENT_PORT_HPP
#include <cstdint>
-#include <string>
#include <babeltrace2/babeltrace.h>
#include "logging.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+
#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
#include "shared-object.hpp"
return static_cast<bool>(bt_component_is_sink(this->libObjPtr()));
}
- const char *name() const noexcept
+ bt2c::CStringView name() const noexcept
{
return bt_component_get_name(this->libObjPtr());
}
class ConstSpecificComponent : public BorrowedObject<LibObjT>
{
public:
- using typename BorrowedObject<LibObjT>::_LibObjPtr;
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
protected:
- explicit ConstSpecificComponent(const _LibObjPtr libObjPtr) noexcept :
+ explicit ConstSpecificComponent(const LibObjPtr libObjPtr) noexcept :
BorrowedObject<LibObjT> {libObjPtr}
{
}
public:
- const char *name() const noexcept
+ bt2c::CStringView name() const noexcept
{
return this->_constComponent().name();
}
using _Spec = internal::ConstComponentPortsSpec<LibCompT, LibPortT>;
public:
- using typename BorrowedObject<LibCompT>::_LibObjPtr;
+ using typename BorrowedObject<LibCompT>::LibObjPtr;
using Port = ConstPort<LibPortT>;
using Iterator = BorrowedObjectIterator<ConstComponentPorts>;
- explicit ConstComponentPorts(const _LibObjPtr libObjPtr) noexcept :
+ explicit ConstComponentPorts(const LibObjPtr libObjPtr) noexcept :
BorrowedObject<LibCompT> {libObjPtr}
{
}
}
Port operator[](std::uint64_t index) const noexcept;
- Port operator[](const char *name) const noexcept;
- Port operator[](const std::string& name) const noexcept;
+ OptionalBorrowedObject<Port> operator[](bt2c::CStringView name) const noexcept;
Iterator begin() const noexcept;
Iterator end() const noexcept;
};
class ConstPort final : public BorrowedObject<LibObjT>
{
public:
- using typename BorrowedObject<LibObjT>::_LibObjPtr;
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
using Shared = SharedObject<ConstPort, LibObjT, internal::ConstPortRefFuncs<LibObjT>>;
- explicit ConstPort(const _LibObjPtr libObjPtr) noexcept : BorrowedObject<LibObjT> {libObjPtr}
+ explicit ConstPort(const LibObjPtr libObjPtr) noexcept : BorrowedObject<LibObjT> {libObjPtr}
{
}
- const char *name() const noexcept
+ bt2c::CStringView name() const noexcept
{
return bt_port_get_name(this->_libConstPortPtr());
}
}
template <typename LibCompT, typename LibPortT>
-typename ConstComponentPorts<LibCompT, LibPortT>::Port
-ConstComponentPorts<LibCompT, LibPortT>::operator[](const char * const name) const noexcept
-{
- return Port {_Spec::portByName(this->libObjPtr(), name)};
-}
-
-template <typename LibCompT, typename LibPortT>
-typename ConstComponentPorts<LibCompT, LibPortT>::Port
-ConstComponentPorts<LibCompT, LibPortT>::operator[](const std::string& name) const noexcept
+OptionalBorrowedObject<typename ConstComponentPorts<LibCompT, LibPortT>::Port>
+ConstComponentPorts<LibCompT, LibPortT>::operator[](const bt2c::CStringView name) const noexcept
{
- return (*this)[name.data()];
+ return _Spec::portByName(this->libObjPtr(), name);
}
template <typename LibCompT, typename LibPortT>