doc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab
[babeltrace.git] / src / cpp-common / bt2 / value.hpp
index 54d33bcc5c3e0ba2991cf0f01d4a0f1f7064f6e3..9f7fdff5cc883b312e8fc71cf495d369a54507ca 100644 (file)
 
 #include "common/assert.h"
 #include "common/common.h"
-#include "cpp-common/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/vendor/wise-enum/wise_enum.h"
 
 #include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
 #include "exc.hpp"
 #include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
 #include "raw-value-proxy.hpp"
 #include "shared-object.hpp"
 
@@ -69,17 +71,19 @@ class CommonArrayValue;
 template <typename LibObjT>
 class CommonMapValue;
 
-enum class ValueType
-{
-    NUL = BT_VALUE_TYPE_NULL,
-    BOOL = BT_VALUE_TYPE_BOOL,
-    UNSIGNED_INTEGER = BT_VALUE_TYPE_UNSIGNED_INTEGER,
-    SIGNED_INTEGER = BT_VALUE_TYPE_SIGNED_INTEGER,
-    REAL = BT_VALUE_TYPE_REAL,
-    STRING = BT_VALUE_TYPE_STRING,
-    ARRAY = BT_VALUE_TYPE_ARRAY,
-    MAP = BT_VALUE_TYPE_MAP,
-};
+/* clang-format off */
+
+WISE_ENUM_CLASS(ValueType,
+    (Null, BT_VALUE_TYPE_NULL),
+    (Bool, BT_VALUE_TYPE_BOOL),
+    (UnsignedInteger, BT_VALUE_TYPE_UNSIGNED_INTEGER),
+    (SignedInteger, BT_VALUE_TYPE_SIGNED_INTEGER),
+    (Real, BT_VALUE_TYPE_REAL),
+    (String, BT_VALUE_TYPE_STRING),
+    (Array, BT_VALUE_TYPE_ARRAY),
+    (Map, BT_VALUE_TYPE_MAP));
+
+/* clang-format on */
 
 template <typename ValueObjT>
 class CommonValueRawValueProxy final
@@ -94,12 +98,12 @@ public:
     CommonValueRawValueProxy& operator=(std::uint64_t rawVal) noexcept;
     CommonValueRawValueProxy& operator=(double rawVal) noexcept;
     CommonValueRawValueProxy& operator=(const char *rawVal);
-    CommonValueRawValueProxy& operator=(const std::string& rawVal);
+    CommonValueRawValueProxy& operator=(bt2c::CStringView rawVal);
     operator bool() const noexcept;
     operator std::int64_t() const noexcept;
     operator std::uint64_t() const noexcept;
     operator double() const noexcept;
-    operator const char *() const noexcept;
+    operator bt2c::CStringView() const noexcept;
 
 private:
     ValueObjT _mObj;
@@ -112,13 +116,13 @@ private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
 
 protected:
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ThisCommonValue = CommonValue<LibObjT>;
 
 public:
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonValue<LibObjT>, LibObjT>;
 
-    explicit CommonValue(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonValue(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -241,7 +245,7 @@ public:
     }
 
     template <typename KeyT>
-    nonstd::optional<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
+    OptionalBorrowedObject<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
     {
         return this->asMap()[std::forward<KeyT>(key)];
     }
@@ -258,10 +262,8 @@ public:
         this->asMap().insert(std::forward<KeyT>(key), std::forward<ValT>(val));
     }
 
-    CommonArrayValue<bt_value> insertEmptyArray(const char *key) const;
-    CommonArrayValue<bt_value> insertEmptyArray(const std::string& key) const;
-    CommonMapValue<bt_value> insertEmptyMap(const char *key) const;
-    CommonMapValue<bt_value> insertEmptyMap(const std::string& key) const;
+    CommonArrayValue<bt_value> insertEmptyArray(bt2c::CStringView key) const;
+    CommonMapValue<bt_value> insertEmptyMap(bt2c::CStringView key) const;
 
     Shared shared() const noexcept
     {
@@ -335,9 +337,10 @@ CommonValueRawValueProxy<ValueObjT>::operator=(const char * const rawVal)
 
 template <typename ValueObjT>
 CommonValueRawValueProxy<ValueObjT>&
-CommonValueRawValueProxy<ValueObjT>::operator=(const std::string& rawVal)
+CommonValueRawValueProxy<ValueObjT>::operator=(const bt2c::CStringView rawVal)
 {
-    return *this = rawVal.data();
+    _mObj.asString().value(rawVal);
+    return *this;
 }
 
 template <typename ValueObjT>
@@ -365,7 +368,7 @@ CommonValueRawValueProxy<ValueObjT>::operator double() const noexcept
 }
 
 template <typename ValueObjT>
