X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ffield.cpp;h=e46e06631eae121b4736547b31995839783bd381;hb=4f2da8b8c0f8fad2ae35dbdb9f29769da52a3dc1;hp=df51df488498589f9f4524f6025cce8a4f2366a4;hpb=eda1aa02582ba8af1f30d40f131f4a32d2b372ab;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/field.cpp b/src/bin/lttng-sessiond/field.cpp index df51df488..e46e06631 100644 --- a/src/bin/lttng-sessiond/field.cpp +++ b/src/bin/lttng-sessiond/field.cpp @@ -66,6 +66,9 @@ bool lst::type::operator!=(const lst::type& other) const noexcept lst::field::field(std::string in_name, lst::type::cuptr in_type) : name{std::move(in_name)}, _type{std::move(in_type)} { + if (!_type) { + LTTNG_THROW_ERROR(fmt::format("Invalid type used to create field: field name = `{}`", name)); + } } void lst::field::accept(lst::field_visitor& visitor) const @@ -78,6 +81,20 @@ bool lst::field::operator==(const lst::field& other) const noexcept return name == other.name && *_type == *other._type; } +lst::type::cuptr lst::field::move_type() noexcept +{ + return std::move(_type); +} + +const lst::type &lst::field::get_type() const +{ + if (_type) { + return *_type; + } else { + LTTNG_THROW_ERROR(fmt::format("Invalid attempt to access field type after transfer: field name = `{}`", name)); + } +} + lst::integer_type::integer_type(unsigned int in_alignment, enum lst::byte_order in_byte_order, unsigned int in_size, @@ -93,6 +110,12 @@ lst::integer_type::integer_type(unsigned int in_alignment, { } +lst::type::cuptr lst::integer_type::copy() const +{ + return lttng::make_unique( + alignment, byte_order, size, signedness_, base_, roles_); +} + bool lst::integer_type::_is_equal(const type &base_other) const noexcept { const auto& other = static_cast(base_other); @@ -145,6 +168,12 @@ lst::floating_point_type::floating_point_type(unsigned int in_alignment, typeid(*this))); } +lst::type::cuptr lst::floating_point_type::copy() const +{ + return lttng::make_unique( + alignment, byte_order, exponent_digits, mantissa_digits); +} + void lst::floating_point_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -174,17 +203,36 @@ lst::enumeration_type::enumeration_type(unsigned int in_alignment, { } +/* + * Due to a bug in g++ < 7.1, these specializations must be enclosed in the namespaces + * rather than using the usual `namespace::namespace::function` notation: + * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480. + */ namespace lttng { namespace sessiond { namespace trace { template <> -void lst::signed_enumeration_type::accept(type_visitor& visitor) const +void signed_enumeration_type::accept(type_visitor& visitor) const +{ + visitor.visit(*this); +} + +template <> +void unsigned_enumeration_type::accept(type_visitor& visitor) const { visitor.visit(*this); } template <> -void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const +void variant_type::accept( + lst::type_visitor& visitor) const +{ + visitor.visit(*this); +} + +template <> +void variant_type::accept( + lst::type_visitor& visitor) const { visitor.visit(*this); } @@ -219,6 +267,12 @@ bool lst::static_length_array_type::_is_equal(const type& base_other) const noex return array_type::_is_equal(base_other) && this->length == other.length; } +lst::type::cuptr lst::static_length_array_type::copy() const +{ + return lttng::make_unique( + alignment, element_type->copy(), length); +} + void lst::static_length_array_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -240,6 +294,12 @@ bool lst::dynamic_length_array_type::_is_equal(const type& base_other) const noe this->length_field_location == other.length_field_location; } +lst::type::cuptr lst::dynamic_length_array_type::copy() const +{ + return lttng::make_unique( + alignment, element_type->copy(), length_field_location); +} + void lst::dynamic_length_array_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -258,6 +318,11 @@ bool lst::static_length_blob_type::_is_equal(const type& base_other) const noexc return length_bytes == other.length_bytes && roles_ == other.roles_; } +lst::type::cuptr lst::static_length_blob_type::copy() const +{ + return lttng::make_unique(alignment, length_bytes, roles_); +} + void lst::static_length_blob_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -276,6 +341,11 @@ bool lst::dynamic_length_blob_type::_is_equal(const type& base_other) const noex return length_field_location == other.length_field_location; } +lst::type::cuptr lst::dynamic_length_blob_type::copy() const +{ + return lttng::make_unique(alignment, length_field_location); +} + void lst::dynamic_length_blob_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -306,6 +376,11 @@ bool lst::static_length_string_type::_is_equal(const type& base_other) const noe return string_type::_is_equal(base_other) && this->length == other.length; } +lst::type::cuptr lst::static_length_string_type::copy() const +{ + return lttng::make_unique(alignment, encoding_, length); +} + void lst::static_length_string_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -327,6 +402,12 @@ bool lst::dynamic_length_string_type::_is_equal(const type& base_other) const no this->length_field_location == other.length_field_location; } +lst::type::cuptr lst::dynamic_length_string_type::copy() const +{ + return lttng::make_unique( + alignment, encoding_, length_field_location); +} + void lst::dynamic_length_string_type::accept(type_visitor& visitor) const { visitor.visit(*this); @@ -338,13 +419,18 @@ lst::null_terminated_string_type::null_terminated_string_type(unsigned int in_al { } +lst::type::cuptr lst::null_terminated_string_type::copy() const +{ + return lttng::make_unique(alignment, encoding_); +} + void lst::null_terminated_string_type::accept(type_visitor& visitor) const { visitor.visit(*this); } lst::structure_type::structure_type(unsigned int in_alignment, fields in_fields) : - type(in_alignment), _fields{std::move(in_fields)} + type(in_alignment), fields_{std::move(in_fields)} { } @@ -352,35 +438,23 @@ bool lst::structure_type::_is_equal(const type& base_other) const noexcept { const auto &other = static_cast(base_other); - return fields_are_equal(this->_fields, other._fields); -} - -void lst::structure_type::accept(type_visitor& visitor) const -{ - visitor.visit(*this); + return fields_are_equal(this->fields_, other.fields_); } -lst::variant_type::variant_type(unsigned int in_alignment, - field_location in_selector_field_location, - choices in_choices) : - type(in_alignment), - selector_field_location{std::move(in_selector_field_location)}, - _choices -{std::move(in_choices)} +lst::type::cuptr lst::structure_type::copy() const { -} + structure_type::fields copy_of_fields; -bool lst::variant_type::_is_equal(const type& base_other) const noexcept -{ - const auto &other = static_cast(base_other); + copy_of_fields.reserve(fields_.size()); + for (const auto& field : fields_) { + copy_of_fields.emplace_back(lttng::make_unique( + field->name, field->get_type().copy())); + } - return this->selector_field_location == other.selector_field_location && - fields_are_equal(this->_choices -, other._choices -); + return lttng::make_unique(alignment, std::move(copy_of_fields)); } -void lst::variant_type::accept(type_visitor& visitor) const +void lst::structure_type::accept(type_visitor& visitor) const { visitor.visit(*this); }