Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / field.hpp
index 207592b3f2af83ca9e3262222f2365828364951d..5180574a1c0cb721aa175cec0d818e7481cd9ddf 100644 (file)
@@ -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;
@@ -132,11 +137,11 @@ public:
        using roles = std::vector<role>;
 
        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 = {});
 
        type::cuptr copy() const override;
 
@@ -160,9 +165,9 @@ protected:
 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);
 
        type::cuptr copy() const final;
 
@@ -177,13 +182,20 @@ private:
 };
 
 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 = {});
 
        void accept(type_visitor& visitor) const override = 0;
 };
@@ -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<MappingIntegerType>;
 
-       enumeration_mapping(const enumeration_mapping<MappingIntegerType>& other) = default;
-       enumeration_mapping(const enumeration_mapping<MappingIntegerType>&& other) noexcept :
-               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<MappingIntegerType>& other) = default;
+       enumeration_mapping(enumeration_mapping<MappingIntegerType>&& 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,31 +270,31 @@ public:
        using mappings = std::vector<mapping>;
 
        static_assert(std::is_integral<MappingIntegerType>::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<const mappings>& 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<const mappings>& in_mappings,
+                              integer_type::roles in_roles = {}) :
                enumeration_type(in_alignment,
-                               in_byte_order,
-                               in_size,
-                               std::is_signed<MappingIntegerType>::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<MappingIntegerType>::value ?
+                                        integer_type::signedness::SIGNED :
+                                        integer_type::signedness::UNSIGNED,
+                                in_base,
+                                std::move(in_roles)),
+               mappings_{ std::move(in_mappings) }
        {
        }
 
        type::cuptr copy() const override
        {
                return lttng::make_unique<typed_enumeration_type<MappingIntegerType>>(
-                               alignment, byte_order, size, base_, mappings_, roles_);
+                       alignment, byte_order, size, base_, mappings_, roles_);
        }
 
        void accept(type_visitor& visitor) const final;
@@ -286,8 +304,8 @@ public:
 private:
        bool _is_equal(const type& base_other) const noexcept final
        {
-               const auto& other = static_cast<const typed_enumeration_type<MappingIntegerType>&>(
-                               base_other);
+               const auto& other =
+                       static_cast<const typed_enumeration_type<MappingIntegerType>&>(base_other);
 
                return integer_type::_is_equal(base_other) && *this->mappings_ == *other.mappings_;
        }
@@ -310,8 +328,8 @@ protected:
 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);
 
        type::cuptr copy() const final;
 
@@ -326,8 +344,8 @@ private:
 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);
 
        type::cuptr copy() const final;
 
@@ -397,8 +415,9 @@ protected:
 
 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);
 
        type::cuptr copy() const final;
 
@@ -413,8 +432,8 @@ private:
 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);
 
        type::cuptr copy() const final;
 
@@ -453,24 +472,25 @@ private:
 
 template <typename MappingIntegerType>
 class variant_type : public type {
-       static_assert(std::is_same<MappingIntegerType,
-                                       unsigned_enumeration_type::mapping::range_t::
-                                                       range_integer_t>::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");
+       static_assert(
+               std::is_same<MappingIntegerType,
+                            unsigned_enumeration_type::mapping::range_t::range_integer_t>::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<const details::enumeration_mapping<MappingIntegerType>, type::cuptr>;
+       using choice =
+               std::pair<const details::enumeration_mapping<MappingIntegerType>, type::cuptr>;
        using choices = std::vector<choice>;
 
        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) }
        {
        }
 
@@ -480,8 +500,8 @@ public:
 
                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<variant_type<MappingIntegerType>>(
@@ -500,11 +520,13 @@ private:
                        return false;
                }
 
-               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;
+                                 });
        }
 
        bool _is_equal(const type& base_other) const noexcept final
@@ -512,13 +534,18 @@ private:
                const auto& other = static_cast<decltype(*this)&>(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:
@@ -528,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;
@@ -540,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<signed_enumeration_type::mapping::range_t::range_integer_t>& type) = 0;
-       virtual void visit(const variant_type<unsigned_enumeration_type::mapping::range_t::range_integer_t>& type) = 0;
+       virtual void
+       visit(const variant_type<signed_enumeration_type::mapping::range_t::range_integer_t>&
+                     type) = 0;
+       virtual void
+       visit(const variant_type<unsigned_enumeration_type::mapping::range_t::range_integer_t>&
+                     type) = 0;
 
 protected:
        type_visitor() = default;
@@ -561,10 +597,10 @@ namespace fmt {
 template <>
 struct formatter<lttng::sessiond::trace::field_location> : formatter<std::string> {
        template <typename FormatContextType>
-       typename FormatContextType::iterator format(
-                       const lttng::sessiond::trace::field_location& location, FormatContextType& ctx)
+       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:
@@ -587,7 +623,7 @@ struct formatter<lttng::sessiond::trace::field_location> : formatter<std::string
                        break;
                }
 
-               for (const auto &name : location.elements_) {
+               for (const autoname : location.elements_) {
                        location_str += ", \"" + name + "\"";
                }
 
@@ -599,12 +635,12 @@ struct formatter<lttng::sessiond::trace::field_location> : formatter<std::string
 namespace details {
 template <typename MappingIntegerType>
 ::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 */
@@ -615,13 +651,12 @@ struct formatter<typename lttng::sessiond::trace::signed_enumeration_type::mappi
        template <typename FormatContextType>
        typename FormatContextType::iterator
        format(typename lttng::sessiond::trace::signed_enumeration_type::mapping::range_t range,
-                       FormatContextType& 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));
        }
 };
 
@@ -631,13 +666,12 @@ struct formatter<typename lttng::sessiond::trace::unsigned_enumeration_type::map
        template <typename FormatContextType>
        typename FormatContextType::iterator
        format(typename lttng::sessiond::trace::unsigned_enumeration_type::mapping::range_t range,
-                       FormatContextType& 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));
        }
 };
 
This page took 0.02995 seconds and 4 git commands to generate.