cpp-common/bt2: make `ConstComponentPorts::operator[](bt2c::CStringView)` return...
[babeltrace.git] / src / cpp-common / bt2 / component-port.hpp
index b82398481cfa352c7513ffddbc814125c7483436..930b2e6f0ee2fbcd121d2347a84b547d2824f5ef 100644 (file)
@@ -8,12 +8,13 @@
 #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"
@@ -93,7 +94,7 @@ public:
         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());
     }
@@ -122,7 +123,7 @@ protected:
     }
 
 public:
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return this->_constComponent().name();
     }
@@ -260,8 +261,7 @@ public:
     }
 
     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;
 };
@@ -467,7 +467,7 @@ public:
     {
     }
 
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_port_get_name(this->_libConstPortPtr());
     }
@@ -502,17 +502,10 @@ ConstComponentPorts<LibCompT, LibPortT>::operator[](const std::uint64_t index) c
 }
 
 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>
This page took 0.025247 seconds and 4 git commands to generate.