#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
-#include "cpp-common/bt2s/optional.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
#include "borrowed-object.hpp"
#include "field-class.hpp"
#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
#include "raw-value-proxy.hpp"
namespace bt2 {
return RawValueProxy<CommonBoolField> {*this};
}
- void value(const Value val) const noexcept
+ CommonBoolField 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));
+ return *this;
}
Value value() const noexcept
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- void valueAsInteger(const std::uint64_t bits) const noexcept
+ CommonBitArrayField 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);
+ return *this;
}
std::uint64_t valueAsInteger() const noexcept
return RawValueProxy<CommonUnsignedIntegerField> {*this};
}
- void value(const Value val) const noexcept
+ CommonUnsignedIntegerField 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);
+ return *this;
}
Value value() const noexcept
return RawValueProxy<CommonSignedIntegerField> {*this};
}
- void value(const Value val) const noexcept
+ CommonSignedIntegerField 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);
+ return *this;
}
Value value() const noexcept
return _mLen;
}
- const char *operator[](const std::uint64_t index) const noexcept
+ bt2c::CStringView operator[](const std::uint64_t index) const noexcept
{
return _mLabels[index];
}
return RawValueProxy<CommonSinglePrecisionRealField> {*this};
}
- void value(const Value val) const noexcept
+ CommonSinglePrecisionRealField 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);
+ return *this;
}
Value value() const noexcept
return RawValueProxy<CommonDoublePrecisionRealField> {*this};
}
- void value(const Value val) const noexcept
+ CommonDoublePrecisionRealField 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);
+ return *this;
}
Value value() const noexcept
public:
using typename CommonField<LibObjT>::LibObjPtr;
- using Value = const char *;
+ using Value = bt2c::CStringView;
explicit CommonStringField(const LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
{
return CommonStringField<const bt_field> {*this};
}
- RawStringValueProxy<CommonStringField> operator*() const noexcept
+ RawValueProxy<CommonStringField> operator*() const noexcept
{
- return RawStringValueProxy<CommonStringField> {*this};
+ return RawValueProxy<CommonStringField> {*this};
}
- void value(const char * const val) const
+ CommonStringField value(const Value val) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
- const auto status = bt_field_string_set_value(this->libObjPtr(), val);
+ const auto status = bt_field_string_set_value(this->libObjPtr(), *val);
if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
- }
- void value(const std::string& val) const
- {
- this->value(val.data());
+ return *this;
}
- void append(const char * const begin, const std::uint64_t len) const
+ CommonStringField append(const bt2c::CStringView begin, const std::uint64_t len) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
if (status == BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
+
+ return *this;
+ }
+
+ CommonStringField append(const bt2c::CStringView val) const
+ {
+ return this->append(val, std::strlen(val));
}
- void append(const std::string& val) const
+ CommonStringField append(const std::string& val) const
{
- this->append(val.data(), val.size());
+ return this->append(val.data(), val.size());
}
- void clear() const noexcept
+ CommonStringField clear() const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstStringField`.");
bt_field_string_clear(this->libObjPtr());
+ return *this;
}
- const char *value() const noexcept
+ Value value() const noexcept
{
return bt_field_string_get_value(this->libObjPtr());
}
+
+ std::uint64_t length() const noexcept
+ {
+ return bt_field_string_get_length(this->libObjPtr());
+ }
};
using StringField = CommonStringField<bt_field>;
return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
}
- bt2s::optional<CommonField<LibObjT>> operator[](const char * const name) const noexcept
- {
- const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
-
- if (libObjPtr) {
- return CommonField<LibObjT> {libObjPtr};
- }
-
- return bt2s::nullopt;
- }
-
- bt2s::optional<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>>
+ operator[](const bt2c::CStringView name) const noexcept
{
- return (*this)[name.data()];
+ return _Spec::memberFieldByName(this->libObjPtr(), name);
}
};
return _ThisCommonArrayField::length();
}
- void length(const std::uint64_t length) const
+ CommonDynamicArrayField length(const std::uint64_t length) const
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstDynamicArrayField`.");
if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) {
throw MemoryError {};
}
+
+ return *this;
}
};
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- void hasField(const bool hasField) const noexcept
+ CommonOptionField hasField(const bool hasField) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstOptionField`.");
bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField));
+ return *this;
}
bool hasField() const noexcept
{
- return this->field().has_value();
+ return this->field();
}
- bt2s::optional<CommonField<LibObjT>> field() const noexcept
+ OptionalBorrowedObject<CommonField<LibObjT>> field() const noexcept
{
- const auto libObjPtr = _Spec::field(this->libObjPtr());
-
- if (libObjPtr) {
- return CommonField<LibObjT> {libObjPtr};
- }
-
- return bt2s::nullopt;
+ return _Spec::field(this->libObjPtr());
}
};
return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
}
- void selectOption(const std::uint64_t index) const noexcept
+ CommonVariantField selectOption(const std::uint64_t index) const noexcept
{
static_assert(!std::is_const<LibObjT>::value,
"Not available with `bt2::ConstVariantField`.");
- static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index));
+ const auto status = bt_field_variant_select_option_by_index(this->libObjPtr(), index);
+
+ BT_ASSERT_DBG(status == BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK);
+ return *this;
}
CommonField<LibObjT> selectedOptionField() const noexcept
template <typename LibObjT>
CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept
{
- BT_ASSERT_DBG(this->isBool());
return CommonBoolField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept
{
- BT_ASSERT_DBG(this->isBitArray());
return CommonBitArrayField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept
{
- BT_ASSERT_DBG(this->isUnsignedInteger());
return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept
{
- BT_ASSERT_DBG(this->isSignedInteger());
return CommonSignedIntegerField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept
{
- BT_ASSERT_DBG(this->isUnsignedEnumeration());
return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept
{
- BT_ASSERT_DBG(this->isSignedEnumeration());
return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept
{
- BT_ASSERT_DBG(this->isSinglePrecisionReal());
return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept
{
- BT_ASSERT_DBG(this->isDoublePrecisionReal());
return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept
{
- BT_ASSERT_DBG(this->isString());
return CommonStringField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept
{
- BT_ASSERT_DBG(this->isStructure());
return CommonStructureField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept
{
- BT_ASSERT_DBG(this->isArray());
return CommonArrayField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept
{
- BT_ASSERT_DBG(this->isDynamicArray());
return CommonDynamicArrayField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept
{
- BT_ASSERT_DBG(this->isOption());
return CommonOptionField<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept
{
- BT_ASSERT_DBG(this->isVariant());
return CommonVariantField<LibObjT> {this->libObjPtr()};
}