X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ffield.hpp;fp=src%2Fbin%2Flttng-sessiond%2Ffield.hpp;h=2e3a67bf42f23f39a2b4242a1817096daff92778;hp=a774d133a0978d0c59e0ce08f3a2865f675e23b4;hb=b6bbb1d666531bf061f29884da1b0d7c10f59aa0;hpb=88277a52069ed0135254ce29da617ebb6ecddbb8 diff --git a/src/bin/lttng-sessiond/field.hpp b/src/bin/lttng-sessiond/field.hpp index a774d133a..2e3a67bf4 100644 --- a/src/bin/lttng-sessiond/field.hpp +++ b/src/bin/lttng-sessiond/field.hpp @@ -9,6 +9,7 @@ #define LTTNG_FIELD_H #include +#include #include @@ -65,6 +66,10 @@ public: bool operator==(const type& other) const noexcept; bool operator!=(const type& other) const noexcept; virtual ~type(); + + /* Obtain an independent copy of `type`. */ + virtual type::cuptr copy() const = 0; + virtual void accept(type_visitor& visitor) const = 0; const unsigned int alignment; @@ -133,6 +138,8 @@ public: base base, roles roles = {}); + virtual type::cuptr copy() const override; + virtual void accept(type_visitor& visitor) const override; const enum byte_order byte_order; @@ -157,6 +164,8 @@ public: unsigned int exponent_digits, unsigned int mantissa_digits); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const enum byte_order byte_order; @@ -236,7 +245,7 @@ bool operator==(const enumeration_mapping& lhs, } } /* namespace details */ -template +template class typed_enumeration_type : public enumeration_type { public: using mapping = details::enumeration_mapping; @@ -264,6 +273,12 @@ public: { } + virtual type::cuptr copy() const override + { + return lttng::make_unique>( + alignment, byte_order, size, base_, mappings_, roles_); + } + virtual void accept(type_visitor& visitor) const override final; const std::shared_ptr mappings_; @@ -298,6 +313,8 @@ public: type::cuptr element_type, uint64_t in_length); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const uint64_t length; @@ -312,6 +329,8 @@ public: type::cuptr element_type, field_location length_field_location); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const field_location length_field_location; @@ -331,6 +350,8 @@ public: static_length_blob_type(unsigned int alignment, uint64_t in_length_bytes, roles roles = {}); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const uint64_t length_bytes; @@ -344,6 +365,8 @@ class dynamic_length_blob_type : public type { public: dynamic_length_blob_type(unsigned int alignment, field_location length_field_location); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const field_location length_field_location; @@ -376,6 +399,9 @@ class static_length_string_type : public string_type { public: static_length_string_type( unsigned int alignment, enum encoding in_encoding, uint64_t length); + + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const uint64_t length; @@ -389,6 +415,9 @@ public: dynamic_length_string_type(unsigned int alignment, enum encoding in_encoding, field_location length_field_location); + + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const field_location length_field_location; @@ -400,6 +429,9 @@ private: class null_terminated_string_type : public string_type { public: null_terminated_string_type(unsigned int alignment, enum encoding in_encoding); + + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; }; @@ -409,6 +441,8 @@ public: structure_type(unsigned int alignment, fields in_fields); + virtual type::cuptr copy() const override final; + virtual void accept(type_visitor& visitor) const override final; const fields fields_; @@ -417,7 +451,7 @@ private: virtual bool _is_equal(const type& base_other) const noexcept override final; }; -template +template class variant_type : public type { static_assert(std::is_samecopy()); + } + + return lttng::make_unique>( + alignment, selector_field_location, std::move(copy_of_choices)); + } + virtual void accept(type_visitor& visitor) const override final; const field_location selector_field_location; const choices choices_; -; private: static bool _choices_are_equal(const choices& a, const choices& b) @@ -507,6 +554,8 @@ protected: } /* namespace lttng */ /* + * Field formatters for libfmt. + * * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace, * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480. */ @@ -548,6 +597,52 @@ struct formatter : formatter +::std::string format_mapping_range(typename lttng::sessiond::trace::typed_enumeration_type< + MappingIntegerType>::mapping::range_t range) +{ + if (range.begin == range.end) { + return ::fmt::format("[{}]", range.begin); + } else { + return ::fmt::format("[{}, {}]", range.begin, range.end); + } +} +} /* namespace details */ + +template <> +struct formatter + : formatter { + template + typename FormatCtx::iterator + format(typename lttng::sessiond::trace::signed_enumeration_type::mapping::range_t range, + FormatCtx& ctx) + { + return format_to(ctx.out(), + details::format_mapping_range< + lttng::sessiond::trace::signed_enumeration_type:: + mapping::range_t::range_integer_t>( + range)); + } +}; + +template <> +struct formatter + : formatter { + template + typename FormatCtx::iterator + format(typename lttng::sessiond::trace::unsigned_enumeration_type::mapping::range_t range, + FormatCtx& ctx) + { + return format_to(ctx.out(), + details::format_mapping_range< + lttng::sessiond::trace::unsigned_enumeration_type:: + mapping::range_t::range_integer_t>( + range)); + } +}; + } /* namespace fmt */ #endif /* LTTNG_FIELD_H */