2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
10 #include <common/exception.hpp>
11 #include <common/format.hpp>
15 namespace lst
= lttng::sessiond::trace
;
18 template <class FieldTypeSet
>
19 bool fields_are_equal(const FieldTypeSet
& a
, const FieldTypeSet
& b
)
21 if (a
.size() != b
.size()) {
25 return std::equal(a
.cbegin(), a
.cend(), b
.cbegin(),
26 [](typename
FieldTypeSet::const_reference field_a
,
27 typename
FieldTypeSet::const_reference field_b
) {
28 return *field_a
== *field_b
;
33 lst::field_location::field_location(lst::field_location::root in_lookup_root
,
34 lst::field_location::elements in_elements
) :
35 root_
{in_lookup_root
}, elements_
{std::move(in_elements
)}
39 bool lst::field_location::operator==(const lst::field_location
& other
) const noexcept
41 return root_
== other
.root_
&&
42 elements_
== other
.elements_
;
45 lst::type::type(unsigned int in_alignment
) : alignment
{in_alignment
}
53 bool lst::type::operator==(const lst::type
& other
) const noexcept
55 return typeid(*this) == typeid(other
) &&
56 alignment
== other
.alignment
&&
57 /* defer to concrete type comparison */
58 this->_is_equal(other
);
61 bool lst::type::operator!=(const lst::type
& other
) const noexcept
63 return !(*this == other
);
66 lst::field::field(std::string in_name
, lst::type::cuptr in_type
) :
67 name
{std::move(in_name
)}, _type
{std::move(in_type
)}
71 void lst::field::accept(lst::field_visitor
& visitor
) const
76 bool lst::field::operator==(const lst::field
& other
) const noexcept
78 return name
== other
.name
&& *_type
== *other
._type
;
81 lst::integer_type::integer_type(unsigned int in_alignment
,
82 enum lst::byte_order in_byte_order
,
84 enum lst::integer_type::signedness in_signedness
,
85 enum lst::integer_type::base in_base
,
88 byte_order
{in_byte_order
},
90 signedness_
{in_signedness
},
92 roles_
{std::move(in_roles
)}
96 bool lst::integer_type::_is_equal(const type
&base_other
) const noexcept
98 const auto& other
= static_cast<decltype(*this)&>(base_other
);
100 return this->byte_order
== other
.byte_order
&&
101 this->size
== other
.size
&&
102 this->signedness_
== other
.signedness_
&&
103 this->base_
== other
.base_
&&
104 this->roles_
== other
.roles_
;
107 void lst::integer_type::accept(type_visitor
& visitor
) const
109 visitor
.visit(*this);
112 lst::byte_order
lst::type::reverse_byte_order(lst::byte_order byte_order
) noexcept
114 if (byte_order
== lst::byte_order::BIG_ENDIAN_
) {
115 return lst::byte_order::LITTLE_ENDIAN_
;
117 return lst::byte_order::BIG_ENDIAN_
;
121 lst::floating_point_type::floating_point_type(unsigned int in_alignment
,
122 lst::byte_order in_byte_order
,
123 unsigned int in_exponent_digits
,
124 unsigned int in_mantissa_digits
) :
126 byte_order(in_byte_order
),
127 exponent_digits
{in_exponent_digits
},
128 mantissa_digits(in_mantissa_digits
)
130 /* Allowed (exponent, mantissa) pairs. */
131 static const std::set
<std::pair
<unsigned int, unsigned int>> allowed_pairs
{
132 {5, 11}, /* binary16 */
133 {8, 24}, /* binary32 */
134 {11, 53}, /* binary64 */
135 {15, 113}, /* binary128 */
138 if (allowed_pairs
.find({exponent_digits
, mantissa_digits
}) != allowed_pairs
.end()) {
139 /* mantissa and exponent digits is a valid pair. */
143 LTTNG_THROW_INVALID_ARGUMENT_ERROR(
144 fmt::format("Invalid exponent/mantissa values provided while creating {}",
148 void lst::floating_point_type::accept(type_visitor
& visitor
) const
150 visitor
.visit(*this);
153 bool lst::floating_point_type::_is_equal(const type
& base_other
) const noexcept
155 const auto& other
= static_cast<decltype(*this)&>(base_other
);
157 return this->byte_order
== other
.byte_order
&&
158 this->exponent_digits
== other
.exponent_digits
&&
159 this->mantissa_digits
== other
.mantissa_digits
;
162 lst::enumeration_type::enumeration_type(unsigned int in_alignment
,
163 enum lst::byte_order in_byte_order
,
164 unsigned int in_size
,
165 enum signedness in_signedness
,
167 lst::integer_type::roles in_roles
) :
168 integer_type(in_alignment
,
181 void lst::signed_enumeration_type::accept(type_visitor
& visitor
) const
183 visitor
.visit(*this);
187 void lst::unsigned_enumeration_type::accept(type_visitor
& visitor
) const
189 visitor
.visit(*this);
191 } /* namespace trace */
192 } /* namespace sessiond */
193 } /* namespace lttng */
195 lst::array_type::array_type(unsigned int in_alignment
, type::cuptr in_element_type
) :
196 type(in_alignment
), element_type
{std::move(in_element_type
)}
200 bool lst::array_type::_is_equal(const type
& base_other
) const noexcept
202 const auto& other
= static_cast<decltype(*this)&>(base_other
);
204 return *this->element_type
== *other
.element_type
;
207 lst::static_length_array_type::static_length_array_type(unsigned int in_alignment
,
208 type::cuptr in_element_type
,
209 uint64_t in_length
) :
210 array_type(in_alignment
, std::move(in_element_type
)),
215 bool lst::static_length_array_type::_is_equal(const type
& base_other
) const noexcept
217 const auto& other
= static_cast<decltype(*this)&>(base_other
);
219 return array_type::_is_equal(base_other
) && this->length
== other
.length
;
222 void lst::static_length_array_type::accept(type_visitor
& visitor
) const
224 visitor
.visit(*this);
227 lst::dynamic_length_array_type::dynamic_length_array_type(unsigned int in_alignment
,
228 type::cuptr in_element_type
,
229 lst::field_location in_length_field_location
) :
230 array_type(in_alignment
, std::move(in_element_type
)),
231 length_field_location
{std::move(in_length_field_location
)}
235 bool lst::dynamic_length_array_type::_is_equal(const type
& base_other
) const noexcept
237 const auto& other
= static_cast<decltype(*this)&>(base_other
);
239 return array_type::_is_equal(base_other
) &&
240 this->length_field_location
== other
.length_field_location
;
243 void lst::dynamic_length_array_type::accept(type_visitor
& visitor
) const
245 visitor
.visit(*this);
248 lst::static_length_blob_type::static_length_blob_type(
249 unsigned int in_alignment
, uint64_t in_length_bytes
, roles in_roles
) :
250 type(in_alignment
), length_bytes
{in_length_bytes
}, roles_
{std::move(in_roles
)}
254 bool lst::static_length_blob_type::_is_equal(const type
& base_other
) const noexcept
256 const auto& other
= static_cast<decltype(*this)&>(base_other
);
258 return length_bytes
== other
.length_bytes
&& roles_
== other
.roles_
;
261 void lst::static_length_blob_type::accept(type_visitor
& visitor
) const
263 visitor
.visit(*this);
266 lst::dynamic_length_blob_type::dynamic_length_blob_type(
267 unsigned int in_alignment
, lst::field_location in_length_field_location
) :
268 type(in_alignment
), length_field_location
{std::move(in_length_field_location
)}
272 bool lst::dynamic_length_blob_type::_is_equal(const type
& base_other
) const noexcept
274 const auto& other
= dynamic_cast<decltype(*this)&>(base_other
);
276 return length_field_location
== other
.length_field_location
;
279 void lst::dynamic_length_blob_type::accept(type_visitor
& visitor
) const
281 visitor
.visit(*this);
284 lst::string_type::string_type(unsigned int in_alignment
, enum encoding in_encoding
) :
285 type(in_alignment
), encoding_
{in_encoding
}
289 bool lst::string_type::_is_equal(const type
& base_other
) const noexcept
291 const auto& other
= static_cast<decltype(*this)&>(base_other
);
293 return this->encoding_
== other
.encoding_
;
296 lst::static_length_string_type::static_length_string_type(
297 unsigned int in_alignment
, enum encoding in_encoding
, uint64_t in_length
) :
298 string_type(in_alignment
, in_encoding
), length
{in_length
}
302 bool lst::static_length_string_type::_is_equal(const type
& base_other
) const noexcept
304 const auto& other
= static_cast<decltype(*this)&>(base_other
);
306 return string_type::_is_equal(base_other
) && this->length
== other
.length
;
309 void lst::static_length_string_type::accept(type_visitor
& visitor
) const
311 visitor
.visit(*this);
314 lst::dynamic_length_string_type::dynamic_length_string_type(unsigned int in_alignment
,
315 enum encoding in_encoding
,
316 field_location in_length_field_location
) :
317 string_type(in_alignment
, in_encoding
),
318 length_field_location
{std::move(in_length_field_location
)}
322 bool lst::dynamic_length_string_type::_is_equal(const type
& base_other
) const noexcept
324 const auto& other
= static_cast<decltype(*this)&>(base_other
);
326 return string_type::_is_equal(base_other
) &&
327 this->length_field_location
== other
.length_field_location
;
330 void lst::dynamic_length_string_type::accept(type_visitor
& visitor
) const
332 visitor
.visit(*this);
335 lst::null_terminated_string_type::null_terminated_string_type(unsigned int in_alignment
,
336 enum encoding in_encoding
) :
337 string_type(in_alignment
, in_encoding
)
341 void lst::null_terminated_string_type::accept(type_visitor
& visitor
) const
343 visitor
.visit(*this);
346 lst::structure_type::structure_type(unsigned int in_alignment
, fields in_fields
) :
347 type(in_alignment
), _fields
{std::move(in_fields
)}
351 bool lst::structure_type::_is_equal(const type
& base_other
) const noexcept
353 const auto &other
= static_cast<decltype(*this)&>(base_other
);
355 return fields_are_equal(this->_fields
, other
._fields
);
358 void lst::structure_type::accept(type_visitor
& visitor
) const
360 visitor
.visit(*this);
363 lst::variant_type::variant_type(unsigned int in_alignment
,
364 field_location in_selector_field_location
,
365 choices in_choices
) :
367 selector_field_location
{std::move(in_selector_field_location
)},
369 {std::move(in_choices
)}
373 bool lst::variant_type::_is_equal(const type
& base_other
) const noexcept
375 const auto &other
= static_cast<decltype(*this)&>(base_other
);
377 return this->selector_field_location
== other
.selector_field_location
&&
378 fields_are_equal(this->_choices
383 void lst::variant_type::accept(type_visitor
& visitor
) const
385 visitor
.visit(*this);