This patch makes field wrappers behave like value wrappers regarding
raw value access.
Now, the `*` operator of boolean, integer, floating point number, and
string fields return a raw value proxy to access the raw value:
void f(const bt2::UnsignedIntegerField val) {
*val = 23;
std::cout << *val << std::endl;
}
I didn't do it for `bt2::CommonBitArrayField` which is a scalar field,
but it's still an array, so it felt weird. Instead, use valueAsInteger()
or bitValue() depending on your use case.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3bbcdc79a6dea781f720b7da8e18aea285d792b5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11371
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "internal/utils.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "internal/utils.hpp"
+#include "raw-value-proxy.hpp"
return CommonBoolField<const bt_field> {*this};
}
return CommonBoolField<const bt_field> {*this};
}
- CommonBoolField<LibObjT> operator=(const Value val) const noexcept
+ RawValueProxy<CommonBoolField> operator*() const noexcept
+ {
+ return RawValueProxy<CommonBoolField> {*this};
+ }
+
+ void value(const Value val) const noexcept
{
static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolField`.");
bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
{
static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolField`.");
bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
}
Value value() const noexcept
{
return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
}
}
Value value() const noexcept
{
return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
}
-
- operator Value() const noexcept
- {
- return this->value();
- }
};
using BoolField = CommonBoolField<bt_field>;
};
using BoolField = CommonBoolField<bt_field>;
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- CommonBitArrayField<LibObjT> operator=(const std::uint64_t bits) const noexcept
+ void valueAsInteger(const std::uint64_t bits) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstBitArrayField`.");
bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits);
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstBitArrayField`.");
bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits);
}
std::uint64_t valueAsInteger() const noexcept
}
std::uint64_t valueAsInteger() const noexcept
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- CommonUnsignedIntegerField<LibObjT> operator=(const Value val) const noexcept
+ RawValueProxy<CommonUnsignedIntegerField> operator*() const noexcept
+ {
+ return RawValueProxy<CommonUnsignedIntegerField> {*this};
+ }
+
+ void value(const Value val) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstUnsignedIntegerField`.");
bt_field_integer_unsigned_set_value(this->libObjPtr(), val);
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstUnsignedIntegerField`.");
bt_field_integer_unsigned_set_value(this->libObjPtr(), val);
}
Value value() const noexcept
{
return bt_field_integer_unsigned_get_value(this->libObjPtr());
}
}
Value value() const noexcept
{
return bt_field_integer_unsigned_get_value(this->libObjPtr());
}
-
- operator Value() const noexcept
- {
- return this->value();
- }
};
using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>;
};
using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>;
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- CommonSignedIntegerField<LibObjT> operator=(const Value val) const noexcept
+ RawValueProxy<CommonSignedIntegerField> operator*() const noexcept
+ {
+ return RawValueProxy<CommonSignedIntegerField> {*this};
+ }
+
+ void value(const Value val) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstSignedIntegerField`.");
bt_field_integer_signed_set_value(this->libObjPtr(), val);
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstSignedIntegerField`.");
bt_field_integer_signed_set_value(this->libObjPtr(), val);
}
Value value() const noexcept
{
return bt_field_integer_signed_get_value(this->libObjPtr());
}
}
Value value() const noexcept
{
return bt_field_integer_signed_get_value(this->libObjPtr());
}
-
- operator Value() const noexcept
- {
- return this->value();
- }
};
using SignedIntegerField = CommonSignedIntegerField<bt_field>;
};
using SignedIntegerField = CommonSignedIntegerField<bt_field>;
return CommonUnsignedEnumerationField<const bt_field> {*this};
}
return CommonUnsignedEnumerationField<const bt_field> {*this};
}
- using CommonUnsignedIntegerField<LibObjT>::operator=;
-
Class cls() const noexcept
{
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
Class cls() const noexcept
{
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
return CommonSignedEnumerationField<const bt_field> {*this};
}
return CommonSignedEnumerationField<const bt_field> {*this};
}
- using CommonSignedIntegerField<LibObjT>::operator=;
-
Class cls() const noexcept
{
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
Class cls() const noexcept
{
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
return CommonSinglePrecisionRealField<const bt_field> {*this};
}
return CommonSinglePrecisionRealField<const bt_field> {*this};
}
- CommonSinglePrecisionRealField<LibObjT> operator=(const Value val) const noexcept
+ RawValueProxy<CommonSinglePrecisionRealField> operator*() const noexcept
+ {
+ return RawValueProxy<CommonSinglePrecisionRealField> {*this};
+ }
+
+ void value(const Value val) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstSinglePrecisionRealField`.");
bt_field_real_single_precision_set_value(this->libObjPtr(), val);
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstSinglePrecisionRealField`.");
bt_field_real_single_precision_set_value(this->libObjPtr(), val);
}
Value value() const noexcept
{
return bt_field_real_single_precision_get_value(this->libObjPtr());
}
}
Value value() const noexcept
{
return bt_field_real_single_precision_get_value(this->libObjPtr());
}
-
- operator Value() const noexcept
- {
- return this->value();
- }
};
using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>;
};
using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>;
return CommonDoublePrecisionRealField<const bt_field> {*this};
}
return CommonDoublePrecisionRealField<const bt_field> {*this};
}
- CommonDoublePrecisionRealField<LibObjT> operator=(const Value val) const noexcept
+ RawValueProxy<CommonDoublePrecisionRealField> operator*() const noexcept
+ {
+ return RawValueProxy<CommonDoublePrecisionRealField> {*this};
+ }
+
+ void value(const Value val) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstDoublePrecisionRealField`.");
bt_field_real_double_precision_set_value(this->libObjPtr(), val);
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstDoublePrecisionRealField`.");
bt_field_real_double_precision_set_value(this->libObjPtr(), val);
}
Value value() const noexcept
{
return bt_field_real_double_precision_get_value(this->libObjPtr());
}
}
Value value() const noexcept
{
return bt_field_real_double_precision_get_value(this->libObjPtr());
}
-
- operator Value() const noexcept
- {
- return this->value();
- }
};
using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>;
};
using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>;
using typename CommonField<LibObjT>::_ThisCommonField;
public:
using typename CommonField<LibObjT>::_ThisCommonField;
public:
+ using Value = const char *;
+
explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
{
BT_ASSERT_DBG(this->isString());
explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
{
BT_ASSERT_DBG(this->isString());
return CommonStringField<const bt_field> {*this};
}
return CommonStringField<const bt_field> {*this};
}
- CommonStringField<LibObjT> operator=(const char * const val) const
+ RawStringValueProxy<CommonStringField> operator*() const noexcept
+ {
+ return RawStringValueProxy<CommonStringField> {*this};
+ }
+
+ void value(const char * const val) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
- CommonStringField<LibObjT> 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
}
void append(const char * const begin, const std::uint64_t len) const
bt_field_string_clear(this->libObjPtr());
}
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());
}
{
return bt_field_string_get_value(this->libObjPtr());
}