X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ffield.hpp;h=dc418b661bd1344049141b9dd39d825244ed0615;hp=2e3a67bf42f23f39a2b4242a1817096daff92778;hb=HEAD;hpb=b6bbb1d666531bf061f29884da1b0d7c10f59aa0 diff --git a/src/bin/lttng-sessiond/field.hpp b/src/bin/lttng-sessiond/field.hpp index 2e3a67bf4..5180574a1 100644 --- a/src/bin/lttng-sessiond/field.hpp +++ b/src/bin/lttng-sessiond/field.hpp @@ -65,7 +65,12 @@ public: bool operator==(const type& other) const noexcept; bool operator!=(const type& other) const noexcept; + virtual ~type(); + type(const type&) = delete; + type(type&&) = delete; + type& operator=(type&&) = delete; + type& operator=(const type&) = delete; /* Obtain an independent copy of `type`. */ virtual type::cuptr copy() const = 0; @@ -75,7 +80,7 @@ public: const unsigned int alignment; protected: - type(unsigned int alignment); + explicit type(unsigned int alignment); private: virtual bool _is_equal(const type& rhs) const noexcept = 0; @@ -132,15 +137,15 @@ public: using roles = std::vector; integer_type(unsigned int alignment, - byte_order byte_order, - unsigned int size, - signedness signedness, - base base, - roles roles = {}); + byte_order byte_order, + unsigned int size, + signedness signedness, + base base, + roles roles = {}); - virtual type::cuptr copy() const override; + type::cuptr copy() const override; - virtual void accept(type_visitor& visitor) const override; + void accept(type_visitor& visitor) const override; const enum byte_order byte_order; const unsigned int size; @@ -154,38 +159,45 @@ public: const roles roles_; protected: - virtual bool _is_equal(const type& other) const noexcept override; + bool _is_equal(const type& other) const noexcept override; }; class floating_point_type : public type { public: floating_point_type(unsigned int alignment, - byte_order byte_order, - unsigned int exponent_digits, - unsigned int mantissa_digits); + byte_order byte_order, + unsigned int exponent_digits, + unsigned int mantissa_digits); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const enum byte_order byte_order; const unsigned int exponent_digits; const unsigned int mantissa_digits; private: - virtual bool _is_equal(const type& other) const noexcept override final; + bool _is_equal(const type& other) const noexcept final; }; class enumeration_type : public integer_type { +public: + ~enumeration_type() override = default; + enumeration_type(const enumeration_type&) = delete; + enumeration_type(enumeration_type&&) = delete; + enumeration_type& operator=(enumeration_type&&) = delete; + enumeration_type& operator=(const enumeration_type&) = delete; + protected: enumeration_type(unsigned int alignment, - enum byte_order byte_order, - unsigned int size, - enum signedness signedness, - enum base base, - integer_type::roles roles = {}); + enum byte_order byte_order, + unsigned int size, + enum signedness signedness, + enum base base, + integer_type::roles roles = {}); - virtual void accept(type_visitor& visitor) const = 0; + void accept(type_visitor& visitor) const override = 0; }; namespace details { @@ -195,7 +207,7 @@ public: using range_integer_t = MappingIntegerType; enumeration_mapping_range(MappingIntegerType in_begin, MappingIntegerType in_end) : - begin{in_begin}, end{in_end} + begin{ in_begin }, end{ in_end } { } @@ -214,20 +226,26 @@ class enumeration_mapping { public: using range_t = enumeration_mapping_range; - enumeration_mapping(const enumeration_mapping& other) = default; - enumeration_mapping(const enumeration_mapping&& other) : - name{std::move(other.name)}, range{other.range} + enumeration_mapping(std::string in_name, MappingIntegerType value) : + name{ std::move(in_name) }, range{ value, value } { } - enumeration_mapping(std::string in_name, MappingIntegerType value) : name{std::move(in_name)}, range{value, value} + enumeration_mapping(std::string in_name, range_t in_range) : + name{ std::move(in_name) }, range{ in_range } { } - enumeration_mapping(std::string in_name, range_t in_range) : name{std::move(in_name)}, range{in_range} + enumeration_mapping(const enumeration_mapping& other) = default; + enumeration_mapping(enumeration_mapping&& other) noexcept : + name{ std::move(other.name) }, range{ other.range } { } + enumeration_mapping& operator=(enumeration_mapping&&) = delete; + enumeration_mapping& operator=(const enumeration_mapping&) = delete; + ~enumeration_mapping() = default; + const std::string name; /* * Only one range per mapping is supported for the moment as @@ -252,42 +270,42 @@ public: using mappings = std::vector; static_assert(std::is_integral::value && - sizeof(MappingIntegerType) == 8, - "MappingIntegerType must be either int64_t or uint64_t"); + sizeof(MappingIntegerType) == 8, + "MappingIntegerType must be either int64_t or uint64_t"); typed_enumeration_type(unsigned int in_alignment, - enum byte_order in_byte_order, - unsigned int in_size, - enum base in_base, - const std::shared_ptr& in_mappings, - integer_type::roles in_roles = {}) : + enum byte_order in_byte_order, + unsigned int in_size, + enum base in_base, + const std::shared_ptr& in_mappings, + integer_type::roles in_roles = {}) : enumeration_type(in_alignment, - in_byte_order, - in_size, - std::is_signed::value ? - integer_type::signedness::SIGNED : - integer_type::signedness::UNSIGNED, - in_base, - std::move(in_roles)), - mappings_{std::move(in_mappings)} + in_byte_order, + in_size, + std::is_signed::value ? + integer_type::signedness::SIGNED : + integer_type::signedness::UNSIGNED, + in_base, + std::move(in_roles)), + mappings_{ std::move(in_mappings) } { } - virtual type::cuptr copy() const override + type::cuptr copy() const override { return lttng::make_unique>( - alignment, byte_order, size, base_, mappings_, roles_); + alignment, byte_order, size, base_, mappings_, roles_); } - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const std::shared_ptr mappings_; private: - virtual bool _is_equal(const type& base_other) const noexcept override final + bool _is_equal(const type& base_other) const noexcept final { - const auto& other = static_cast&>( - base_other); + const auto& other = + static_cast&>(base_other); return integer_type::_is_equal(base_other) && *this->mappings_ == *other.mappings_; } @@ -304,39 +322,39 @@ public: const type::cuptr element_type; protected: - virtual bool _is_equal(const type& base_other) const noexcept override; + bool _is_equal(const type& base_other) const noexcept override; }; class static_length_array_type : public array_type { public: static_length_array_type(unsigned int alignment, - type::cuptr element_type, - uint64_t in_length); + type::cuptr element_type, + uint64_t in_length); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const uint64_t length; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; class dynamic_length_array_type : public array_type { public: dynamic_length_array_type(unsigned int alignment, - type::cuptr element_type, - field_location length_field_location); + type::cuptr element_type, + field_location length_field_location); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const field_location length_field_location; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; class static_length_blob_type : public type { @@ -350,29 +368,29 @@ public: static_length_blob_type(unsigned int alignment, uint64_t in_length_bytes, roles roles = {}); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const uint64_t length_bytes; const roles roles_; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; 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; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const field_location length_field_location; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; class string_type : public type { @@ -392,47 +410,48 @@ public: const encoding encoding_; protected: - virtual bool _is_equal(const type& base_other) const noexcept override; + bool _is_equal(const type& base_other) const noexcept override; }; class static_length_string_type : public string_type { public: - static_length_string_type( - unsigned int alignment, enum encoding in_encoding, uint64_t length); + static_length_string_type(unsigned int alignment, + enum encoding in_encoding, + uint64_t length); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const uint64_t length; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; class dynamic_length_string_type : public string_type { public: dynamic_length_string_type(unsigned int alignment, - enum encoding in_encoding, - field_location length_field_location); + enum encoding in_encoding, + field_location length_field_location); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const field_location length_field_location; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; 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; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; }; class structure_type : public type { @@ -441,54 +460,55 @@ public: structure_type(unsigned int alignment, fields in_fields); - virtual type::cuptr copy() const override final; + type::cuptr copy() const final; - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const fields fields_; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + bool _is_equal(const type& base_other) const noexcept final; }; template class variant_type : public type { - static_assert(std::is_same::value || - std::is_same::value, - "Variant mapping integer type must be one of those allowed by typed_enumeration_type"); + static_assert( + std::is_same::value || + std::is_same< + MappingIntegerType, + signed_enumeration_type::mapping::range_t::range_integer_t>::value, + "Variant mapping integer type must be one of those allowed by typed_enumeration_type"); public: - using choice = std::pair, type::cuptr>; + using choice = + std::pair, type::cuptr>; using choices = std::vector; variant_type(unsigned int in_alignment, - field_location in_selector_field_location, - choices in_choices) : + 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)} + selector_field_location{ std::move(in_selector_field_location) }, + choices_{ std::move(in_choices) } { } - virtual type::cuptr copy() const override final + type::cuptr copy() const final { choices copy_of_choices; copy_of_choices.reserve(choices_.size()); for (const auto& current_choice : choices_) { - copy_of_choices.emplace_back( - current_choice.first, current_choice.second->copy()); + copy_of_choices.emplace_back(current_choice.first, + current_choice.second->copy()); } return lttng::make_unique>( alignment, selector_field_location, std::move(copy_of_choices)); } - virtual void accept(type_visitor& visitor) const override final; + void accept(type_visitor& visitor) const final; const field_location selector_field_location; const choices choices_; @@ -500,27 +520,32 @@ private: return false; } - return true; - - return std::equal(a.cbegin(), a.cend(), b.cbegin(), - [](const choice& choice_a, const choice& choice_b) { - return choice_a.first == choice_b.first && - *choice_a.second == *choice_b.second; - }); + return std::equal(a.cbegin(), + a.cend(), + b.cbegin(), + [](const choice& choice_a, const choice& choice_b) { + return choice_a.first == choice_b.first && + *choice_a.second == *choice_b.second; + }); } - virtual bool _is_equal(const type& base_other) const noexcept override final + bool _is_equal(const type& base_other) const noexcept final { const auto& other = static_cast(base_other); return selector_field_location == other.selector_field_location && - _choices_are_equal(choices_, other.choices_); + _choices_are_equal(choices_, other.choices_); } }; class field_visitor { public: virtual ~field_visitor() = default; + field_visitor(field_visitor&&) = delete; + field_visitor(const field_visitor&) = delete; + field_visitor& operator=(const field_visitor&) = delete; + field_visitor& operator=(field_visitor&&) = delete; + virtual void visit(const field& field) = 0; protected: @@ -530,6 +555,11 @@ protected: class type_visitor { public: virtual ~type_visitor() = default; + type_visitor(type_visitor&&) = delete; + type_visitor(const type_visitor&) = delete; + type_visitor& operator=(const type_visitor&) = delete; + type_visitor& operator=(type_visitor&&) = delete; + virtual void visit(const integer_type& type) = 0; virtual void visit(const floating_point_type& type) = 0; virtual void visit(const signed_enumeration_type& type) = 0; @@ -542,8 +572,12 @@ public: virtual void visit(const static_length_string_type& type) = 0; virtual void visit(const dynamic_length_string_type& type) = 0; virtual void visit(const structure_type& type) = 0; - virtual void visit(const variant_type& type) = 0; - virtual void visit(const variant_type& type) = 0; + virtual void + visit(const variant_type& + type) = 0; + virtual void + visit(const variant_type& + type) = 0; protected: type_visitor() = default; @@ -562,11 +596,11 @@ protected: namespace fmt { template <> struct formatter : formatter { - template - typename FormatCtx::iterator format( - const lttng::sessiond::trace::field_location& location, FormatCtx& ctx) + template + typename FormatContextType::iterator + format(const lttng::sessiond::trace::field_location& location, FormatContextType& ctx) { - std::string location_str{"["}; + std::string location_str{ "[" }; switch (location.root_) { case lttng::sessiond::trace::field_location::root::PACKET_HEADER: @@ -589,7 +623,7 @@ struct formatter : formatter : formatter ::std::string format_mapping_range(typename lttng::sessiond::trace::typed_enumeration_type< - MappingIntegerType>::mapping::range_t range) + MappingIntegerType>::mapping::range_t range) { if (range.begin == range.end) { - return ::fmt::format("[{}]", range.begin); + return ::lttng::format("[{}]", range.begin); } else { - return ::fmt::format("[{}, {}]", range.begin, range.end); + return ::lttng::format("[{}, {}]", range.begin, range.end); } } } /* namespace details */ @@ -614,32 +648,30 @@ template template <> struct formatter : formatter { - template - typename FormatCtx::iterator + template + typename FormatContextType::iterator format(typename lttng::sessiond::trace::signed_enumeration_type::mapping::range_t range, - FormatCtx& ctx) + FormatContextType& ctx) { return format_to(ctx.out(), - details::format_mapping_range< - lttng::sessiond::trace::signed_enumeration_type:: - mapping::range_t::range_integer_t>( - range)); + 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 + template + typename FormatContextType::iterator format(typename lttng::sessiond::trace::unsigned_enumeration_type::mapping::range_t range, - FormatCtx& ctx) + FormatContextType& ctx) { return format_to(ctx.out(), - details::format_mapping_range< - lttng::sessiond::trace::unsigned_enumeration_type:: - mapping::range_t::range_integer_t>( - range)); + details::format_mapping_range< + lttng::sessiond::trace::unsigned_enumeration_type:: + mapping::range_t::range_integer_t>(range)); } };