cpp-common/bt2: use bt2c::CStringView in parameters and return values throughout
[babeltrace.git] / src / cpp-common / bt2 / field-class.hpp
index 6682e5b52a07d9a239b358a2852594e881403e85..b0420c4f61d7a41d00ce9d797ecbe6e3cdcc84a3 100644 (file)
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
+#include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
-#include "common-iterator.hpp"
 #include "exc.hpp"
 #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"
 
@@ -163,43 +164,18 @@ enum class FieldClassType
 template <typename LibObjT>
 class CommonFieldClass : public BorrowedObject<LibObjT>
 {
-    /* Allow appendMember() to call `fc.libObjPtr()` */
-    friend class CommonStructureFieldClass<bt_field_class>;
-
-    /* Allow appendOption() to call `fc.libObjPtr()` */
-    friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>;
-
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_unsigned_option>>;
-
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_signed_option>>;
-
-    /* Allow *FieldClass() to call `fc.libObjPtr()` */
-    friend class CommonEventClass<bt_event_class>;
-    friend class CommonStreamClass<bt_stream_class>;
-
-    /* Allow create*FieldClass() to call `fc.libObjPtr()` */
-    friend class CommonTraceClass<bt_trace_class>;
-
 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>;
 
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -209,12 +185,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
+    CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
+    CommonFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonFieldClass<const bt_field_class> {*this};
+    }
+
     FieldClassType type() const noexcept
     {
         return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
@@ -423,7 +404,7 @@ public:
     template <typename LibValT>
     void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`.");
 
         bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
@@ -473,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());
@@ -492,13 +473,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayFieldClass<LibObjT>&
+    CommonBitArrayFieldClass<LibObjT>
     operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonBitArrayFieldClass<const bt_field_class> {*this};
+    }
+
     std::uint64_t length() const noexcept
     {
         return bt_field_class_bit_array_get_length(this->libObjPtr());
@@ -548,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());
@@ -567,15 +553,21 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
+    CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonIntegerFieldClass<const bt_field_class> {*this};
+    }
+
     void fieldValueRange(const std::uint64_t n) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstIntegerFieldClass`.");
 
         bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
     }
@@ -587,7 +579,8 @@ public:
 
     void preferredDisplayBase(const DisplayBase base) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstIntegerFieldClass`.");
 
         bt_field_class_integer_set_preferred_display_base(
             this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
@@ -626,10 +619,6 @@ struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
 {
 };
 
-} /* namespace internal */
-
-namespace internal {
-
 template <typename LibObjT>
 struct ConstEnumerationFieldClassMappingSpec;
 
@@ -677,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 +684,7 @@ public:
     {
     }
 
-    ConstEnumerationFieldClassMapping&
+    ConstEnumerationFieldClassMapping
     operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
     {
         _ThisBorrowedObject::operator=(mapping);
@@ -707,7 +697,7 @@ public:
             internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
     }
 
-    bpstd::string_view label() const noexcept
+    bt2c::CStringView label() const noexcept
     {
         return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
     }
@@ -781,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());
@@ -801,14 +791,19 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBaseEnumerationFieldClass&
+    CommonBaseEnumerationFieldClass
     operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonIntegerFieldClass::operator=(fc);
         return *this;
     }
 
-    std::uint64_t size() const noexcept
+    CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonBaseEnumerationFieldClass<const bt_field_class> {*this};
+    }
+
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
     }
@@ -823,16 +818,15 @@ template <typename LibObjT, typename MappingT>
 class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
-    using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
 
 public:
-    using Shared = SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
-    using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
+    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());
@@ -841,15 +835,15 @@ public:
     template <typename OtherLibObjT>
     CommonEnumerationFieldClass(
         const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
-        _ThisCommonEnumerationFieldClass {fc}
+        CommonEnumerationFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonEnumerationFieldClass&
+    CommonEnumerationFieldClass
     operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
     {
-        _ThisCommonEnumerationFieldClass::operator=(fc);
+        CommonEnumerationFieldClass::operator=(fc);
         return *this;
     }
 
@@ -859,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());
@@ -886,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};
@@ -898,7 +876,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Shared shared() const noexcept
@@ -997,17 +975,14 @@ template <typename LibObjT>
 class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+    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,14 +995,19 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClassMember<LibObjT>&
+    CommonStructureFieldClassMember<LibObjT>
     operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
-    bpstd::string_view name() const noexcept
+    CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept
+    {
+        return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
+    }
+
+    bt2c::CStringView name() const noexcept
     {
         return bt_field_class_structure_member_get_name(this->libObjPtr());
     }
@@ -1041,7 +1021,8 @@ public:
     template <typename LibValT>
     void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStructureFieldClassMember`.");
 
         bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
                                                             userAttrs.libObjPtr());
@@ -1121,18 +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 Member =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
-                                  StructureFieldClassMember>::type;
+    using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>;
 