-CommonValueRawValueProxy<ValueObjT>::operator const char *() const noexcept
+CommonValueRawValueProxy<ValueObjT>::operator bt2c::CStringView() const noexcept
 {
     return _mObj.asString().value();
 }
@@ -453,14 +456,14 @@ template <typename LibObjT>
 class CommonBoolValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonBoolValue<LibObjT>, LibObjT>;
     using Value = bool;
 
-    explicit CommonBoolValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
+    explicit CommonBoolValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isBool());
     }
@@ -500,11 +503,12 @@ public:
         return static_cast<Value>(bt_value_bool_get(this->libObjPtr()));
     }
 
-    void value(const Value val) const noexcept
+    CommonBoolValue value(const Value val) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolValue`.");
 
         bt_value_bool_set(this->libObjPtr(), static_cast<bt_bool>(val));
+        return *this;
     }
 
     Shared shared() const noexcept
@@ -540,14 +544,14 @@ template <typename LibObjT>
 class CommonUnsignedIntegerValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonUnsignedIntegerValue<LibObjT>, LibObjT>;
     using Value = std::uint64_t;
 
-    explicit CommonUnsignedIntegerValue(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonUnsignedIntegerValue(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isUnsignedInteger());
@@ -585,12 +589,13 @@ public:
         return RawValueProxy<CommonUnsignedIntegerValue> {*this};
     }
 
-    void value(const Value val) const noexcept
+    CommonUnsignedIntegerValue value(const Value val) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value,
                       "Not available with `bt2::ConstUnsignedIntegerValue`.");
 
         bt_value_integer_unsigned_set(this->libObjPtr(), val);
+        return *this;
     }
 
     Value value() const noexcept
@@ -631,14 +636,14 @@ template <typename LibObjT>
 class CommonSignedIntegerValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonSignedIntegerValue<LibObjT>, LibObjT>;
     using Value = std::int64_t;
 
-    explicit CommonSignedIntegerValue(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonSignedIntegerValue(const LibObjPtr libObjPtr) noexcept :
         _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isSignedInteger());
@@ -676,12 +681,13 @@ public:
         return RawValueProxy<CommonSignedIntegerValue> {*this};
     }
 
-    void value(const Value val) const noexcept
+    CommonSignedIntegerValue value(const Value val) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value,
                       "Not available with `bt2::ConstSignedIntegerValue`.");
 
         bt_value_integer_signed_set(this->libObjPtr(), val);
+        return *this;
     }
 
     Value value() const noexcept
@@ -722,14 +728,14 @@ template <typename LibObjT>
 class CommonRealValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonRealValue<LibObjT>, LibObjT>;
     using Value = double;
 
-    explicit CommonRealValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
+    explicit CommonRealValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isReal());
     }
@@ -764,11 +770,12 @@ public:
         return RawValueProxy<CommonRealValue> {*this};
     }
 
-    void value(const Value val) const noexcept
+    CommonRealValue value(const Value val) const noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstRealValue`.");
 
         bt_value_real_set(this->libObjPtr(), val);
+        return *this;
     }
 
     Value value() const noexcept
@@ -809,19 +816,19 @@ template <typename LibObjT>
 class CommonStringValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonStringValue<LibObjT>, LibObjT>;
-    using Value = const char *;
+    using Value = bt2c::CStringView;
 
-    explicit CommonStringValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
+    explicit CommonStringValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isString());
     }
 
-    static Shared create(const char * const rawVal = "")
+    static Shared create(const bt2c::CStringView rawVal = "")
     {
         const auto libObjPtr = bt_value_string_create_init(rawVal);
 
@@ -829,11 +836,6 @@ public:
         return CommonStringValue::Shared::createWithoutRef(libObjPtr);
     }
 
