cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2 / field-class.hpp
index 5ce29b70a4d8c621bf9df48bd57c96f12d362c43..94cdb8e6de036f2cd94ece042011537d39ede863 100644 (file)
@@ -13,8 +13,7 @@
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
@@ -184,7 +183,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
+    CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
         return *this;
@@ -472,7 +471,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayFieldClass<LibObjT>&
+    CommonBitArrayFieldClass<LibObjT>
     operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
@@ -552,7 +551,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
+    CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
@@ -618,10 +617,6 @@ struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
 {
 };
 
-} /* namespace internal */
-
-namespace internal {
-
 template <typename LibObjT>
 struct ConstEnumerationFieldClassMappingSpec;
 
@@ -686,7 +681,7 @@ public:
     {
     }
 
-    ConstEnumerationFieldClassMapping&
+    ConstEnumerationFieldClassMapping
     operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
     {
         _ThisBorrowedObject::operator=(mapping);
@@ -699,7 +694,7 @@ public:
             internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
     }
 
-    bpstd::string_view label() const noexcept
+    const char *label() const noexcept
     {
         return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
     }
@@ -793,7 +788,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBaseEnumerationFieldClass&
+    CommonBaseEnumerationFieldClass
     operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonIntegerFieldClass::operator=(fc);
@@ -822,10 +817,9 @@ class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass
 private:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
-    using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
 
 public:
-    using Shared = SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
+    using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>;
     using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>;
     using Mapping = MappingT;
 
@@ -838,15 +832,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;
     }
 
@@ -856,7 +850,7 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Mapping> operator[](const char * const label) const noexcept
+    bt2s::optional<Mapping> operator[](const char * const label) const noexcept
     {
         const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
             this->libObjPtr(), label);
@@ -865,10 +859,10 @@ public:
             return Mapping {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
+    bt2s::optional<Mapping> operator[](const std::string& label) const noexcept
     {
         return (*this)[label.data()];
     }
@@ -1014,7 +1008,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClassMember<LibObjT>&
+    CommonStructureFieldClassMember<LibObjT>
     operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
@@ -1026,7 +1020,7 @@ public:
         return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
     }
 
-    bpstd::string_view name() const noexcept
+    const char *name() const noexcept
     {
         return bt_field_class_structure_member_get_name(this->libObjPtr());
     }
@@ -1144,7 +1138,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
+    CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
@@ -1194,7 +1188,7 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Member> operator[](const char * const name) const noexcept
+    bt2s::optional<Member> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr =
             internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
@@ -1203,10 +1197,10 @@ public:
             return Member {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Member> operator[](const std::string& name) const noexcept
+    bt2s::optional<Member> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -1290,7 +1284,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
+    CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
@@ -1359,7 +1353,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStaticArrayFieldClass&
+    CommonStaticArrayFieldClass
     operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
@@ -1429,7 +1423,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDynamicArrayWithLengthFieldClass&
+    CommonDynamicArrayWithLengthFieldClass
     operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
@@ -1531,7 +1525,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
+    CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
@@ -1604,7 +1598,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithSelectorFieldClass&
+    CommonOptionWithSelectorFieldClass
     operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionFieldClass::operator=(fc);
@@ -1678,7 +1672,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithBoolSelectorFieldClass&
+    CommonOptionWithBoolSelectorFieldClass
     operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
@@ -1765,12 +1759,8 @@ private:
     using typename CommonOptionWithSelectorFieldClass<
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
-    using _ThisCommonOptionWithIntegerSelectorFieldClass =
-        CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
-
 public:
-    using Shared = SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
-
+    using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>;
     using RangeSet = RangeSetT;
 
     explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
@@ -1787,7 +1777,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithIntegerSelectorFieldClass&
+    CommonOptionWithIntegerSelectorFieldClass
     operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
@@ -1916,7 +1906,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClassOption&
+    CommonVariantFieldClassOption
     operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
@@ -1928,15 +1918,9 @@ public:
         return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
-        const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_field_class_variant_option_get_name(this->libObjPtr());
     }
 
     _FieldClass fieldClass() const noexcept
@@ -2063,7 +2047,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    ConstVariantWithIntegerSelectorFieldClassOption&
+    ConstVariantWithIntegerSelectorFieldClassOption
     operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
     {
         _ThisBorrowedObject::operator=(fc);
@@ -2075,7 +2059,7 @@ public:
         return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    const char *name() const noexcept
     {
         return this->asBaseOption().name();
     }
@@ -2170,7 +2154,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
+    CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
@@ -2202,7 +2186,7 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const name) const noexcept
+    bt2s::optional<Option> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr =
             internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
@@ -2211,10 +2195,10 @@ public:
             return Option {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Option> operator[](const std::string& name) const noexcept
+    bt2s::optional<Option> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -2272,7 +2256,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithoutSelectorFieldClass&
+    CommonVariantWithoutSelectorFieldClass
     operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
@@ -2298,7 +2282,7 @@ public:
         }
     }
 
-    void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc) const
+    void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc) const
     {
         this->appendOption(name ? name->data() : nullptr, fc);
     }
@@ -2425,7 +2409,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithSelectorFieldClass&
+    CommonVariantWithSelectorFieldClass
     operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
@@ -2462,14 +2446,11 @@ 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 Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
     using Option = OptionT;
 
     using Iterator =
@@ -2489,7 +2470,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithIntegerSelectorFieldClass&
+    CommonVariantWithIntegerSelectorFieldClass
     operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
     {
         _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
@@ -2501,7 +2482,7 @@ public:
         return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const name) const noexcept
+    bt2s::optional<Option> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
 
@@ -2509,10 +2490,10 @@ public:
             return Option {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Option> operator[](const std::string& name) const noexcept
+    bt2s::optional<Option> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -2533,7 +2514,7 @@ public:
         }
     }
 
-    void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc,
+    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.029948 seconds and 4 git commands to generate.