From ca61ecbc0d9d2d64cc3b6a02d118e4ee87477cf6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 25 Nov 2023 20:04:47 -0500 Subject: [PATCH] cpp-common/bt2: use `bt2::OptionalBorrowedObject` where possible Signed-off-by: Philippe Proulx Change-Id: Iba2056e520bbe4ad4843a51e51f99173e4929c4f Reviewed-on: https://review.lttng.org/c/babeltrace/+/11439 Tested-by: jenkins Reviewed-by: Simon Marchi CI-Build: Simon Marchi --- src/cpp-common/bt2/field-class.hpp | 53 +++------- src/cpp-common/bt2/field.hpp | 24 ++--- src/cpp-common/bt2/message.hpp | 22 ++-- src/cpp-common/bt2/shared-object.hpp | 35 ++----- src/cpp-common/bt2/trace-ir.hpp | 147 ++++++--------------------- src/cpp-common/bt2/value.hpp | 17 +--- 6 files changed, 78 insertions(+), 220 deletions(-) diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 2cef7290..fe4cea46 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -21,6 +21,7 @@ #include "field-path.hpp" #include "integer-range-set.hpp" #include "internal/utils.hpp" +#include "optional-borrowed-object.hpp" #include "shared-object.hpp" #include "value.hpp" @@ -851,19 +852,13 @@ public: this->libObjPtr(), index)}; } - bt2s::optional operator[](const char * const label) const noexcept + OptionalBorrowedObject operator[](const char * const label) const noexcept { - const auto libObjPtr = internal::CommonEnumerationFieldClassSpec::mappingByLabel( + return internal::CommonEnumerationFieldClassSpec::mappingByLabel( this->libObjPtr(), label); - - if (libObjPtr) { - return Mapping {libObjPtr}; - } - - return bt2s::nullopt; } - bt2s::optional operator[](const std::string& label) const noexcept + OptionalBorrowedObject operator[](const std::string& label) const noexcept { return (*this)[label.data()]; } @@ -1189,19 +1184,13 @@ public: this->libObjPtr(), index)}; } - bt2s::optional operator[](const char * const name) const noexcept + OptionalBorrowedObject operator[](const char * const name) const noexcept { - const auto libObjPtr = - internal::CommonStructureFieldClassSpec::memberByName(this->libObjPtr(), name); - - if (libObjPtr) { - return Member {libObjPtr}; - } - - return bt2s::nullopt; + return internal::CommonStructureFieldClassSpec::memberByName(this->libObjPtr(), + name); } - bt2s::optional operator[](const std::string& name) const noexcept + OptionalBorrowedObject operator[](const std::string& name) const noexcept { return (*this)[name.data()]; } @@ -2186,19 +2175,13 @@ public: this->libObjPtr(), index)}; } - bt2s::optional