From: Simon Marchi Date: Thu, 29 Feb 2024 18:50:00 +0000 (-0500) Subject: cpp-common/bt2: make setters return `*this` X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=2a24eba8b45ab4bd62dfb2cd95f31e4c2a7a91a8;p=babeltrace.git cpp-common/bt2: make setters return `*this` Change setters (and other methods currently returning `void`) to return `*this`. This allows writing more compact code and avoid intermediate variables, like: return graph->addComponent( *dummySinkCompCls, "the-sink", bt2::MapValue::create()->insert("key1", "val1").insert("key2", "val2")); It doesn't always produce super readable code, but it's nice to have the option. In sub-classes of `BorrowedObject`, the methods return by value. `ConstMessageArray::append` returns by reference. Change-Id: I5af80c96b4c947dc217f4dff4b0bcb31885005e8 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11951 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index f9814a78..e8780c38 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -119,11 +119,12 @@ public: return CommonClockClass {*this}; } - void frequency(const std::uint64_t frequency) const noexcept + CommonClockClass frequency(const std::uint64_t frequency) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_frequency(this->libObjPtr(), frequency); + return *this; } std::uint64_t frequency() const noexcept @@ -131,12 +132,13 @@ public: return bt_clock_class_get_frequency(this->libObjPtr()); } - void offsetFromOrigin(const ClockOffset& offsetFromOrigin) const noexcept + CommonClockClass offsetFromOrigin(const ClockOffset& offsetFromOrigin) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_offset(this->libObjPtr(), offsetFromOrigin.seconds(), offsetFromOrigin.cycles()); + return *this; } ClockOffset offsetFromOrigin() const noexcept @@ -148,11 +150,12 @@ public: return ClockOffset {seconds, cycles}; } - void precision(const std::uint64_t precision) const noexcept + CommonClockClass precision(const std::uint64_t precision) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_precision(this->libObjPtr(), precision); + return *this; } std::uint64_t precision() const noexcept @@ -160,12 +163,13 @@ public: return bt_clock_class_get_precision(this->libObjPtr()); } - void originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept + CommonClockClass originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_origin_is_unix_epoch(this->libObjPtr(), static_cast(originIsUnixEpoch)); + return *this; } bool originIsUnixEpoch() const noexcept @@ -173,7 +177,7 @@ public: return static_cast(bt_clock_class_origin_is_unix_epoch(this->libObjPtr())); } - void name(const bt2c::CStringView name) const + CommonClockClass name(const bt2c::CStringView name) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); @@ -182,6 +186,8 @@ public: if (status == BT_CLOCK_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView name() const noexcept @@ -189,7 +195,7 @@ public: return bt_clock_class_get_name(this->libObjPtr()); } - void description(const bt2c::CStringView description) const + CommonClockClass description(const bt2c::CStringView description) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); @@ -198,6 +204,8 @@ public: if (status == BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView description() const noexcept @@ -205,9 +213,10 @@ public: return bt_clock_class_get_description(this->libObjPtr()); } - void uuid(const std::uint8_t * const uuid) const noexcept + CommonClockClass uuid(const std::uint8_t * const uuid) const noexcept { bt_clock_class_set_uuid(this->libObjPtr(), uuid); + return *this; } bt2s::optional uuid() const noexcept @@ -222,11 +231,12 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonClockClass userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); bt_clock_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 857c33a7..411cf669 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -402,11 +402,12 @@ public: asVariantWithSignedIntegerSelector() const noexcept; template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonFieldClass userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstFieldClass`."); bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -564,12 +565,13 @@ public: return CommonIntegerFieldClass {*this}; } - void fieldValueRange(const std::uint64_t n) const noexcept + CommonIntegerFieldClass fieldValueRange(const std::uint64_t n) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstIntegerFieldClass`."); bt_field_class_integer_set_field_value_range(this->libObjPtr(), n); + return *this; } std::uint64_t fieldValueRange() const noexcept @@ -577,13 +579,14 @@ public: return bt_field_class_integer_get_field_value_range(this->libObjPtr()); } - void preferredDisplayBase(const DisplayBase base) const noexcept + CommonIntegerFieldClass preferredDisplayBase(const DisplayBase base) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstIntegerFieldClass`."); bt_field_class_integer_set_preferred_display_base( this->libObjPtr(), static_cast(base)); + return *this; } DisplayBase preferredDisplayBase() const noexcept @@ -859,7 +862,8 @@ public: this->libObjPtr(), label); } - void addMapping(const bt2c::CStringView label, const typename Mapping::RangeSet ranges) const + CommonEnumerationFieldClass addMapping(const bt2c::CStringView label, + const typename Mapping::RangeSet ranges) const { const auto status = internal::CommonEnumerationFieldClassSpec::addMapping( this->libObjPtr(), label, ranges.libObjPtr()); @@ -867,6 +871,8 @@ public: if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } Iterator begin() const noexcept @@ -1019,13 +1025,15 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonStructureFieldClassMember + userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStructureFieldClassMember`."); bt_field_class_structure_member_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -1136,7 +1144,7 @@ public: return CommonStructureFieldClass {*this}; } - void appendMember(const bt2c::CStringView name, const FieldClass fc) const + CommonStructureFieldClass appendMember(const bt2c::CStringView name, const FieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStructureFieldClass`."); @@ -1147,6 +1155,8 @@ public: if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } std::uint64_t length() const noexcept @@ -1899,12 +1909,14 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonVariantFieldClassOption + userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstVariantFieldClassOption`."); bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -2227,7 +2239,8 @@ public: return CommonVariantWithoutSelectorFieldClass {*this}; } - void appendOption(const char * const name, const FieldClass fc) const + CommonVariantWithoutSelectorFieldClass appendOption(const char * const name, + const FieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`."); @@ -2239,16 +2252,20 @@ public: BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void appendOption(const bt2c::CStringView name, const FieldClass fc) const + CommonVariantWithoutSelectorFieldClass appendOption(const bt2c::CStringView name, + const FieldClass fc) const { return this->appendOption(name.data(), fc); } - void appendOption(const bt2s::optional& name, const FieldClass fc) const + CommonVariantWithoutSelectorFieldClass appendOption(const bt2s::optional& name, + const FieldClass fc) const { - this->appendOption(name ? name->data() : nullptr, fc); + return this->appendOption(name ? name->data() : nullptr, fc); } Shared shared() const noexcept @@ -2451,8 +2468,9 @@ public: return _Spec::optionByName(this->libObjPtr(), name); } - void appendOption(const char * const name, const FieldClass fc, - const typename Option::RangeSet ranges) const + CommonVariantWithIntegerSelectorFieldClass + appendOption(const char * const name, const FieldClass fc, + const typename Option::RangeSet ranges) const { static_assert( !std::is_const::value, @@ -2465,18 +2483,22 @@ public: BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void appendOption(const bt2c::CStringView name, const FieldClass fc, - const typename Option::RangeSet ranges) const + CommonVariantWithIntegerSelectorFieldClass + appendOption(const bt2c::CStringView name, const FieldClass fc, + const typename Option::RangeSet ranges) const { return this->appendOption(name.data(), fc, ranges); } - void appendOption(const bt2s::optional& name, const FieldClass fc, - const typename Option::RangeSet ranges) const + CommonVariantWithIntegerSelectorFieldClass + appendOption(const bt2s::optional& name, const FieldClass fc, + const typename Option::RangeSet ranges) const { - this->appendOption(name ? name->data() : nullptr, fc, ranges); + return this->appendOption(name ? name->data() : nullptr, fc, ranges); } Iterator begin() const noexcept diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index bf470e0b..05e1c244 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -288,11 +288,12 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonBoolField 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 @@ -368,12 +369,13 @@ public: return Class {internal::CommonFieldSpec::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::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 @@ -460,12 +462,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonUnsignedIntegerField 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 @@ -546,12 +549,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonSignedIntegerField 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 @@ -810,12 +814,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonSinglePrecisionRealField 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 @@ -888,12 +893,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonDoublePrecisionRealField 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 @@ -962,7 +968,7 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const + CommonStringField value(const Value val) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStringField`."); @@ -972,9 +978,11 @@ public: if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void append(const bt2c::CStringView begin, const std::uint64_t len) const + CommonStringField append(const bt2c::CStringView begin, const std::uint64_t len) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStringField`."); @@ -984,24 +992,27 @@ public: if (status == BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void append(const bt2c::CStringView val) const + CommonStringField append(const bt2c::CStringView val) const { - this->append(val, std::strlen(val)); + 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::value, "Not available with `bt2::ConstStringField`."); bt_field_string_clear(this->libObjPtr()); + return *this; } Value value() const noexcept @@ -1292,7 +1303,7 @@ public: return _ThisCommonArrayField::length(); } - void length(const std::uint64_t length) const + CommonDynamicArrayField length(const std::uint64_t length) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstDynamicArrayField`."); @@ -1302,6 +1313,8 @@ public: if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } }; @@ -1389,12 +1402,13 @@ public: return Class {internal::CommonFieldSpec::cls(this->libObjPtr())}; } - void hasField(const bool hasField) const noexcept + CommonOptionField hasField(const bool hasField) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstOptionField`."); bt_field_option_set_has_field(this->libObjPtr(), static_cast(hasField)); + return *this; } bool hasField() const noexcept @@ -1492,7 +1506,7 @@ public: return Class {internal::CommonFieldSpec::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::value, "Not available with `bt2::ConstVariantField`."); @@ -1500,6 +1514,7 @@ public: 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 selectedOptionField() const noexcept diff --git a/src/cpp-common/bt2/graph.hpp b/src/cpp-common/bt2/graph.hpp index 787888af..63199bf7 100644 --- a/src/cpp-common/bt2/graph.hpp +++ b/src/cpp-common/bt2/graph.hpp @@ -117,7 +117,7 @@ public: bt_graph_add_sink_component_with_initialize_method_data); } - void connectPorts(const ConstOutputPort outputPort, const ConstInputPort inputPort) const + Graph connectPorts(const ConstOutputPort outputPort, const ConstInputPort inputPort) const { const auto status = bt_graph_connect_ports(this->libObjPtr(), outputPort.libObjPtr(), inputPort.libObjPtr(), nullptr); @@ -127,9 +127,11 @@ public: } else if (status == BT_GRAPH_CONNECT_PORTS_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void runOnce() const + Graph runOnce() const { const auto status = bt_graph_run_once(this->libObjPtr()); @@ -140,9 +142,11 @@ public: } else if (status == BT_GRAPH_RUN_ONCE_STATUS_AGAIN) { throw TryAgain {}; } + + return *this; } - void run() const + Graph run() const { const auto status = bt_graph_run(this->libObjPtr()); @@ -153,6 +157,8 @@ public: } else if (status == BT_GRAPH_RUN_STATUS_AGAIN) { throw TryAgain {}; } + + return *this; } private: diff --git a/src/cpp-common/bt2/integer-range-set.hpp b/src/cpp-common/bt2/integer-range-set.hpp index 403b7fe7..090520bc 100644 --- a/src/cpp-common/bt2/integer-range-set.hpp +++ b/src/cpp-common/bt2/integer-range-set.hpp @@ -195,7 +195,7 @@ public: return !(*this == other); } - void addRange(const Value lower, const Value upper) const + CommonIntegerRangeSet addRange(const Value lower, const Value upper) const { static_assert( !std::is_const::value, @@ -206,6 +206,8 @@ public: if (status == BT_INTEGER_RANGE_SET_ADD_RANGE_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } std::uint64_t length() const noexcept diff --git a/src/cpp-common/bt2/message-array.hpp b/src/cpp-common/bt2/message-array.hpp index a286bc9e..76b3491f 100644 --- a/src/cpp-common/bt2/message-array.hpp +++ b/src/cpp-common/bt2/message-array.hpp @@ -218,13 +218,14 @@ public: return _mLen == _mCap; } - void append(ConstMessage::Shared message) noexcept + ConstMessageArray& append(ConstMessage::Shared message) noexcept { BT_ASSERT_DBG(!this->isFull()); /* Move reference to underlying array */ _mLibArrayPtr[_mLen] = message.release().libObjPtr(); ++_mLen; + return *this; } /* diff --git a/src/cpp-common/bt2/message-iterator.hpp b/src/cpp-common/bt2/message-iterator.hpp index 9691ee4e..36c144d0 100644 --- a/src/cpp-common/bt2/message-iterator.hpp +++ b/src/cpp-common/bt2/message-iterator.hpp @@ -93,13 +93,13 @@ public: } } - void seekBeginning() const + MessageIterator seekBeginning() const { const auto status = bt_message_iterator_seek_beginning(this->libObjPtr()); switch (status) { case BT_MESSAGE_ITERATOR_SEEK_BEGINNING_STATUS_OK: - return; + break; case BT_MESSAGE_ITERATOR_SEEK_BEGINNING_STATUS_AGAIN: throw TryAgain {}; case BT_MESSAGE_ITERATOR_SEEK_BEGINNING_STATUS_MEMORY_ERROR: @@ -109,6 +109,8 @@ public: default: bt_common_abort(); } + + return *this; } bool canSeekNsFromOrigin(const std::int64_t nsFromOrigin) const @@ -132,14 +134,14 @@ public: } } - void seekNsFromOrigin(const std::int64_t nsFromOrigin) const + MessageIterator seekNsFromOrigin(const std::int64_t nsFromOrigin) const { const auto status = bt_message_iterator_seek_ns_from_origin(this->libObjPtr(), nsFromOrigin); switch (status) { case BT_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_STATUS_OK: - return; + break; case BT_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_STATUS_AGAIN: throw TryAgain {}; case BT_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_STATUS_MEMORY_ERROR: @@ -149,6 +151,8 @@ public: default: bt_common_abort(); } + + return *this; } bool canSeekForward() const noexcept diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index 3f9d7418..0abd3c54 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -268,12 +268,13 @@ public: internal::CommonStreamBeginningMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamBeginningMessage`."); bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } OptionalBorrowedObject defaultClockSnapshot() const noexcept @@ -382,12 +383,13 @@ public: return _Stream {internal::CommonStreamEndMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamEndMessage`."); bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } OptionalBorrowedObject defaultClockSnapshot() const noexcept @@ -497,12 +499,13 @@ public: internal::CommonPacketBeginningMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstPacketBeginningMessage`."); bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -606,12 +609,13 @@ public: return _Packet {internal::CommonPacketEndMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstPacketEndMessage`."); bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -837,12 +841,13 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) const noexcept + CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstDiscardedEventsMessage`."); bt_message_discarded_events_set_count(this->libObjPtr(), count); + return *this; } bt2s::optional count() const noexcept @@ -967,12 +972,13 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) const noexcept + CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstDiscardedPacketsMessage`."); bt_message_discarded_packets_set_count(this->libObjPtr(), count); + return *this; } bt2s::optional count() const noexcept diff --git a/src/cpp-common/bt2/self-component-port.hpp b/src/cpp-common/bt2/self-component-port.hpp index e2bbe807..e1ab8098 100644 --- a/src/cpp-common/bt2/self-component-port.hpp +++ b/src/cpp-common/bt2/self-component-port.hpp @@ -99,10 +99,11 @@ public: } template - void data(T& obj) const noexcept + SelfComponent data(T& obj) const noexcept { bt_self_component_set_data(this->libObjPtr(), const_cast(static_cast(&obj))); + return *this; } bt2::TraceClass::Shared createTraceClass() const @@ -187,13 +188,7 @@ public: return this->_selfComponent().template data(); } - template - void data(T& obj) const noexcept - { - this->_selfComponent().data(obj); - } - -private: +protected: SelfComponent _selfComponent() const noexcept { return SelfComponent {this->libObjPtr()}; @@ -328,6 +323,8 @@ public: class SelfSourceComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using OutputPorts = SelfComponentPorts; @@ -343,6 +340,15 @@ public: bt_self_component_source_as_component_source(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfSourceComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + template OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const; @@ -357,6 +363,8 @@ private: class SelfFilterComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using InputPorts = SelfComponentPorts; @@ -374,6 +382,15 @@ public: bt_self_component_filter_as_component_filter(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfFilterComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + template InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const; @@ -398,6 +415,8 @@ private: class SelfSinkComponent final : public internal::SelfSpecificComponent { + using _ThisSelfSpecificComponent = internal::SelfSpecificComponent; + public: using InputPorts = SelfComponentPorts; @@ -412,6 +431,15 @@ public: return ConstSinkComponent {bt_self_component_sink_as_component_sink(this->libObjPtr())}; } + using _ThisSelfSpecificComponent::data; + + template + SelfSinkComponent data(T& obj) const noexcept + { + this->_selfComponent().data(obj); + return *this; + } + MessageIterator::Shared createMessageIterator(InputPorts::Port port) const; bool isInterrupted() const noexcept diff --git a/src/cpp-common/bt2/self-message-iterator-configuration.hpp b/src/cpp-common/bt2/self-message-iterator-configuration.hpp index e628194a..5205efaf 100644 --- a/src/cpp-common/bt2/self-message-iterator-configuration.hpp +++ b/src/cpp-common/bt2/self-message-iterator-configuration.hpp @@ -22,10 +22,11 @@ public: { } - void canSeekForward(const bool canSeekForward) const noexcept + SelfMessageIteratorConfiguration canSeekForward(const bool canSeekForward) const noexcept { bt_self_message_iterator_configuration_set_can_seek_forward( this->libObjPtr(), static_cast(canSeekForward)); + return *this; } }; diff --git a/src/cpp-common/bt2/self-message-iterator.hpp b/src/cpp-common/bt2/self-message-iterator.hpp index 12ad0783..7ad212c1 100644 --- a/src/cpp-common/bt2/self-message-iterator.hpp +++ b/src/cpp-common/bt2/self-message-iterator.hpp @@ -65,10 +65,11 @@ public: } template - void data(T& obj) const noexcept + SelfMessageIterator data(T& obj) const noexcept { bt_self_message_iterator_set_data(this->libObjPtr(), const_cast(static_cast(&obj))); + return *this; } bt2::StreamBeginningMessage::Shared diff --git a/src/cpp-common/bt2/trace-ir.hpp b/src/cpp-common/bt2/trace-ir.hpp index 7171138d..f2678f89 100644 --- a/src/cpp-common/bt2/trace-ir.hpp +++ b/src/cpp-common/bt2/trace-ir.hpp @@ -445,7 +445,7 @@ public: return bt_stream_get_id(this->libObjPtr()); } - void name(const bt2c::CStringView name) const + CommonStream name(const bt2c::CStringView name) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStream`."); @@ -454,6 +454,8 @@ public: if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView name() const noexcept @@ -462,11 +464,12 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonStream userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStream`."); bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -632,7 +635,7 @@ public: Class cls() const noexcept; - void name(const bt2c::CStringView name) const + CommonTrace name(const bt2c::CStringView name) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstTrace`."); @@ -641,6 +644,8 @@ public: if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView name() const noexcept @@ -648,9 +653,10 @@ public: return bt_trace_get_name(this->libObjPtr()); } - void uuid(const bt2c::UuidView& uuid) const noexcept + CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept { bt_trace_set_uuid(this->libObjPtr(), uuid.begin()); + return *this; } bt2s::optional uuid() const noexcept @@ -679,7 +685,7 @@ public: return _Spec::streamById(this->libObjPtr(), id); } - void environmentEntry(const bt2c::CStringView name, const std::int64_t val) const + CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstTrace`."); @@ -688,9 +694,11 @@ public: if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } - void environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const + CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstTrace`."); @@ -699,6 +707,8 @@ public: if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } std::uint64_t environmentSize() const noexcept @@ -722,11 +732,12 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonTrace userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstTrace`."); bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -907,7 +918,7 @@ public: return bt_event_class_get_id(this->libObjPtr()); } - void name(const bt2c::CStringView name) const + CommonEventClass name(const bt2c::CStringView name) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); @@ -916,6 +927,8 @@ public: if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView name() const noexcept @@ -923,12 +936,13 @@ public: return bt_event_class_get_name(this->libObjPtr()); } - void logLevel(const LogLevel logLevel) const noexcept + CommonEventClass logLevel(const LogLevel logLevel) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); bt_event_class_set_log_level(this->libObjPtr(), static_cast(logLevel)); + return *this; } bt2s::optional logLevel() const noexcept @@ -942,7 +956,7 @@ public: return bt2s::nullopt; } - void emfUri(const bt2c::CStringView emfUri) const + CommonEventClass emfUri(const bt2c::CStringView emfUri) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); @@ -951,6 +965,8 @@ public: if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView emfUri() const noexcept @@ -958,7 +974,7 @@ public: return bt_event_class_get_emf_uri(this->libObjPtr()); } - void payloadFieldClass(const StructureFieldClass fc) const + CommonEventClass payloadFieldClass(const StructureFieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); @@ -968,6 +984,8 @@ public: if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept @@ -975,7 +993,7 @@ public: return _Spec::payloadFieldClass(this->libObjPtr()); } - void specificContextFieldClass(const StructureFieldClass fc) const + CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); @@ -985,6 +1003,8 @@ public: if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept @@ -993,11 +1013,12 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonEventClass userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstEventClass`."); bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -1240,7 +1261,7 @@ public: return bt_stream_class_get_id(this->libObjPtr()); } - void name(const bt2c::CStringView name) const + CommonStreamClass name(const bt2c::CStringView name) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1250,6 +1271,8 @@ public: if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } bt2c::CStringView name() const noexcept @@ -1257,13 +1280,14 @@ public: return bt_stream_class_get_name(this->libObjPtr()); } - void assignsAutomaticEventClassId(const bool val) const noexcept + CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(), static_cast(val)); + return *this; } bool assignsAutomaticEventClassId() const noexcept @@ -1272,13 +1296,14 @@ public: bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr())); } - void assignsAutomaticStreamId(const bool val) const noexcept + CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(), static_cast(val)); + return *this; } bool assignsAutomaticStreamId() const noexcept @@ -1286,8 +1311,9 @@ public: return static_cast(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr())); } - void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot, - const bool withEndDefaultClkSnapshot) const noexcept + CommonStreamClass supportsPackets(const bool supportsPackets, + const bool withBeginningDefaultClkSnapshot, + const bool withEndDefaultClkSnapshot) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1296,6 +1322,7 @@ public: static_cast(supportsPackets), static_cast(withBeginningDefaultClkSnapshot), static_cast(withEndDefaultClkSnapshot)); + return *this; } bool supportsPackets() const noexcept @@ -1315,8 +1342,8 @@ public: bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr())); } - void supportsDiscardedEvents(const bool supportsDiscardedEvents, - const bool withDefaultClkSnapshots) const noexcept + CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents, + const bool withDefaultClkSnapshots) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1324,6 +1351,7 @@ public: bt_stream_class_set_supports_discarded_events( this->libObjPtr(), static_cast(supportsDiscardedEvents), static_cast(withDefaultClkSnapshots)); + return *this; } bool supportsDiscardedEvents() const noexcept @@ -1337,8 +1365,8 @@ public: bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr())); } - void supportsDiscardedPackets(const bool supportsDiscardedPackets, - const bool withDefaultClkSnapshots) const noexcept + CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets, + const bool withDefaultClkSnapshots) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1346,6 +1374,7 @@ public: bt_stream_class_set_supports_discarded_packets( this->libObjPtr(), static_cast(supportsDiscardedPackets), static_cast(withDefaultClkSnapshots)); + return *this; } bool supportsDiscardedPackets() const noexcept @@ -1359,7 +1388,7 @@ public: bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr())); } - void defaultClockClass(const ClockClass clkCls) const + CommonStreamClass defaultClockClass(const ClockClass clkCls) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1368,6 +1397,7 @@ public: bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr()); BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK); + return *this; } OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept @@ -1390,7 +1420,7 @@ public: return _Spec::eventClassById(this->libObjPtr(), id); } - void packetContextFieldClass(const StructureFieldClass fc) const + CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1401,6 +1431,8 @@ public: if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept @@ -1408,7 +1440,7 @@ public: return _Spec::packetContextFieldClass(this->libObjPtr()); } - void eventCommonContextFieldClass(const StructureFieldClass fc) const + CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); @@ -1419,6 +1451,8 @@ public: if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept @@ -1427,12 +1461,13 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonStreamClass userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstStreamClass`."); bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept @@ -1830,12 +1865,13 @@ public: VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass); } - void assignsAutomaticStreamClassId(const bool val) const noexcept + CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstTraceClass`."); bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(), static_cast(val)); + return *this; } bool assignsAutomaticStreamClassId() const noexcept @@ -1860,11 +1896,12 @@ public: } template - void userAttributes(const CommonMapValue userAttrs) const noexcept + CommonTraceClass userAttributes(const CommonMapValue userAttrs) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstTraceClass`."); bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); + return *this; } UserAttributes userAttributes() const noexcept diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index 7388c340..80e17dea 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -500,11 +500,12 @@ public: return static_cast(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::value, "Not available with `bt2::ConstBoolValue`."); bt_value_bool_set(this->libObjPtr(), static_cast(val)); + return *this; } Shared shared() const noexcept @@ -585,12 +586,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonUnsignedIntegerValue value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstUnsignedIntegerValue`."); bt_value_integer_unsigned_set(this->libObjPtr(), val); + return *this; } Value value() const noexcept @@ -676,12 +678,13 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonSignedIntegerValue value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstSignedIntegerValue`."); bt_value_integer_signed_set(this->libObjPtr(), val); + return *this; } Value value() const noexcept @@ -764,11 +767,12 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const noexcept + CommonRealValue value(const Value val) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstRealValue`."); bt_value_real_set(this->libObjPtr(), val); + return *this; } Value value() const noexcept @@ -851,7 +855,7 @@ public: return RawValueProxy {*this}; } - void value(const Value val) const + CommonStringValue value(const Value val) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstStringValue`."); @@ -861,6 +865,8 @@ public: if (status == BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR) { throw MemoryError {}; } + + return *this; } Value value() const noexcept @@ -988,16 +994,17 @@ public: internal::CommonArrayValueSpec::elementByIndex(this->libObjPtr(), index)}; } - void append(const Value val) const + CommonArrayValue append(const Value val) const { static_assert(!std::is_const::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::value, "Not available with `bt2::ConstArrayValue`."); @@ -1005,9 +1012,10 @@ public: bt_value_array_append_bool_element(this->libObjPtr(), static_cast(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::value, "Not available with `bt2::ConstArrayValue`."); @@ -1015,38 +1023,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::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::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::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 bt2c::CStringView rawVal) const + CommonArrayValue append(const bt2c::CStringView rawVal) const { - this->append(rawVal.data()); + return this->append(rawVal.data()); } CommonArrayValue appendEmptyArray() const; @@ -1286,16 +1298,17 @@ public: return static_cast(bt_value_map_has_entry(this->libObjPtr(), key)); } - void insert(const bt2c::CStringView key, const Value val) const + CommonMapValue insert(const bt2c::CStringView key, const Value val) const { static_assert(!std::is_const::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 bt2c::CStringView key, const bool rawVal) const + CommonMapValue insert(const bt2c::CStringView key, const bool rawVal) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstMapValue`."); @@ -1303,9 +1316,10 @@ public: bt_value_map_insert_bool_entry(this->libObjPtr(), key, static_cast(rawVal)); this->_handleInsertLibStatus(status); + return *this; } - void insert(const bt2c::CStringView key, const std::uint64_t rawVal) const + CommonMapValue insert(const bt2c::CStringView key, const std::uint64_t rawVal) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstMapValue`."); @@ -1313,8 +1327,10 @@ public: bt_value_map_insert_unsigned_integer_entry(this->libObjPtr(), key, rawVal); this->_handleInsertLibStatus(status); + return *this; } - void insert(const bt2c::CStringView key, const std::int64_t rawVal) const + + CommonMapValue insert(const bt2c::CStringView key, const std::int64_t rawVal) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstMapValue`."); @@ -1322,27 +1338,30 @@ public: bt_value_map_insert_signed_integer_entry(this->libObjPtr(), key, rawVal); this->_handleInsertLibStatus(status); + return *this; } - void insert(const bt2c::CStringView key, const double rawVal) const + CommonMapValue insert(const bt2c::CStringView key, const double rawVal) const { static_assert(!std::is_const::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 bt2c::CStringView key, const char *rawVal) const + CommonMapValue insert(const bt2c::CStringView key, const char *rawVal) const { static_assert(!std::is_const::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 bt2c::CStringView key, const bt2c::CStringView rawVal) const + CommonMapValue insert(const bt2c::CStringView key, const bt2c::CStringView rawVal) const { return this->insert(key, rawVal.data()); } @@ -1350,9 +1369,11 @@ public: CommonArrayValue insertEmptyArray(bt2c::CStringView key) const; CommonMapValue insertEmptyMap(bt2c::CStringView key) const; - void forEach(const internal::CommonMapValueForEachUserFunc>& func) const + CommonMapValue + forEach(const internal::CommonMapValueForEachUserFunc>& func) const { internal::CommonMapValueSpec::forEach(this->libObjPtr(), func); + return *this; } Shared shared() const noexcept