cpp-common/bt2: make `ConstComponentPorts::operator[](bt2c::CStringView)` return...
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 14 Feb 2024 16:14:07 +0000 (11:14 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 19 Feb 2024 18:10:15 +0000 (13:10 -0500)
The library functions that borrow ports by name return `NULL` when
no port with such name exist.  Change
`ConstComponentPorts::operator[](bt2c::CStringView)` to return an
`OptionalBorrowedObject` to model that in C++.

Change-Id: I2fafb509622e324980b88b70735e7beeb25f7fb4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11802
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/component-port.hpp

index c533da0efed855a5a1d8eeb1e786c9012baf9275..930b2e6f0ee2fbcd121d2347a84b547d2824f5ef 100644 (file)
@@ -261,7 +261,7 @@ public:
     }
 
     Port operator[](std::uint64_t index) const noexcept;
-    Port operator[](bt2c::CStringView name) const noexcept;
+    OptionalBorrowedObject<Port> operator[](bt2c::CStringView name) const noexcept;
     Iterator begin() const noexcept;
     Iterator end() const noexcept;
 };
@@ -502,10 +502,10 @@ ConstComponentPorts<LibCompT, LibPortT>::operator[](const std::uint64_t index) c
 }
 
 template <typename LibCompT, typename LibPortT>
-typename ConstComponentPorts<LibCompT, LibPortT>::Port
+OptionalBorrowedObject<typename ConstComponentPorts<LibCompT, LibPortT>::Port>
 ConstComponentPorts<LibCompT, LibPortT>::operator[](const bt2c::CStringView name) const noexcept
 {
-    return Port {_Spec::portByName(this->libObjPtr(), name)};
+    return _Spec::portByName(this->libObjPtr(), name);
 }
 
 template <typename LibCompT, typename LibPortT>
This page took 0.025997 seconds and 4 git commands to generate.