-    static Shared create(const std::string& rawVal)
-    {
-        return CommonStringValue::create(rawVal.data());
-    }
-
     template <typename OtherLibObjT>
     CommonStringValue(const CommonStringValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
     {
@@ -851,29 +853,26 @@ public:
         return CommonStringValue<const bt_value> {*this};
     }
 
-    RawStringValueProxy<CommonStringValue> operator*() const noexcept
+    RawValueProxy<CommonStringValue> operator*() const noexcept
     {
-        return RawStringValueProxy<CommonStringValue> {*this};
+        return RawValueProxy<CommonStringValue> {*this};
     }
 
-    void value(const Value val) const
+    CommonStringValue value(const Value val) const
     {
         static_assert(!std::is_const<LibObjT>::value,
                       "Not available with `bt2::ConstStringValue`.");
 
-        const auto status = bt_value_string_set(this->libObjPtr(), val);
+        const auto status = bt_value_string_set(this->libObjPtr(), *val);
 
         if (status == BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void value(const std::string& val) const
-    {
-        this->value(val.data());
+        return *this;
     }
 
-    const char *value() const noexcept
+    Value value() const noexcept
     {
         return bt_value_string_get(this->libObjPtr());
     }
@@ -935,14 +934,14 @@ template <typename LibObjT>
 class CommonArrayValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonArrayValue<LibObjT>, LibObjT>;
     using Iterator = BorrowedObjectIterator<CommonArrayValue<LibObjT>>;
 
-    explicit CommonArrayValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
+    explicit CommonArrayValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isArray());
     }
@@ -998,16 +997,17 @@ public:
             internal::CommonArrayValueSpec<LibObjT>::elementByIndex(this->libObjPtr(), index)};
     }
 
-    void append(const Value val) const
+    CommonArrayValue append(const Value val) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
         const auto status = bt_value_array_append_element(this->libObjPtr(), val.libObjPtr());
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const bool rawVal) const
+    CommonArrayValue append(const bool rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
@@ -1015,9 +1015,10 @@ public:
             bt_value_array_append_bool_element(this->libObjPtr(), static_cast<bt_bool>(rawVal));
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const std::uint64_t rawVal) const
+    CommonArrayValue append(const std::uint64_t rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
@@ -1025,38 +1026,42 @@ public:
             bt_value_array_append_unsigned_integer_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const std::int64_t rawVal) const
+    CommonArrayValue append(const std::int64_t rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
         const auto status = bt_value_array_append_signed_integer_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const double rawVal) const
+    CommonArrayValue append(const double rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
         const auto status = bt_value_array_append_real_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const char * const rawVal) const
+    CommonArrayValue append(const char * const rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
 
         const auto status = bt_value_array_append_string_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
+        return *this;
     }
 
-    void append(const std::string& rawVal) const
+    CommonArrayValue append(const bt2c::CStringView rawVal) const
     {
-        this->append(rawVal.data());
+        return this->append(rawVal.data());
     }
 
     CommonArrayValue<bt_value> appendEmptyArray() const;
@@ -1092,7 +1097,7 @@ public:
         this->append(rawVal);
     }
 
-    void operator+=(const std::string& rawVal) const
+    void operator+=(const bt2c::CStringView rawVal) const
     {
         this->append(rawVal);
     }
@@ -1138,7 +1143,7 @@ struct TypeDescr<ConstArrayValue> : public ArrayValueTypeDescr
  * First argument is the entry's key, second is its value.
  */
 template <typename ObjT>
-using CommonMapValueForEachUserFunc = std::function<void(const char *, ObjT)>;
+using CommonMapValueForEachUserFunc = std::function<void(bt2c::CStringView, ObjT)>;
 
 /*
  * Template of a function to be passed to bt_value_map_foreach_entry()
@@ -1148,7 +1153,7 @@ using CommonMapValueForEachUserFunc = std::function<void(const char *, ObjT)>;
  * `CommonMapValueForEachUserFunc<ObjT>` (the user function to call).
  *
  * This function catches any exception which the user function throws
- * and returns the `ErrorStatus` value. If there's no execption, this
+ * and returns the `ErrorStatus` value. If there's no exception, this
  * function returns the `OkStatus` value.
  */
 template <typename ObjT, typename LibObjT, typename LibStatusT, int OkStatus, int ErrorStatus>
@@ -1239,13 +1244,13 @@ template <typename LibObjT>
 class CommonMapValue final : public CommonValue<LibObjT>
 {
 private:
-    using typename CommonValue<LibObjT>::_LibObjPtr;
     using typename CommonValue<LibObjT>::_ThisCommonValue;
 
 public:
+    using typename CommonValue<LibObjT>::LibObjPtr;
     using Shared = SharedValue<CommonMapValue<LibObjT>, LibObjT>;
 
-    explicit CommonMapValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
+    explicit CommonMapValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
         BT_ASSERT_DBG(this->isMap());
     }
