X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Ffield.hpp;fp=src%2Fcpp-common%2Fbt2%2Ffield.hpp;h=b69295b250c67c6f576cb924e5b97b4bd147d0e7;hb=7f7fbdb3f53e75d7c5fcdab092ebc819984ee499;hp=aa160289b4f686dcece5ba000dd78590429e4688;hpb=b3f060ed119961106d34da4db9071653a37f5c53;p=babeltrace.git diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index aa160289..b69295b2 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -19,6 +19,7 @@ #include "borrowed-object.hpp" #include "field-class.hpp" #include "internal/utils.hpp" +#include "raw-value-proxy.hpp" namespace bt2 { @@ -282,23 +283,22 @@ public: return CommonBoolField {*this}; } - CommonBoolField operator=(const Value val) const noexcept + RawValueProxy operator*() const noexcept + { + return RawValueProxy {*this}; + } + + void value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstBoolField`."); bt_field_bool_set_value(this->libObjPtr(), static_cast(val)); - return *this; } Value value() const noexcept { return static_cast(bt_field_bool_get_value(this->libObjPtr())); } - - operator Value() const noexcept - { - return this->value(); - } }; using BoolField = CommonBoolField; @@ -368,13 +368,12 @@ public: return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; } - CommonBitArrayField operator=(const std::uint64_t bits) const noexcept + void valueAsInteger(const std::uint64_t bits) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstBitArrayField`."); bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits); - return *this; } std::uint64_t valueAsInteger() const noexcept @@ -456,24 +455,23 @@ public: return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; } - CommonUnsignedIntegerField operator=(const Value val) const noexcept + RawValueProxy operator*() const noexcept + { + return RawValueProxy {*this}; + } + + void value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstUnsignedIntegerField`."); bt_field_integer_unsigned_set_value(this->libObjPtr(), val); - return *this; } Value value() const noexcept { return bt_field_integer_unsigned_get_value(this->libObjPtr()); } - - operator Value() const noexcept - { - return this->value(); - } }; using UnsignedIntegerField = CommonUnsignedIntegerField; @@ -543,24 +541,23 @@ public: return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; } - CommonSignedIntegerField operator=(const Value val) const noexcept + RawValueProxy operator*() const noexcept + { + return RawValueProxy {*this}; + } + + void value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstSignedIntegerField`."); bt_field_integer_signed_set_value(this->libObjPtr(), val); - return *this; } Value value() const noexcept { return bt_field_integer_signed_get_value(this->libObjPtr()); } - - operator Value() const noexcept - { - return this->value(); - } }; using SignedIntegerField = CommonSignedIntegerField; @@ -654,8 +651,6 @@ public: return CommonUnsignedEnumerationField {*this}; } - using CommonUnsignedIntegerField::operator=; - Class cls() const noexcept { return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; @@ -735,8 +730,6 @@ public: return CommonSignedEnumerationField {*this}; } - using CommonSignedIntegerField::operator=; - Class cls() const noexcept { return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; @@ -816,24 +809,23 @@ public: return CommonSinglePrecisionRealField {*this}; } - CommonSinglePrecisionRealField operator=(const Value val) const noexcept + RawValueProxy operator*() const noexcept + { + return RawValueProxy {*this}; + } + + void value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstSinglePrecisionRealField`."); bt_field_real_single_precision_set_value(this->libObjPtr(), val); - return *this; } Value value() const noexcept { return bt_field_real_single_precision_get_value(this->libObjPtr()); } - - operator Value() const noexcept - { - return this->value(); - } }; using SinglePrecisionRealField = CommonSinglePrecisionRealField; @@ -895,24 +887,23 @@ public: return CommonDoublePrecisionRealField {*this}; } - CommonDoublePrecisionRealField operator=(const Value val) const noexcept + RawValueProxy operator*() const noexcept + { + return RawValueProxy {*this}; + } + + void value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstDoublePrecisionRealField`."); bt_field_real_double_precision_set_value(this->libObjPtr(), val); - return *this; } Value value() const noexcept { return bt_field_real_double_precision_get_value(this->libObjPtr()); } - - operator Value() const noexcept - { - return this->value(); - } }; using DoublePrecisionRealField = CommonDoublePrecisionRealField; @@ -946,6 +937,8 @@ private: using typename CommonField::_ThisCommonField; public: + using Value = const char *; + explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} { BT_ASSERT_DBG(this->isString()); @@ -968,7 +961,12 @@ public: return CommonStringField {*this}; } - CommonStringField operator=(const char * const val) const + RawStringValueProxy operator*() const noexcept + { + return RawStringValueProxy {*this}; + } + + void value(const char * const val) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStringField`."); @@ -978,13 +976,11 @@ public: if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) { throw MemoryError {}; } - - return *this; } - CommonStringField operator=(const std::string& val) const + void value(const std::string& val) const { - return *this = val.data(); + this->value(val.data()); } void append(const char * const begin, const std::uint64_t len) const @@ -1012,7 +1008,7 @@ public: bt_field_string_clear(this->libObjPtr()); } - bpstd::string_view value() const noexcept + const char *value() const noexcept { return bt_field_string_get_value(this->libObjPtr()); }