Fix: cpp-common/bt2: more specific assertion in `CommonVariantWithIntegerSelectorFiel...
[babeltrace.git] / src / cpp-common / bt2 / field-class.hpp
index f299690edce680bd5685e3a4d908dfd34cbac769..c6c4d690ff7870e93b26ee6bc4852630991c3d9c 100644 (file)
@@ -13,7 +13,8 @@
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
-#include "cpp-common/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
@@ -21,6 +22,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"
 
@@ -166,14 +168,14 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
 
 protected:
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -452,13 +454,13 @@ template <typename LibObjT>
 class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonBitArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isBitArray());
@@ -532,13 +534,13 @@ private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonIntegerFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isInteger());
@@ -664,14 +666,15 @@ class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+
     using RangeSet = typename std::conditional<
         std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value,
         ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
 
-    explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept :
+    explicit ConstEnumerationFieldClassMapping(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -694,7 +697,7 @@ public:
             internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
     }
 
-    const char *label() const noexcept
+    bt2c::CStringView label() const noexcept
     {
         return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
     }
@@ -768,13 +771,13 @@ private:
     using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
 
-    explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonBaseEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonIntegerFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isEnumeration());
@@ -815,15 +818,15 @@ template <typename LibObjT, typename MappingT>
 class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>;
     using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>;
     using Mapping = MappingT;
 
-    explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonBaseEnumerationFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isEnumeration());
@@ -850,24 +853,13 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Mapping> operator[](const char * const label) const noexcept
+    OptionalBorrowedObject<Mapping> operator[](const bt2c::CStringView label) const noexcept
     {
-        const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
+        return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
             this->libObjPtr(), label);
-
-        if (libObjPtr) {
-            return Mapping {libObjPtr};
-        }
-
-        return nonstd::nullopt;
     }
 
-    nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
-    {
-        return (*this)[label.data()];
-    }
-
-    void addMapping(const char * const label, const typename Mapping::RangeSet ranges) const
+    void addMapping(const bt2c::CStringView label, const typename Mapping::RangeSet ranges) const
     {
         const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
             this->libObjPtr(), label, ranges.libObjPtr());
@@ -877,11 +869,6 @@ public:
         }
     }
 
-    void addMapping(const std::string& label, const typename Mapping::RangeSet ranges) const
-    {
-        this->addMapping(label.data(), ranges);
-    }
-
     Iterator begin() const noexcept
     {
         return Iterator {*this, 0};
@@ -988,14 +975,14 @@ template <typename LibObjT>
 class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -1020,7 +1007,7 @@ public:
         return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
     }
 
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_field_class_structure_member_get_name(this->libObjPtr());
     }
@@ -1115,17 +1102,17 @@ template <typename LibObjT>
 class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
     using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>;
 
     using Member =
         internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>;
 
-    explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isStructure());
@@ -1149,7 +1136,7 @@ public:
         return CommonStructureFieldClass<const bt_field_class> {*this};
     }
 
-    void appendMember(const char * const name, const FieldClass fc) const
+    void appendMember(const bt2c::CStringView name, const FieldClass fc) const
     {
         static_assert(!std::is_const<LibObjT>::value,
                       "Not available with `bt2::ConstStructureFieldClass`.");
@@ -1162,11 +1149,6 @@ public:
         }
     }
 
-    void appendMember(const std::string& name, const FieldClass fc) const
-    {
-        this->appendMember(name.data(), fc);
-    }
-
     std::uint64_t length() const noexcept
     {
         return bt_field_class_structure_get_member_count(this->libObjPtr());
@@ -1188,21 +1170,10 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Member> operator[](const char * const name) const noexcept
-    {
-        const auto libObjPtr =
-            internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return Member {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<Member> operator[](const std::string& name) const noexcept
+    OptionalBorrowedObject<Member> operator[](const bt2c::CStringView name) const noexcept
     {
-        return (*this)[name.data()];
+        return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(),
+                                                                              name);
     }
 
     Shared shared() const noexcept
@@ -1265,13 +1236,13 @@ private:
     using _FieldClass = internal::DepFc<LibObjT>;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isArray());
@@ -1335,12 +1306,12 @@ class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
 {
 private:
     using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonArrayFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isStaticArray());
@@ -1404,12 +1375,12 @@ class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClas
 {
 private:
     using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonArrayFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isDynamicArrayWithLength());
@@ -1506,13 +1477,13 @@ private:
     using _FieldClass = internal::DepFc<LibObjT>;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isOption());
@@ -1578,13 +1549,13 @@ private:
     using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonOptionFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isOptionWithSelector());
@@ -1650,15 +1621,14 @@ template <typename LibObjT>
 class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
     using typename CommonOptionWithSelectorFieldClass<
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isOptionWithBoolSelector());
@@ -1754,16 +1724,15 @@ template <typename LibObjT, typename RangeSetT>
 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
     using typename CommonOptionWithSelectorFieldClass<
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>;
     using RangeSet = RangeSetT;
 
-    explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
@@ -1888,13 +1857,13 @@ class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -1918,7 +1887,7 @@ public:
         return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
     }
 
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return bt_field_class_variant_option_get_name(this->libObjPtr());
     }
@@ -2024,17 +1993,18 @@ class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<Li
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+
     using RangeSet = typename std::conditional<
         std::is_same<
             LibObjT,
             const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
         ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
 
-    explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
+    explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -2059,7 +2029,7 @@ public:
         return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
     }
 
-    const char *name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return this->asBaseOption().name();
     }
@@ -2131,17 +2101,17 @@ private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
     using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>;
 
     using Option =
         internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>;
 
-    explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isVariant());
@@ -2186,21 +2156,10 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const name) const noexcept
+    OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
     {
-        const auto libObjPtr =
-            internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return Option {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<Option> operator[](const std::string& name) const noexcept
-    {
-        return (*this)[name.data()];
+        return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(),
+                                                                            name);
     }
 
     Shared shared() const noexcept
@@ -2237,12 +2196,12 @@ class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<Li
 {
 private:
     using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
 
-    explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isVariantWithoutSelector());
@@ -2282,7 +2241,12 @@ public:
         }
     }
 
-    void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc) const
+    void appendOption(const bt2c::CStringView name, const FieldClass fc) const
+    {
+        return this->appendOption(name.data(), fc);
+    }
+
+    void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc) const
     {
         this->appendOption(name ? name->data() : nullptr, fc);
     }
@@ -2389,13 +2353,13 @@ private:
     using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
 
 protected:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
 
-    explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isVariantWithSelector());
@@ -2445,21 +2409,21 @@ class CommonVariantWithIntegerSelectorFieldClass :
 private:
     using typename CommonVariantWithSelectorFieldClass<
         LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
     using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
 
 public:
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
     using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
     using Option = OptionT;
 
     using Iterator =
         BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>;
 
-    explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
     {
-        BT_ASSERT_DBG(this->isVariant());
+        BT_ASSERT_DBG(this->isVariantWithIntegerSelector());
     }
 
     template <typename OtherLibObjT>
@@ -2482,20 +2446,9 @@ public:
         return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const name) const noexcept
+    OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
     {
-        const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return Option {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<Option> operator[](const std::string& name) const noexcept
-    {
-        return (*this)[name.data()];
+        return _Spec::optionByName(this->libObjPtr(), name);
     }
 
     void appendOption(const char * const name, const FieldClass fc,
@@ -2514,7 +2467,13 @@ public:
         }
     }
 
-    void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc,
+    void appendOption(const bt2c::CStringView name, const FieldClass fc,
+                      const typename Option::RangeSet ranges) const
+    {
+        return this->appendOption(name.data(), fc, ranges);
+    }
+
+    void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc,
                       const typename Option::RangeSet ranges) const
     {
         this->appendOption(name ? name->data() : nullptr, fc, ranges);
This page took 0.030665 seconds and 4 git commands to generate.