@@ -1285,48 +1290,28 @@ public:
         return this->length() == 0;
     }
 
-    nonstd::optional<CommonValue<LibObjT>> operator[](const char * const key) const noexcept
-    {
-        const auto libObjPtr =
-            internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
-
-        if (!libObjPtr) {
-            return nonstd::nullopt;
-        }
-
-        return CommonValue<LibObjT> {libObjPtr};
-    }
-
-    nonstd::optional<CommonValue<LibObjT>> operator[](const std::string& key) const noexcept
+    OptionalBorrowedObject<CommonValue<LibObjT>>
+    operator[](const bt2c::CStringView key) const noexcept
     {
-        return (*this)[key.data()];
+        return internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
     }
 
-    bool hasEntry(const char * const key) const noexcept
+    bool hasEntry(const bt2c::CStringView key) const noexcept
     {
         return static_cast<bool>(bt_value_map_has_entry(this->libObjPtr(), key));
     }
 
-    bool hasEntry(const std::string& key) const noexcept
-    {
-        return this->hasEntry(key.data());
-    }
-
-    void insert(const char * const key, const Value val) const
+    CommonMapValue insert(const bt2c::CStringView key, const Value val) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
         const auto status = bt_value_map_insert_entry(this->libObjPtr(), key, val.libObjPtr());
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const std::string& key, const Value val) const
-    {
-        this->insert(key.data(), val);
-    }
-
-    void insert(const char * const key, const bool rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const bool rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
@@ -1334,14 +1319,10 @@ public:
             bt_value_map_insert_bool_entry(this->libObjPtr(), key, static_cast<bt_bool>(rawVal));
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const std::string& key, const bool rawVal) const
-    {
-        this->insert(key.data(), rawVal);
-    }
-
-    void insert(const char * const key, const std::uint64_t rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const std::uint64_t rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
@@ -1349,14 +1330,10 @@ public:
             bt_value_map_insert_unsigned_integer_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const std::string& key, const std::uint64_t rawVal) const
-    {
-        this->insert(key.data(), rawVal);
-    }
-
-    void insert(const char * const key, const std::int64_t rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const std::int64_t rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
@@ -1364,59 +1341,42 @@ public:
             bt_value_map_insert_signed_integer_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const std::string& key, const std::int64_t rawVal) const
-    {
-        this->insert(key.data(), rawVal);
-    }
-
-    void insert(const char * const key, const double rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const double rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
         const auto status = bt_value_map_insert_real_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const std::string& key, const double rawVal) const
-    {
-        this->insert(key.data(), rawVal);
-    }
-
-    void insert(const char * const key, const char * const rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const char *rawVal) const
     {
         static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
         const auto status = bt_value_map_insert_string_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
+        return *this;
     }
 
-    void insert(const char * const key, const std::string& rawVal) const
-    {
-        this->insert(key, rawVal.data());
-    }
-
-    void insert(const std::string& key, const char * const rawVal) const
-    {
-        this->insert(key.data(), rawVal);
-    }
-
-    void insert(const std::string& key, const std::string& rawVal) const
+    CommonMapValue insert(const bt2c::CStringView key, const bt2c::CStringView rawVal) const
     {
-        this->insert(key.data(), rawVal.data());
+        return this->insert(key, rawVal.data());
     }
 
-    CommonArrayValue<bt_value> insertEmptyArray(const char *key) const;
-    CommonArrayValue<bt_value> insertEmptyArray(const std::string& key) const;
-    CommonMapValue<bt_value> insertEmptyMap(const char *key) const;
-    CommonMapValue<bt_value> insertEmptyMap(const std::string& key) const;
+    CommonArrayValue<bt_value> insertEmptyArray(bt2c::CStringView key) const;
+    CommonMapValue<bt_value> insertEmptyMap(bt2c::CStringView key) const;
 
-    void forEach(const internal::CommonMapValueForEachUserFunc<CommonValue<LibObjT>>& func) const
+    CommonMapValue
+    forEach(const internal::CommonMapValueForEachUserFunc<CommonValue<LibObjT>>& func) const
     {
         internal::CommonMapValueSpec<LibObjT>::forEach(this->libObjPtr(), func);
+        return *this;
     }
 
     Shared shared() const noexcept