-    using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
+    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());
@@ -1145,15 +1125,21 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
+    CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    void appendMember(const char * const name, const FieldClass fc) const
+    CommonStructureFieldClass<const bt_field_class> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonStructureFieldClass<const bt_field_class> {*this};
+    }
+
+    void appendMember(const bt2c::CStringView name, const FieldClass fc) const
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStructureFieldClass`.");
 
         const auto status =
             bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
@@ -1163,12 +1149,7 @@ public:
         }
     }
 
-    void appendMember(const std::string& name, const FieldClass fc) const
-    {
-        this->appendMember(name.data(), fc);
-    }
-
-    std::uint64_t size() const noexcept
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_structure_get_member_count(this->libObjPtr());
     }
@@ -1180,7 +1161,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Member operator[](const std::uint64_t index) const noexcept
@@ -1189,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
@@ -1263,18 +1233,16 @@ class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
 {
 private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    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());
@@ -1287,12 +1255,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
+    CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonArrayFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonArrayFieldClass<const bt_field_class> {*this};
+    }
+
     _FieldClass elementFieldClass() const noexcept
     {
         return _FieldClass {
@@ -1333,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());
@@ -1351,13 +1324,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStaticArrayFieldClass&
+    CommonStaticArrayFieldClass
     operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonStaticArrayFieldClass<const bt_field_class> {*this};
+    }
+
     std::uint64_t length() const noexcept
     {
         return bt_field_class_array_static_get_length(this->libObjPtr());
@@ -1397,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());
@@ -1416,13 +1394,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDynamicArrayWithLengthFieldClass&
+    CommonDynamicArrayWithLengthFieldClass
     operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath lengthFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -1491,18 +1474,16 @@ class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
 {
 private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    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());
@@ -1515,12 +1496,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
+    CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonOptionFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonOptionFieldClass<const bt_field_class> {*this};
+    }
+
     _FieldClass fieldClass() const noexcept
     {
         return _FieldClass {
@@ -1563,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());
@@ -1583,13 +1569,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithSelectorFieldClass&
+    CommonOptionWithSelectorFieldClass
     operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath selectorFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -1630,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());
@@ -1652,13 +1642,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithBoolSelectorFieldClass&
+    CommonOptionWithBoolSelectorFieldClass
     operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     bool selectorIsReversed() const noexcept
     {
         return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
@@ -1729,20 +1724,15 @@ template <typename LibObjT, typename RangeSetT>
 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
 {
 private:
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
     using typename CommonOptionWithSelectorFieldClass<
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
-    using _ThisCommonOptionWithIntegerSelectorFieldClass =
-        CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
-
 public:
-    using Shared = SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
-
+    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());
@@ -1756,7 +1746,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithIntegerSelectorFieldClass&
+    CommonOptionWithIntegerSelectorFieldClass
     operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
@@ -1867,16 +1857,13 @@ class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -1888,22 +1875,21 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClassOption&
+    CommonVariantFieldClassOption
     operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept
     {
-        const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
+        return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
+    }
 
-        return nonstd::nullopt;
+    bt2c::CStringView name() const noexcept
+    {
+        return bt_field_class_variant_option_get_name(this->libObjPtr());
     }
 
     _FieldClass fieldClass() const noexcept
@@ -1915,7 +1901,8 @@ public:
     template <typename LibValT>
     void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstVariantFieldClassOption`.");
 
         bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
@@ -2006,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}
     {
     }
@@ -2029,7 +2017,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    ConstVariantWithIntegerSelectorFieldClassOption&
+    ConstVariantWithIntegerSelectorFieldClassOption
     operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
@@ -2041,7 +2029,7 @@ public:
         return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
         return this->asBaseOption().name();
     }
@@ -2113,19 +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 =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
-                                  VariantFieldClassOption>::type;
-
-    using Iterator = CommonIterator<CommonVariantFieldClass, 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());
@@ -2138,13 +2124,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
+    CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    std::uint64_t size() const noexcept
+    CommonVariantFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonVariantFieldClass<const bt_field_class> {*this};
+    }
+
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_variant_get_option_count(this->libObjPtr());
     }
@@ -2156,7 +2147,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Option operator[](const std::uint64_t index) const noexcept
@@ -2165,21 +2156,10 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const 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
+    OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
     {
-        return (*this)[name.data()];
+        return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(),
+                                                                            name);
     }
 
     Shared shared() const noexcept
@@ -2216,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());
@@ -2235,16 +2215,22 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithoutSelectorFieldClass&
+    CommonVariantWithoutSelectorFieldClass
     operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     void appendOption(const char * const name, const FieldClass fc) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`.");
 
         const auto status = bt_field_class_variant_without_selector_append_option(
             this->libObjPtr(), name, fc.libObjPtr());
@@ -2255,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);
     }
@@ -2362,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());
@@ -2382,13 +2373,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithSelectorFieldClass&
+    CommonVariantWithSelectorFieldClass
     operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath selectorFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -2413,20 +2409,18 @@ class CommonVariantWithIntegerSelectorFieldClass :
 private:
     using typename CommonVariantWithSelectorFieldClass<
         LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
-    using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-    using _ThisCommonVariantWithIntegerSelectorFieldClass =
-        CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
 
     using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
 
 public:
-    using Shared = SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
-
+    using typename CommonFieldClass<LibObjT>::LibObjPtr;
+    using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
     using Option = OptionT;
+
     using Iterator =
-        CommonIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>, Option>;
+        BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>;
 
-    explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
     {
         BT_ASSERT_DBG(this->isVariant());
@@ -2440,7 +2434,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithIntegerSelectorFieldClass&
+    CommonVariantWithIntegerSelectorFieldClass
     operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
     {
         _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
@@ -2452,26 +2446,17 @@ public:
         return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const 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
+    OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
     {
-        return (*this)[name.data()];
+        return _Spec::optionByName(this->libObjPtr(), name);
     }
 
     void appendOption(const char * const name, const FieldClass fc,
                       const typename Option::RangeSet ranges) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(
+            !std::is_const<LibObjT>::value,
+            "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`.");
 
         const auto status =
             _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
@@ -2482,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);
@@ -2495,7 +2486,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Shared shared() const noexcept
This page took 0.038777 seconds and 4 git commands to generate.