X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ffield.hpp;fp=src%2Fbin%2Flttng-sessiond%2Ffield.hpp;h=93091572885413e4722bff08358fc7dd13ba1dc8;hb=45110cdd99bd9ecc13a12d29afde3fffa48b4641;hp=dec5b103222008200b7adbcb8a019fa2ae3dbd3d;hpb=6e01cdc6c6e9cd18d99e8898fa3df41911388e8e;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/field.hpp b/src/bin/lttng-sessiond/field.hpp index dec5b1032..930915728 100644 --- a/src/bin/lttng-sessiond/field.hpp +++ b/src/bin/lttng-sessiond/field.hpp @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -77,14 +78,20 @@ private: class field { public: + using uptr = std::unique_ptr; using cuptr = std::unique_ptr; field(std::string name, type::cuptr type); void accept(field_visitor& visitor) const; bool operator==(const field& other) const noexcept; + const type& get_type() const; + type::cuptr move_type() noexcept; + const std::string name; - const type::cuptr _type; + +private: + type::cuptr _type; }; class integer_type : public type { @@ -198,7 +205,7 @@ class enumeration_mapping { public: using range_t = enumeration_mapping_range; - enumeration_mapping(const enumeration_mapping& other) = delete; + enumeration_mapping(const enumeration_mapping& other) = default; enumeration_mapping(const enumeration_mapping&& other) : name{std::move(other.name)}, range{other.range} { @@ -406,22 +413,57 @@ private: virtual bool _is_equal(const type& base_other) const noexcept override final; }; +template class variant_type : public type { -public: - using choices = std::vector; + static_assert(std::is_same::value || + std::is_same::value, + "Variant mapping integer type must be one of those allowed by typed_enumeration_type"); - variant_type(unsigned int alignment, - field_location selector_field_location, - choices in_choices); +public: + 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) : + type(in_alignment), + selector_field_location{std::move(in_selector_field_location)}, + _choices{std::move(in_choices)} + { + } virtual void accept(type_visitor& visitor) const override final; const field_location selector_field_location; const choices _choices; -; private: - virtual bool _is_equal(const type& base_other) const noexcept override final; + static bool _choices_are_equal(const choices& a, const choices& b) + { + if (a.size() != b.size()) { + 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; + }); + } + + virtual bool _is_equal(const type& base_other) const noexcept override final + { + const auto& other = static_cast(base_other); + + return selector_field_location == other.selector_field_location && + _choices_are_equal(_choices, other._choices); + } }; class field_visitor { @@ -448,7 +490,8 @@ 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; protected: type_visitor() = default;