@@ -1469,25 +1429,13 @@ MapValue CommonValue<LibObjT>::appendEmptyMap() const
 }
 
 template <typename LibObjT>
-ArrayValue CommonValue<LibObjT>::insertEmptyArray(const char * const key) const
-{
-    return this->asMap().insertEmptyArray(key);
-}
-
-template <typename LibObjT>
-ArrayValue CommonValue<LibObjT>::insertEmptyArray(const std::string& key) const
+ArrayValue CommonValue<LibObjT>::insertEmptyArray(const bt2c::CStringView key) const
 {
     return this->asMap().insertEmptyArray(key);
 }
 
 template <typename LibObjT>
-MapValue CommonValue<LibObjT>::insertEmptyMap(const char * const key) const
-{
-    return this->asMap().insertEmptyMap(key);
-}
-
-template <typename LibObjT>
-MapValue CommonValue<LibObjT>::insertEmptyMap(const std::string& key) const
+MapValue CommonValue<LibObjT>::insertEmptyMap(const bt2c::CStringView key) const
 {
     return this->asMap().insertEmptyMap(key);
 }
@@ -1496,55 +1444,48 @@ template <typename LibObjT>
 CommonNullValue<LibObjT> CommonValue<LibObjT>::asNull() const noexcept
 {
     BT_ASSERT_DBG(this->isNull());
-    return CommonNullValue<LibObjT> {this->libObjPtr()};
+    return CommonNullValue<LibObjT> {};
 }
 
 template <typename LibObjT>
 CommonBoolValue<LibObjT> CommonValue<LibObjT>::asBool() const noexcept
 {
-    BT_ASSERT_DBG(this->isBool());
     return CommonBoolValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedIntegerValue<LibObjT> CommonValue<LibObjT>::asSignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isSignedInteger());
     return CommonSignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedIntegerValue<LibObjT> CommonValue<LibObjT>::asUnsignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isUnsignedInteger());
     return CommonUnsignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonRealValue<LibObjT> CommonValue<LibObjT>::asReal() const noexcept
 {
-    BT_ASSERT_DBG(this->isReal());
     return CommonRealValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStringValue<LibObjT> CommonValue<LibObjT>::asString() const noexcept
 {
-    BT_ASSERT_DBG(this->isString());
     return CommonStringValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayValue<LibObjT> CommonValue<LibObjT>::asArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isArray());
     return CommonArrayValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonMapValue<LibObjT> CommonValue<LibObjT>::asMap() const noexcept
 {
-    BT_ASSERT_DBG(this->isMap());
     return CommonMapValue<LibObjT> {this->libObjPtr()};
 }
 
@@ -1573,7 +1514,7 @@ MapValue CommonArrayValue<LibObjT>::appendEmptyMap() const
 }
 
 template <typename LibObjT>
-ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const char * const key) const
+ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const bt2c::CStringView key) const
 {
     static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
@@ -1585,13 +1526,7 @@ ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const char * const key) con
 }
 
 template <typename LibObjT>
-ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const std::string& key) const
-{
-    return this->insertEmptyArray(key.data());
-}
-
-template <typename LibObjT>
-MapValue CommonMapValue<LibObjT>::insertEmptyMap(const char * const key) const
+MapValue CommonMapValue<LibObjT>::insertEmptyMap(const bt2c::CStringView key) const
 {
     static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
 
@@ -1602,12 +1537,6 @@ MapValue CommonMapValue<LibObjT>::insertEmptyMap(const char * const key) const
     return MapValue {libEntryPtr};
 }
 
-template <typename LibObjT>
-MapValue CommonMapValue<LibObjT>::insertEmptyMap(const std::string& key) const
-{
-    return this->insertEmptyMap(key.data());
-}
-
 inline BoolValue::Shared createValue(const bool rawVal)
 {
     return BoolValue::create(rawVal);
@@ -1633,7 +1562,7 @@ inline StringValue::Shared createValue(const char * const rawVal)
     return StringValue::create(rawVal);
 }
 
-inline StringValue::Shared createValue(const std::string& rawVal)
+inline StringValue::Shared createValue(const bt2c::CStringView rawVal)
 {
     return StringValue::create(rawVal);
 }
This page took 0.033739 seconds and 4 git commands to generate.