X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fvalue.hpp;h=81c033673f8b70d72c056e7dc5c0c4ed2094d54e;hb=e74015680521597497c3218160a9e80081932896;hp=4dc4019a8677ffab3d36f35043217331eddbcc05;hpb=ca61ecbc0d9d2d64cc3b6a02d118e4ee87477cf6;p=babeltrace.git diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index 4dc4019a..81c03367 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -15,6 +15,7 @@ #include "common/assert.h" #include "common/common.h" +#include "cpp-common/bt2c/c-string-view.hpp" #include "borrowed-object-iterator.hpp" #include "borrowed-object.hpp" @@ -100,6 +101,7 @@ public: operator std::uint64_t() const noexcept; operator double() const noexcept; operator const char *() const noexcept; + operator bt2c::CStringView() const noexcept; private: ValueObjT _mObj; @@ -337,7 +339,8 @@ template CommonValueRawValueProxy& CommonValueRawValueProxy::operator=(const std::string& rawVal) { - return *this = rawVal.data(); + _mObj.asString().value(rawVal); + return *this; } template @@ -370,6 +373,12 @@ CommonValueRawValueProxy::operator const char *() const noexcept return _mObj.asString().value(); } +template +CommonValueRawValueProxy::operator bt2c::CStringView() const noexcept +{ + return _mObj.asString().value(); +} + namespace internal { struct ValueTypeDescr @@ -814,7 +823,7 @@ private: public: using typename CommonValue::LibObjPtr; using Shared = SharedValue, LibObjT>; - using Value = const char *; + using Value = bt2c::CStringView; explicit CommonStringValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr} { @@ -861,19 +870,24 @@ public: static_assert(!std::is_const::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 char * const val) const + { + this->value(bt2c::CStringView {val}); + } + void value(const std::string& val) const { - this->value(val.data()); + this->value(bt2c::CStringView {val.data()}); } - const char *value() const noexcept + Value value() const noexcept { return bt_value_string_get(this->libObjPtr()); } @@ -1138,7 +1152,7 @@ struct TypeDescr : public ArrayValueTypeDescr * First argument is the entry's key, second is its value. */ template -using CommonMapValueForEachUserFunc = std::function; +using CommonMapValueForEachUserFunc = std::function; /* * Template of a function to be passed to bt_value_map_foreach_entry() @@ -1148,7 +1162,7 @@ using CommonMapValueForEachUserFunc = std::function; * `CommonMapValueForEachUserFunc` (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