Commit | Line | Data |
---|---|---|
12435a68 PP |
1 | /* |
2 | * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
7 | #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP | |
8 | #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP | |
9 | ||
12435a68 | 10 | #include <cstdint> |
c802cacb SM |
11 | #include <type_traits> |
12 | ||
12435a68 PP |
13 | #include <babeltrace2/babeltrace.h> |
14 | ||
15 | #include "common/assert.h" | |
e7f0f07b | 16 | #include "cpp-common/bt2c/c-string-view.hpp" |
c022776a | 17 | #include "cpp-common/bt2s/optional.hpp" |
c802cacb | 18 | |
56862ee2 | 19 | #include "borrowed-object-iterator.hpp" |
0d218157 | 20 | #include "borrowed-object.hpp" |
39278ebc | 21 | #include "exc.hpp" |
12435a68 | 22 | #include "field-path.hpp" |
c802cacb | 23 | #include "integer-range-set.hpp" |
c802cacb | 24 | #include "internal/utils.hpp" |
ca61ecbc | 25 | #include "optional-borrowed-object.hpp" |
7f5cdaf0 | 26 | #include "shared-object.hpp" |
096c6be7 | 27 | #include "value.hpp" |
12435a68 PP |
28 | |
29 | namespace bt2 { | |
12435a68 PP |
30 | namespace internal { |
31 | ||
32 | struct FieldClassRefFuncs final | |
33 | { | |
c677c492 | 34 | static void get(const bt_field_class * const libObjPtr) noexcept |
12435a68 PP |
35 | { |
36 | bt_field_class_get_ref(libObjPtr); | |
37 | } | |
38 | ||
c677c492 | 39 | static void put(const bt_field_class * const libObjPtr) noexcept |
12435a68 PP |
40 | { |
41 | bt_field_class_put_ref(libObjPtr); | |
42 | } | |
43 | }; | |
44 | ||
12435a68 PP |
45 | template <typename LibObjT> |
46 | struct CommonFieldClassSpec; | |
47 | ||
b5f55e9f | 48 | /* Functions specific to mutable field classes */ |
12435a68 PP |
49 | template <> |
50 | struct CommonFieldClassSpec<bt_field_class> final | |
51 | { | |
52 | static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept | |
53 | { | |
54 | return bt_field_class_borrow_user_attributes(libObjPtr); | |
55 | } | |
56 | }; | |
57 | ||
b5f55e9f | 58 | /* Functions specific to constant field classes */ |
12435a68 PP |
59 | template <> |
60 | struct CommonFieldClassSpec<const bt_field_class> final | |
61 | { | |
62 | static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept | |
63 | { | |
64 | return bt_field_class_borrow_user_attributes_const(libObjPtr); | |
65 | } | |
66 | }; | |
67 | ||
b5f55e9f | 68 | } /* namespace internal */ |
12435a68 | 69 | |
26b9d24c | 70 | template <typename ObjT, typename LibObjT> |
7f5cdaf0 | 71 | using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>; |
26b9d24c | 72 | |
12435a68 PP |
73 | template <typename LibObjT> |
74 | class CommonBitArrayFieldClass; | |
75 | ||
76 | template <typename LibObjT> | |
77 | class CommonIntegerFieldClass; | |
78 | ||
79 | template <typename LibObjT> | |
80 | class ConstEnumerationFieldClassMapping; | |
81 | ||
be6aa636 FD |
82 | template <typename LibObjT> |
83 | class CommonBaseEnumerationFieldClass; | |
84 | ||
12435a68 PP |
85 | template <typename LibObjT, typename MappingT> |
86 | class CommonEnumerationFieldClass; | |
87 | ||
88 | template <typename LibObjT> | |
89 | class CommonStructureFieldClass; | |
90 | ||
91 | template <typename LibObjT> | |
92 | class CommonArrayFieldClass; | |
93 | ||
94 | template <typename LibObjT> | |
95 | class CommonStaticArrayFieldClass; | |
96 | ||
97 | template <typename LibObjT> | |
98 | class CommonDynamicArrayWithLengthFieldClass; | |
99 | ||
100 | template <typename LibObjT> | |
101 | class CommonOptionFieldClass; | |
102 | ||
103 | template <typename LibObjT> | |
104 | class CommonOptionWithSelectorFieldClass; | |
105 | ||
106 | template <typename LibObjT> | |
107 | class CommonOptionWithBoolSelectorFieldClass; | |
108 | ||
109 | template <typename LibObjT> | |
110 | class CommonVariantFieldClass; | |
111 | ||
112 | template <typename LibObjT, typename RangeSetT> | |
113 | class CommonOptionWithIntegerSelectorFieldClass; | |
114 | ||
115 | template <typename LibObjT> | |
116 | class CommonVariantWithoutSelectorFieldClass; | |
117 | ||
cefe03a2 FD |
118 | template <typename LibObjT> |
119 | class CommonVariantWithSelectorFieldClass; | |
120 | ||
12435a68 PP |
121 | template <typename LibObjT> |
122 | class ConstVariantWithIntegerSelectorFieldClassOption; | |
123 | ||
124 | template <typename LibObjT, typename RangeSetT> | |
125 | class CommonVariantWithIntegerSelectorFieldClass; | |
126 | ||
74fc764d PP |
127 | template <typename LibObjT> |
128 | class CommonEventClass; | |
129 | ||
130 | template <typename LibObjT> | |
131 | class CommonStreamClass; | |
132 | ||
133 | template <typename LibObjT> | |
134 | class CommonTraceClass; | |
135 | ||
12435a68 PP |
136 | enum class FieldClassType |
137 | { | |
138 | BOOL = BT_FIELD_CLASS_TYPE_BOOL, | |
139 | BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY, | |
140 | UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER, | |
141 | SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER, | |
142 | UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
143 | SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
144 | SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, | |
145 | DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, | |
146 | STRING = BT_FIELD_CLASS_TYPE_STRING, | |
147 | STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE, | |
148 | STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
149 | DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, | |
150 | DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, | |
151 | OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD, | |
152 | OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, | |
153 | OPTION_WITH_UNSIGNED_INTEGER_SELECTOR = | |
154 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, | |
155 | OPTION_WITH_SIGNED_INTEGER_SELECTOR = | |
156 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD, | |
157 | VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, | |
158 | VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR = | |
159 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, | |
160 | VARIANT_WITH_SIGNED_INTEGER_SELECTOR = | |
161 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, | |
162 | }; | |
163 | ||
164 | template <typename LibObjT> | |
0d218157 | 165 | class CommonFieldClass : public BorrowedObject<LibObjT> |
12435a68 | 166 | { |
12435a68 | 167 | private: |
0d218157 | 168 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
12435a68 PP |
169 | |
170 | protected: | |
12435a68 PP |
171 | using _ThisCommonFieldClass = CommonFieldClass<LibObjT>; |
172 | ||
173 | public: | |
d246c457 | 174 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
26b9d24c | 175 | using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>; |
8047a175 | 176 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
12435a68 | 177 | |
d246c457 | 178 | explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
179 | { |
180 | } | |
181 | ||
182 | template <typename OtherLibObjT> | |
0d218157 | 183 | CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc} |
12435a68 PP |
184 | { |
185 | } | |
186 | ||
187 | template <typename OtherLibObjT> | |
ac30a470 | 188 | CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept |
12435a68 | 189 | { |
0d218157 | 190 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
191 | return *this; |
192 | } | |
193 | ||
328a274a PP |
194 | CommonFieldClass<const bt_field_class> asConst() const noexcept |
195 | { | |
196 | return CommonFieldClass<const bt_field_class> {*this}; | |
197 | } | |
198 | ||
12435a68 PP |
199 | FieldClassType type() const noexcept |
200 | { | |
341a67c4 | 201 | return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr())); |
12435a68 PP |
202 | } |
203 | ||
204 | bool isBool() const noexcept | |
205 | { | |
206 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL); | |
207 | } | |
208 | ||
209 | bool isBitArray() const noexcept | |
210 | { | |
211 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY); | |
212 | } | |
213 | ||
214 | bool isInteger() const noexcept | |
215 | { | |
216 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER); | |
217 | } | |
218 | ||
219 | bool isUnsignedInteger() const noexcept | |
220 | { | |
221 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); | |
222 | } | |
223 | ||
224 | bool isSignedInteger() const noexcept | |
225 | { | |
226 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); | |
227 | } | |
228 | ||
229 | bool isEnumeration() const noexcept | |
230 | { | |
231 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION); | |
232 | } | |
233 | ||
234 | bool isUnsignedEnumeration() const noexcept | |
235 | { | |
236 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); | |
237 | } | |
238 | ||
239 | bool isSignedEnumeration() const noexcept | |
240 | { | |
241 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); | |
242 | } | |
243 | ||
ff620936 FD |
244 | bool isReal() const noexcept |
245 | { | |
246 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL); | |
247 | } | |
248 | ||
12435a68 PP |
249 | bool isSinglePrecisionReal() const noexcept |
250 | { | |
251 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); | |
252 | } | |
253 | ||
254 | bool isDoublePrecisionReal() const noexcept | |
255 | { | |
256 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); | |
257 | } | |
258 | ||
259 | bool isString() const noexcept | |
260 | { | |
261 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING); | |
262 | } | |
263 | ||
264 | bool isStructure() const noexcept | |
265 | { | |
266 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE); | |
267 | } | |
268 | ||
269 | bool isArray() const noexcept | |
270 | { | |
271 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY); | |
272 | } | |
273 | ||
274 | bool isStaticArray() const noexcept | |
275 | { | |
276 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY); | |
277 | } | |
278 | ||
279 | bool isDynamicArray() const noexcept | |
280 | { | |
281 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY); | |
282 | } | |
283 | ||
284 | bool isDynamicArrayWithoutLength() const noexcept | |
285 | { | |
286 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD); | |
287 | } | |
288 | ||
289 | bool isDynamicArrayWithLength() const noexcept | |
290 | { | |
291 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); | |
292 | } | |
293 | ||
294 | bool isOption() const noexcept | |
295 | { | |
296 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION); | |
297 | } | |
298 | ||
299 | bool isOptionWithoutSelector() const noexcept | |
300 | { | |
301 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD); | |
302 | } | |
303 | ||
304 | bool isOptionWithSelector() const noexcept | |
305 | { | |
306 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD); | |
307 | } | |
308 | ||
309 | bool isOptionWithBoolSelector() const noexcept | |
310 | { | |
311 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD); | |
312 | } | |
313 | ||
314 | bool isOptionWithIntegerSelector() const noexcept | |
315 | { | |
316 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD); | |
317 | } | |
318 | ||
319 | bool isOptionWithUnsignedIntegerSelector() const noexcept | |
320 | { | |
321 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); | |
322 | } | |
323 | ||
324 | bool isOptionWithSignedIntegerSelector() const noexcept | |
325 | { | |
326 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD); | |
327 | } | |
328 | ||
329 | bool isVariant() const noexcept | |
330 | { | |
331 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT); | |
332 | } | |
333 | ||
334 | bool isVariantWithoutSelector() const noexcept | |
335 | { | |
336 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); | |
337 | } | |
338 | ||
339 | bool isVariantWithSelector() const noexcept | |
340 | { | |
341 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD); | |
342 | } | |
343 | ||
344 | bool isVariantWithIntegerSelector() const noexcept | |
345 | { | |
346 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD); | |
347 | } | |
348 | ||
349 | bool isVariantWithUnsignedIntegerSelector() const noexcept | |
350 | { | |
351 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); | |
352 | } | |
353 | ||
354 | bool isVariantWithSignedIntegerSelector() const noexcept | |
355 | { | |
356 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD); | |
357 | } | |
358 | ||
45e0ded5 PP |
359 | template <typename FieldClassT> |
360 | FieldClassT as() const noexcept | |
361 | { | |
362 | return FieldClassT {this->libObjPtr()}; | |
363 | } | |
364 | ||
12435a68 PP |
365 | CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept; |
366 | CommonIntegerFieldClass<LibObjT> asInteger() const noexcept; | |
be6aa636 | 367 | CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept; |
12435a68 PP |
368 | CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping< |
369 | const bt_field_class_enumeration_unsigned_mapping>> | |
370 | asUnsignedEnumeration() const noexcept; | |
371 | ||
372 | CommonEnumerationFieldClass< | |
373 | LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>> | |
374 | asSignedEnumeration() const noexcept; | |
375 | ||
376 | CommonStructureFieldClass<LibObjT> asStructure() const noexcept; | |
377 | CommonArrayFieldClass<LibObjT> asArray() const noexcept; | |
378 | CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept; | |
379 | CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept; | |
380 | CommonOptionFieldClass<LibObjT> asOption() const noexcept; | |
381 | CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept; | |
382 | CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept; | |
383 | ||
384 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> | |
385 | asOptionWithUnsignedIntegerSelector() const noexcept; | |
386 | ||
387 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> | |
388 | asOptionWithSignedIntegerSelector() const noexcept; | |
389 | ||
390 | CommonVariantFieldClass<LibObjT> asVariant() const noexcept; | |
391 | CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept; | |
cefe03a2 | 392 | CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept; |
12435a68 PP |
393 | |
394 | CommonVariantWithIntegerSelectorFieldClass< | |
395 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< | |
396 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>> | |
397 | asVariantWithUnsignedIntegerSelector() const noexcept; | |
398 | ||
399 | CommonVariantWithIntegerSelectorFieldClass< | |
400 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< | |
401 | const bt_field_class_variant_with_selector_field_integer_signed_option>> | |
402 | asVariantWithSignedIntegerSelector() const noexcept; | |
403 | ||
404 | template <typename LibValT> | |
2a24eba8 | 405 | CommonFieldClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
12435a68 | 406 | { |
5c895f64 | 407 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`."); |
12435a68 | 408 | |
341a67c4 | 409 | bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
2a24eba8 | 410 | return *this; |
12435a68 PP |
411 | } |
412 | ||
dcb8ae9b | 413 | UserAttributes userAttributes() const noexcept |
12435a68 PP |
414 | { |
415 | return UserAttributes { | |
341a67c4 | 416 | internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())}; |
12435a68 PP |
417 | } |
418 | ||
419 | Shared shared() const noexcept | |
420 | { | |
c9c0b6e2 | 421 | return Shared::createWithRef(*this); |
12435a68 PP |
422 | } |
423 | ||
424 | protected: | |
425 | bool _libTypeIs(const bt_field_class_type type) const noexcept | |
426 | { | |
341a67c4 | 427 | return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type); |
12435a68 PP |
428 | } |
429 | }; | |
430 | ||
431 | using FieldClass = CommonFieldClass<bt_field_class>; | |
432 | using ConstFieldClass = CommonFieldClass<const bt_field_class>; | |
433 | ||
4927bae7 PP |
434 | namespace internal { |
435 | ||
436 | struct FieldClassTypeDescr | |
437 | { | |
438 | using Const = ConstFieldClass; | |
439 | using NonConst = FieldClass; | |
440 | }; | |
441 | ||
442 | template <> | |
443 | struct TypeDescr<FieldClass> : public FieldClassTypeDescr | |
444 | { | |
445 | }; | |
446 | ||
447 | template <> | |
448 | struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr | |
449 | { | |
450 | }; | |
451 | ||
452 | } /* namespace internal */ | |
453 | ||
12435a68 PP |
454 | template <typename LibObjT> |
455 | class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT> | |
456 | { | |
457 | private: | |
12435a68 PP |
458 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
459 | ||
460 | public: | |
d246c457 | 461 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 462 | using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>; |
12435a68 | 463 | |
d246c457 | 464 | explicit CommonBitArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
465 | _ThisCommonFieldClass {libObjPtr} |
466 | { | |
467 | BT_ASSERT_DBG(this->isBitArray()); | |
468 | } | |
469 | ||
470 | template <typename OtherLibObjT> | |
100fa861 | 471 | CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
472 | _ThisCommonFieldClass {fc} |
473 | { | |
474 | } | |
475 | ||
476 | template <typename OtherLibObjT> | |
ac30a470 | 477 | CommonBitArrayFieldClass<LibObjT> |
100fa861 | 478 | operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
479 | { |
480 | _ThisCommonFieldClass::operator=(fc); | |
481 | return *this; | |
482 | } | |
483 | ||
328a274a PP |
484 | CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept |
485 | { | |
486 | return CommonBitArrayFieldClass<const bt_field_class> {*this}; | |
487 | } | |
488 | ||
12435a68 PP |
489 | std::uint64_t length() const noexcept |
490 | { | |
341a67c4 | 491 | return bt_field_class_bit_array_get_length(this->libObjPtr()); |
12435a68 PP |
492 | } |
493 | ||
494 | Shared shared() const noexcept | |
495 | { | |
c9c0b6e2 | 496 | return Shared::createWithRef(*this); |
12435a68 PP |
497 | } |
498 | }; | |
499 | ||
500 | using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>; | |
501 | using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>; | |
502 | ||
4927bae7 PP |
503 | namespace internal { |
504 | ||
505 | struct BitArrayFieldClassTypeDescr | |
506 | { | |
507 | using Const = ConstBitArrayFieldClass; | |
508 | using NonConst = BitArrayFieldClass; | |
509 | }; | |
510 | ||
511 | template <> | |
512 | struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr | |
513 | { | |
514 | }; | |
515 | ||
516 | template <> | |
517 | struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr | |
518 | { | |
519 | }; | |
520 | ||
521 | } /* namespace internal */ | |
522 | ||
12435a68 PP |
523 | enum class DisplayBase |
524 | { | |
525 | BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY, | |
526 | OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL, | |
527 | DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL, | |
528 | HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL, | |
529 | }; | |
530 | ||
531 | template <typename LibObjT> | |
532 | class CommonIntegerFieldClass : public CommonFieldClass<LibObjT> | |
533 | { | |
534 | private: | |
535 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
536 | ||
537 | protected: | |
12435a68 PP |
538 | using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>; |
539 | ||
540 | public: | |
d246c457 | 541 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 542 | using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>; |
12435a68 | 543 | |
d246c457 | 544 | explicit CommonIntegerFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
545 | _ThisCommonFieldClass {libObjPtr} |
546 | { | |
547 | BT_ASSERT_DBG(this->isInteger()); | |
548 | } | |
549 | ||
550 | template <typename OtherLibObjT> | |
100fa861 | 551 | CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
552 | _ThisCommonFieldClass {fc} |
553 | { | |
554 | } | |
555 | ||
556 | template <typename OtherLibObjT> | |
ac30a470 | 557 | CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
558 | { |
559 | _ThisCommonFieldClass::operator=(fc); | |
560 | return *this; | |
561 | } | |
562 | ||
328a274a PP |
563 | CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept |
564 | { | |
565 | return CommonIntegerFieldClass<const bt_field_class> {*this}; | |
566 | } | |
567 | ||
2a24eba8 | 568 | CommonIntegerFieldClass fieldValueRange(const std::uint64_t n) const noexcept |
12435a68 | 569 | { |
5c895f64 PP |
570 | static_assert(!std::is_const<LibObjT>::value, |
571 | "Not available with `bt2::ConstIntegerFieldClass`."); | |
12435a68 | 572 | |
78017fef | 573 | bt_field_class_integer_set_field_value_range(this->libObjPtr(), n); |
2a24eba8 | 574 | return *this; |
12435a68 PP |
575 | } |
576 | ||
577 | std::uint64_t fieldValueRange() const noexcept | |
578 | { | |
341a67c4 | 579 | return bt_field_class_integer_get_field_value_range(this->libObjPtr()); |
12435a68 PP |
580 | } |
581 | ||
2a24eba8 | 582 | CommonIntegerFieldClass preferredDisplayBase(const DisplayBase base) const noexcept |
12435a68 | 583 | { |
5c895f64 PP |
584 | static_assert(!std::is_const<LibObjT>::value, |
585 | "Not available with `bt2::ConstIntegerFieldClass`."); | |
12435a68 PP |
586 | |
587 | bt_field_class_integer_set_preferred_display_base( | |
341a67c4 | 588 | this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base)); |
2a24eba8 | 589 | return *this; |
12435a68 PP |
590 | } |
591 | ||
592 | DisplayBase preferredDisplayBase() const noexcept | |
593 | { | |
594 | return static_cast<DisplayBase>( | |
341a67c4 | 595 | bt_field_class_integer_get_preferred_display_base(this->libObjPtr())); |
12435a68 PP |
596 | } |
597 | ||
598 | Shared shared() const noexcept | |
599 | { | |
c9c0b6e2 | 600 | return Shared::createWithRef(*this); |
12435a68 PP |
601 | } |
602 | }; | |
603 | ||
604 | using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>; | |
605 | using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>; | |
606 | ||
607 | namespace internal { | |
608 | ||
4927bae7 PP |
609 | struct IntegerFieldClassTypeDescr |
610 | { | |
611 | using Const = ConstIntegerFieldClass; | |
612 | using NonConst = IntegerFieldClass; | |
613 | }; | |
614 | ||
615 | template <> | |
616 | struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr | |
617 | { | |
618 | }; | |
619 | ||
620 | template <> | |
621 | struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr | |
622 | { | |
623 | }; | |
624 | ||
12435a68 PP |
625 | template <typename LibObjT> |
626 | struct ConstEnumerationFieldClassMappingSpec; | |
627 | ||
b5f55e9f | 628 | /* Functions specific to unsigned enumeration field class mappings */ |
12435a68 PP |
629 | template <> |
630 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping> | |
631 | final | |
632 | { | |
633 | static const bt_integer_range_set_unsigned * | |
634 | ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept | |
635 | { | |
636 | return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr); | |
637 | } | |
638 | ||
639 | static const char * | |
640 | label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept | |
641 | { | |
642 | return bt_field_class_enumeration_mapping_get_label( | |
643 | bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr)); | |
644 | } | |
645 | }; | |
646 | ||
b5f55e9f | 647 | /* Functions specific to signed enumeration field class mappings */ |
12435a68 PP |
648 | template <> |
649 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final | |
650 | { | |
651 | static const bt_integer_range_set_signed * | |
652 | ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept | |
653 | { | |
654 | return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr); | |
655 | } | |
656 | ||
657 | static const char * | |
658 | label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept | |
659 | { | |
660 | return bt_field_class_enumeration_mapping_get_label( | |
661 | bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr)); | |
662 | } | |
663 | }; | |
664 | ||
b5f55e9f | 665 | } /* namespace internal */ |
12435a68 PP |
666 | |
667 | template <typename LibObjT> | |
0d218157 | 668 | class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT> |
12435a68 PP |
669 | { |
670 | private: | |
0d218157 | 671 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
12435a68 PP |
672 | |
673 | public: | |
d246c457 PP |
674 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
675 | ||
12435a68 PP |
676 | using RangeSet = typename std::conditional< |
677 | std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value, | |
678 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; | |
679 | ||
d246c457 | 680 | explicit ConstEnumerationFieldClassMapping(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 681 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
682 | { |
683 | } | |
684 | ||
0d6ad4d8 | 685 | ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept : |
0d218157 | 686 | _ThisBorrowedObject {mapping} |
12435a68 PP |
687 | { |
688 | } | |
689 | ||
ac30a470 | 690 | ConstEnumerationFieldClassMapping |
0d6ad4d8 | 691 | operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept |
12435a68 | 692 | { |
0d218157 | 693 | _ThisBorrowedObject::operator=(mapping); |
12435a68 PP |
694 | return *this; |
695 | } | |
696 | ||
697 | RangeSet ranges() const noexcept | |
698 | { | |
699 | return RangeSet { | |
341a67c4 | 700 | internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())}; |
12435a68 PP |
701 | } |
702 | ||
e7f0f07b | 703 | bt2c::CStringView label() const noexcept |
12435a68 | 704 | { |
341a67c4 | 705 | return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr()); |
12435a68 PP |
706 | } |
707 | }; | |
708 | ||
709 | using ConstUnsignedEnumerationFieldClassMapping = | |
710 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>; | |
711 | ||
712 | using ConstSignedEnumerationFieldClassMapping = | |
713 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>; | |
714 | ||
715 | namespace internal { | |
716 | ||
717 | template <typename MappingT> | |
718 | struct CommonEnumerationFieldClassSpec; | |
719 | ||
b5f55e9f | 720 | /* Functions specific to unsigned enumeration field classes */ |
12435a68 PP |
721 | template <> |
722 | struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final | |
723 | { | |
724 | static const bt_field_class_enumeration_unsigned_mapping * | |
725 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
726 | { | |
727 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index); | |
728 | } | |
729 | ||
730 | static const bt_field_class_enumeration_unsigned_mapping * | |
731 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept | |
732 | { | |
733 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label); | |
734 | } | |
5d6ccdae PP |
735 | |
736 | static bt_field_class_enumeration_add_mapping_status | |
737 | addMapping(bt_field_class * const libObjPtr, const char * const label, | |
738 | const bt_integer_range_set_unsigned * const libRanges) noexcept | |
739 | { | |
740 | return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges); | |
741 | } | |
12435a68 PP |
742 | }; |
743 | ||
b5f55e9f | 744 | /* Functions specific to signed enumeration field classes */ |
12435a68 PP |
745 | template <> |
746 | struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final | |
747 | { | |
748 | static const bt_field_class_enumeration_signed_mapping * | |
749 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
750 | { | |
751 | return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index); | |
752 | } | |
753 | ||
754 | static const bt_field_class_enumeration_signed_mapping * | |
755 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept | |
756 | { | |
757 | return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label); | |
758 | } | |
5d6ccdae PP |
759 | |
760 | static bt_field_class_enumeration_add_mapping_status | |
761 | addMapping(bt_field_class * const libObjPtr, const char * const label, | |
762 | const bt_integer_range_set_signed * const libRanges) noexcept | |
763 | { | |
764 | return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges); | |
765 | } | |
12435a68 PP |
766 | }; |
767 | ||
b5f55e9f | 768 | } /* namespace internal */ |
12435a68 | 769 | |
be6aa636 FD |
770 | template <typename LibObjT> |
771 | class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT> | |
772 | { | |
773 | private: | |
774 | using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass; | |
775 | ||
776 | protected: | |
be6aa636 FD |
777 | using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>; |
778 | ||
779 | public: | |
d246c457 | 780 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 781 | using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>; |
be6aa636 | 782 | |
d246c457 | 783 | explicit CommonBaseEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept : |
be6aa636 FD |
784 | _ThisCommonIntegerFieldClass {libObjPtr} |
785 | { | |
786 | BT_ASSERT_DBG(this->isEnumeration()); | |
787 | } | |
788 | ||
789 | template <typename OtherLibObjT> | |
100fa861 PP |
790 | CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
791 | : | |
be6aa636 FD |
792 | _ThisCommonIntegerFieldClass {fc} |
793 | { | |
794 | } | |
795 | ||
796 | template <typename OtherLibObjT> | |
ac30a470 | 797 | CommonBaseEnumerationFieldClass |
100fa861 | 798 | operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
be6aa636 FD |
799 | { |
800 | _ThisCommonIntegerFieldClass::operator=(fc); | |
801 | return *this; | |
802 | } | |
803 | ||
328a274a PP |
804 | CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept |
805 | { | |
806 | return CommonBaseEnumerationFieldClass<const bt_field_class> {*this}; | |
807 | } | |
808 | ||
c0b73c63 | 809 | std::uint64_t length() const noexcept |
be6aa636 | 810 | { |
341a67c4 | 811 | return bt_field_class_enumeration_get_mapping_count(this->libObjPtr()); |
be6aa636 FD |
812 | } |
813 | ||
814 | Shared shared() const noexcept | |
815 | { | |
c9c0b6e2 | 816 | return Shared::createWithRef(*this); |
be6aa636 FD |
817 | } |
818 | }; | |
819 | ||
12435a68 | 820 | template <typename LibObjT, typename MappingT> |
be6aa636 | 821 | class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT> |
12435a68 PP |
822 | { |
823 | private: | |
be6aa636 | 824 | using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass; |
12435a68 PP |
825 | |
826 | public: | |
d246c457 | 827 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
ac19444e | 828 | using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>; |
56862ee2 | 829 | using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>; |
12435a68 PP |
830 | using Mapping = MappingT; |
831 | ||
d246c457 | 832 | explicit CommonEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept : |
be6aa636 | 833 | _ThisCommonBaseEnumerationFieldClass {libObjPtr} |
12435a68 PP |
834 | { |
835 | BT_ASSERT_DBG(this->isEnumeration()); | |
836 | } | |
837 | ||
838 | template <typename OtherLibObjT> | |
839 | CommonEnumerationFieldClass( | |
100fa861 | 840 | const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept : |
ac19444e | 841 | CommonEnumerationFieldClass {fc} |
12435a68 PP |
842 | { |
843 | } | |
844 | ||
845 | template <typename OtherLibObjT> | |
ac30a470 | 846 | CommonEnumerationFieldClass |
100fa861 | 847 | operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept |
12435a68 | 848 | { |
ac19444e | 849 | CommonEnumerationFieldClass::operator=(fc); |
12435a68 PP |
850 | return *this; |
851 | } | |
852 | ||
12435a68 PP |
853 | Mapping operator[](const std::uint64_t index) const noexcept |
854 | { | |
855 | return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex( | |
341a67c4 | 856 | this->libObjPtr(), index)}; |
12435a68 PP |
857 | } |
858 | ||
15030982 | 859 | OptionalBorrowedObject<Mapping> operator[](const bt2c::CStringView label) const noexcept |
12435a68 | 860 | { |
ca61ecbc | 861 | return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel( |
341a67c4 | 862 | this->libObjPtr(), label); |
12435a68 PP |
863 | } |
864 | ||
2a24eba8 SM |
865 | CommonEnumerationFieldClass addMapping(const bt2c::CStringView label, |
866 | const typename Mapping::RangeSet ranges) const | |
5d6ccdae PP |
867 | { |
868 | const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping( | |
869 | this->libObjPtr(), label, ranges.libObjPtr()); | |
870 | ||
871 | if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) { | |
39278ebc | 872 | throw MemoryError {}; |
5d6ccdae | 873 | } |
2a24eba8 SM |
874 | |
875 | return *this; | |
5d6ccdae PP |
876 | } |
877 | ||
e5a8a7c4 FD |
878 | Iterator begin() const noexcept |
879 | { | |
880 | return Iterator {*this, 0}; | |
881 | } | |
882 | ||
883 | Iterator end() const noexcept | |
884 | { | |
c0b73c63 | 885 | return Iterator {*this, this->length()}; |
e5a8a7c4 FD |
886 | } |
887 | ||
12435a68 PP |
888 | Shared shared() const noexcept |
889 | { | |
c9c0b6e2 | 890 | return Shared::createWithRef(*this); |
12435a68 PP |
891 | } |
892 | }; | |
893 | ||
be6aa636 FD |
894 | using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>; |
895 | using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>; | |
896 | ||
12435a68 PP |
897 | using UnsignedEnumerationFieldClass = |
898 | CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
899 | ||
900 | using ConstUnsignedEnumerationFieldClass = | |
901 | CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
902 | ||
903 | using SignedEnumerationFieldClass = | |
904 | CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
905 | ||
906 | using ConstSignedEnumerationFieldClass = | |
907 | CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
908 | ||
909 | namespace internal { | |
910 | ||
4927bae7 PP |
911 | struct UnsignedEnumerationFieldClassTypeDescr |
912 | { | |
913 | using Const = ConstUnsignedEnumerationFieldClass; | |
914 | using NonConst = UnsignedEnumerationFieldClass; | |
915 | }; | |
916 | ||
917 | template <> | |
918 | struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr | |
919 | { | |
920 | }; | |
921 | ||
922 | template <> | |
923 | struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr | |
924 | { | |
925 | }; | |
926 | ||
927 | struct SignedEnumerationFieldClassTypeDescr | |
928 | { | |
929 | using Const = ConstSignedEnumerationFieldClass; | |
930 | using NonConst = SignedEnumerationFieldClass; | |
931 | }; | |
932 | ||
933 | template <> | |
934 | struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr | |
935 | { | |
936 | }; | |
937 | ||
938 | template <> | |
939 | struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr | |
940 | { | |
941 | }; | |
942 | ||
12435a68 PP |
943 | template <typename LibObjT> |
944 | struct CommonStructureFieldClassMemberSpec; | |
945 | ||
b5f55e9f | 946 | /* Functions specific to mutable structure field class members */ |
12435a68 PP |
947 | template <> |
948 | struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final | |
949 | { | |
950 | static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept | |
951 | { | |
952 | return bt_field_class_structure_member_borrow_field_class(libObjPtr); | |
953 | } | |
8e557120 PP |
954 | |
955 | static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept | |
956 | { | |
957 | return bt_field_class_structure_member_borrow_user_attributes(libObjPtr); | |
958 | } | |
12435a68 PP |
959 | }; |
960 | ||
b5f55e9f | 961 | /* Functions specific to constant structure field class members */ |
12435a68 PP |
962 | template <> |
963 | struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final | |
964 | { | |
965 | static const bt_field_class * | |
966 | fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept | |
967 | { | |
968 | return bt_field_class_structure_member_borrow_field_class_const(libObjPtr); | |
969 | } | |
8e557120 PP |
970 | |
971 | static const bt_value * | |
972 | userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept | |
973 | { | |
974 | return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr); | |
975 | } | |
12435a68 PP |
976 | }; |
977 | ||
b5f55e9f | 978 | } /* namespace internal */ |
12435a68 PP |
979 | |
980 | template <typename LibObjT> | |
0d218157 | 981 | class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT> |
12435a68 PP |
982 | { |
983 | private: | |
0d218157 | 984 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
8047a175 | 985 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
986 | |
987 | public: | |
d246c457 | 988 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
8047a175 | 989 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
8e557120 | 990 | |
d246c457 | 991 | explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 992 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
993 | { |
994 | } | |
995 | ||
996 | template <typename OtherLibObjT> | |
100fa861 PP |
997 | CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
998 | : | |
0d218157 | 999 | _ThisBorrowedObject {fc} |
12435a68 PP |
1000 | { |
1001 | } | |
1002 | ||
1003 | template <typename OtherLibObjT> | |
ac30a470 | 1004 | CommonStructureFieldClassMember<LibObjT> |
100fa861 | 1005 | operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
12435a68 | 1006 | { |
0d218157 | 1007 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
1008 | return *this; |
1009 | } | |
1010 | ||
328a274a PP |
1011 | CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept |
1012 | { | |
1013 | return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this}; | |
1014 | } | |
1015 | ||
e7f0f07b | 1016 | bt2c::CStringView name() const noexcept |
12435a68 | 1017 | { |
341a67c4 | 1018 | return bt_field_class_structure_member_get_name(this->libObjPtr()); |
12435a68 PP |
1019 | } |
1020 | ||
dcb8ae9b | 1021 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1022 | { |
1023 | return _FieldClass { | |
341a67c4 | 1024 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 | 1025 | } |
8e557120 PP |
1026 | |
1027 | template <typename LibValT> | |
2a24eba8 SM |
1028 | CommonStructureFieldClassMember |
1029 | userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept | |
8e557120 | 1030 | { |
5c895f64 PP |
1031 | static_assert(!std::is_const<LibObjT>::value, |
1032 | "Not available with `bt2::ConstStructureFieldClassMember`."); | |
8e557120 PP |
1033 | |
1034 | bt_field_class_structure_member_set_user_attributes(this->libObjPtr(), | |
1035 | userAttrs.libObjPtr()); | |
2a24eba8 | 1036 | return *this; |
8e557120 PP |
1037 | } |
1038 | ||
dcb8ae9b | 1039 | UserAttributes userAttributes() const noexcept |
8e557120 PP |
1040 | { |
1041 | return UserAttributes { | |
1042 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes( | |
1043 | this->libObjPtr())}; | |
1044 | } | |
12435a68 PP |
1045 | }; |
1046 | ||
1047 | using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>; | |
1048 | ||
1049 | using ConstStructureFieldClassMember = | |
1050 | CommonStructureFieldClassMember<const bt_field_class_structure_member>; | |
1051 | ||
1052 | namespace internal { | |
1053 | ||
4927bae7 PP |
1054 | struct StructureFieldClassMemberTypeDescr |
1055 | { | |
1056 | using Const = ConstStructureFieldClassMember; | |
1057 | using NonConst = StructureFieldClassMember; | |
1058 | }; | |
1059 | ||
1060 | template <> | |
1061 | struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr | |
1062 | { | |
1063 | }; | |
1064 | ||
1065 | template <> | |
1066 | struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr | |
1067 | { | |
1068 | }; | |
1069 | ||
12435a68 PP |
1070 | template <typename LibObjT> |
1071 | struct CommonStructureFieldClassSpec; | |
1072 | ||
b5f55e9f | 1073 | /* Functions specific to mutable structure field classes */ |
12435a68 PP |
1074 | template <> |
1075 | struct CommonStructureFieldClassSpec<bt_field_class> final | |
1076 | { | |
1077 | static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr, | |
1078 | const std::uint64_t index) noexcept | |
1079 | { | |
1080 | return bt_field_class_structure_borrow_member_by_index(libObjPtr, index); | |
1081 | } | |
1082 | ||
1083 | static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr, | |
1084 | const char * const name) noexcept | |
1085 | { | |
1086 | return bt_field_class_structure_borrow_member_by_name(libObjPtr, name); | |
1087 | } | |
1088 | }; | |
1089 | ||
b5f55e9f | 1090 | /* Functions specific to constant structure field classes */ |
12435a68 PP |
1091 | template <> |
1092 | struct CommonStructureFieldClassSpec<const bt_field_class> final | |
1093 | { | |
1094 | static const bt_field_class_structure_member * | |
1095 | memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
1096 | { | |
1097 | return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index); | |
1098 | } | |
1099 | ||
1100 | static const bt_field_class_structure_member * | |
1101 | memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
1102 | { | |
1103 | return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name); | |
1104 | } | |
1105 | }; | |
1106 | ||
b5f55e9f | 1107 | } /* namespace internal */ |
12435a68 PP |
1108 | |
1109 | template <typename LibObjT> | |
1110 | class CommonStructureFieldClass final : public CommonFieldClass<LibObjT> | |
1111 | { | |
1112 | private: | |
12435a68 PP |
1113 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
1114 | ||
1115 | public: | |
d246c457 | 1116 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1117 | using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>; |
56862ee2 | 1118 | using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>; |
8047a175 | 1119 | |
12435a68 | 1120 | using Member = |
8047a175 | 1121 | internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>; |
12435a68 | 1122 | |
d246c457 | 1123 | explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1124 | _ThisCommonFieldClass {libObjPtr} |
1125 | { | |
1126 | BT_ASSERT_DBG(this->isStructure()); | |
1127 | } | |
1128 | ||
1129 | template <typename OtherLibObjT> | |
100fa861 | 1130 | CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1131 | _ThisCommonFieldClass {fc} |
1132 | { | |
1133 | } | |
1134 | ||
1135 | template <typename OtherLibObjT> | |
ac30a470 | 1136 | CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1137 | { |
1138 | _ThisCommonFieldClass::operator=(fc); | |
1139 | return *this; | |
1140 | } | |
1141 | ||
328a274a PP |
1142 | CommonStructureFieldClass<const bt_field_class> asConst() const noexcept |
1143 | { | |
1144 | return CommonStructureFieldClass<const bt_field_class> {*this}; | |
1145 | } | |
1146 | ||
2a24eba8 | 1147 | CommonStructureFieldClass appendMember(const bt2c::CStringView name, const FieldClass fc) const |
12435a68 | 1148 | { |
5c895f64 PP |
1149 | static_assert(!std::is_const<LibObjT>::value, |
1150 | "Not available with `bt2::ConstStructureFieldClass`."); | |
12435a68 PP |
1151 | |
1152 | const auto status = | |
341a67c4 | 1153 | bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr()); |
12435a68 PP |
1154 | |
1155 | if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { | |
39278ebc | 1156 | throw MemoryError {}; |
12435a68 | 1157 | } |
2a24eba8 SM |
1158 | |
1159 | return *this; | |
12435a68 PP |
1160 | } |
1161 | ||
c0b73c63 | 1162 | std::uint64_t length() const noexcept |
12435a68 | 1163 | { |
341a67c4 | 1164 | return bt_field_class_structure_get_member_count(this->libObjPtr()); |
12435a68 PP |
1165 | } |
1166 | ||
5046c776 FD |
1167 | Iterator begin() const noexcept |
1168 | { | |
1169 | return Iterator {*this, 0}; | |
1170 | } | |
1171 | ||
1172 | Iterator end() const noexcept | |
1173 | { | |
c0b73c63 | 1174 | return Iterator {*this, this->length()}; |
5046c776 FD |
1175 | } |
1176 | ||
dcb8ae9b | 1177 | Member operator[](const std::uint64_t index) const noexcept |
12435a68 PP |
1178 | { |
1179 | return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex( | |
341a67c4 | 1180 | this->libObjPtr(), index)}; |
12435a68 PP |
1181 | } |
1182 | ||
15030982 | 1183 | OptionalBorrowedObject<Member> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 1184 | { |
ca61ecbc PP |
1185 | return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), |
1186 | name); | |
12435a68 PP |
1187 | } |
1188 | ||
12435a68 PP |
1189 | Shared shared() const noexcept |
1190 | { | |
c9c0b6e2 | 1191 | return Shared::createWithRef(*this); |
12435a68 PP |
1192 | } |
1193 | }; | |
1194 | ||
1195 | using StructureFieldClass = CommonStructureFieldClass<bt_field_class>; | |
1196 | using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>; | |
1197 | ||
1198 | namespace internal { | |
1199 | ||
4927bae7 PP |
1200 | struct StructureFieldClassTypeDescr |
1201 | { | |
1202 | using Const = ConstStructureFieldClass; | |
1203 | using NonConst = StructureFieldClass; | |
1204 | }; | |
1205 | ||
1206 | template <> | |
1207 | struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr | |
1208 | { | |
1209 | }; | |
1210 | ||
1211 | template <> | |
1212 | struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr | |
1213 | { | |
1214 | }; | |
1215 | ||
12435a68 PP |
1216 | template <typename LibObjT> |
1217 | struct CommonArrayFieldClassSpec; | |
1218 | ||
b5f55e9f | 1219 | /* Functions specific to mutable array field classes */ |
12435a68 PP |
1220 | template <> |
1221 | struct CommonArrayFieldClassSpec<bt_field_class> final | |
1222 | { | |
1223 | static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept | |
1224 | { | |
1225 | return bt_field_class_array_borrow_element_field_class(libObjPtr); | |
1226 | } | |
1227 | }; | |
1228 | ||
b5f55e9f | 1229 | /* Functions specific to constant array field classes */ |
12435a68 PP |
1230 | template <> |
1231 | struct CommonArrayFieldClassSpec<const bt_field_class> final | |
1232 | { | |
1233 | static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept | |
1234 | { | |
1235 | return bt_field_class_array_borrow_element_field_class_const(libObjPtr); | |
1236 | } | |
1237 | }; | |
1238 | ||
b5f55e9f | 1239 | } /* namespace internal */ |
12435a68 PP |
1240 | |
1241 | template <typename LibObjT> | |
1242 | class CommonArrayFieldClass : public CommonFieldClass<LibObjT> | |
1243 | { | |
1244 | private: | |
1245 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
8047a175 | 1246 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1247 | |
1248 | protected: | |
12435a68 PP |
1249 | using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>; |
1250 | ||
1251 | public: | |
d246c457 | 1252 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1253 | using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1254 | |
d246c457 | 1255 | explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1256 | _ThisCommonFieldClass {libObjPtr} |
1257 | { | |
1258 | BT_ASSERT_DBG(this->isArray()); | |
1259 | } | |
1260 | ||
1261 | template <typename OtherLibObjT> | |
100fa861 | 1262 | CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1263 | _ThisCommonFieldClass {fc} |
1264 | { | |
1265 | } | |
1266 | ||
1267 | template <typename OtherLibObjT> | |
ac30a470 | 1268 | CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1269 | { |
1270 | _ThisCommonFieldClass::operator=(fc); | |
1271 | return *this; | |
1272 | } | |
1273 | ||
328a274a PP |
1274 | CommonArrayFieldClass<const bt_field_class> asConst() const noexcept |
1275 | { | |
1276 | return CommonArrayFieldClass<const bt_field_class> {*this}; | |
1277 | } | |
1278 | ||
dcb8ae9b | 1279 | _FieldClass elementFieldClass() const noexcept |
12435a68 PP |
1280 | { |
1281 | return _FieldClass { | |
341a67c4 | 1282 | internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())}; |
12435a68 PP |
1283 | } |
1284 | ||
1285 | Shared shared() const noexcept | |
1286 | { | |
c9c0b6e2 | 1287 | return Shared::createWithRef(*this); |
12435a68 PP |
1288 | } |
1289 | }; | |
1290 | ||
1291 | using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>; | |
1292 | using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>; | |
1293 | ||
4927bae7 PP |
1294 | namespace internal { |
1295 | ||
1296 | struct ArrayFieldClassTypeDescr | |
1297 | { | |
1298 | using Const = ConstArrayFieldClass; | |
1299 | using NonConst = ArrayFieldClass; | |
1300 | }; | |
1301 | ||
1302 | template <> | |
1303 | struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr | |
1304 | { | |
1305 | }; | |
1306 | ||
1307 | template <> | |
1308 | struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr | |
1309 | { | |
1310 | }; | |
1311 | ||
1312 | } /* namespace internal */ | |
1313 | ||
12435a68 PP |
1314 | template <typename LibObjT> |
1315 | class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1316 | { | |
1317 | private: | |
1318 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
12435a68 PP |
1319 | |
1320 | public: | |
d246c457 | 1321 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1322 | using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1323 | |
d246c457 | 1324 | explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1325 | _ThisCommonArrayFieldClass {libObjPtr} |
1326 | { | |
1327 | BT_ASSERT_DBG(this->isStaticArray()); | |
1328 | } | |
1329 | ||
1330 | template <typename OtherLibObjT> | |
100fa861 | 1331 | CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1332 | _ThisCommonArrayFieldClass {fc} |
1333 | { | |
1334 | } | |
1335 | ||
1336 | template <typename OtherLibObjT> | |
ac30a470 | 1337 | CommonStaticArrayFieldClass |
100fa861 | 1338 | operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1339 | { |
1340 | _ThisCommonArrayFieldClass::operator=(fc); | |
1341 | return *this; | |
1342 | } | |
1343 | ||
328a274a PP |
1344 | CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept |
1345 | { | |
1346 | return CommonStaticArrayFieldClass<const bt_field_class> {*this}; | |
1347 | } | |
1348 | ||
12435a68 PP |
1349 | std::uint64_t length() const noexcept |
1350 | { | |
341a67c4 | 1351 | return bt_field_class_array_static_get_length(this->libObjPtr()); |
12435a68 PP |
1352 | } |
1353 | ||
1354 | Shared shared() const noexcept | |
1355 | { | |
c9c0b6e2 | 1356 | return Shared::createWithRef(*this); |
12435a68 PP |
1357 | } |
1358 | }; | |
1359 | ||
1360 | using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>; | |
1361 | using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>; | |
1362 | ||
4927bae7 PP |
1363 | namespace internal { |
1364 | ||
1365 | struct StaticArrayFieldClassTypeDescr | |
1366 | { | |
1367 | using Const = ConstStaticArrayFieldClass; | |
1368 | using NonConst = StaticArrayFieldClass; | |
1369 | }; | |
1370 | ||
1371 | template <> | |
1372 | struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr | |
1373 | { | |
1374 | }; | |
1375 | ||
1376 | template <> | |
1377 | struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr | |
1378 | { | |
1379 | }; | |
1380 | ||
1381 | } /* namespace internal */ | |
1382 | ||
12435a68 PP |
1383 | template <typename LibObjT> |
1384 | class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1385 | { | |
1386 | private: | |
1387 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
12435a68 PP |
1388 | |
1389 | public: | |
d246c457 | 1390 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1391 | using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1392 | |
d246c457 | 1393 | explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1394 | _ThisCommonArrayFieldClass {libObjPtr} |
1395 | { | |
1396 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); | |
1397 | } | |
1398 | ||
1399 | template <typename OtherLibObjT> | |
1400 | CommonDynamicArrayWithLengthFieldClass( | |
100fa861 | 1401 | const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1402 | _ThisCommonArrayFieldClass {fc} |
1403 | { | |
1404 | } | |
1405 | ||
1406 | template <typename OtherLibObjT> | |
ac30a470 | 1407 | CommonDynamicArrayWithLengthFieldClass |
100fa861 | 1408 | operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1409 | { |
1410 | _ThisCommonArrayFieldClass::operator=(fc); | |
1411 | return *this; | |
1412 | } | |
1413 | ||
328a274a PP |
1414 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept |
1415 | { | |
1416 | return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this}; | |
1417 | } | |
1418 | ||
12435a68 PP |
1419 | ConstFieldPath lengthFieldPath() const noexcept |
1420 | { | |
1421 | return ConstFieldPath { | |
1422 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( | |
341a67c4 | 1423 | this->libObjPtr())}; |
12435a68 PP |
1424 | } |
1425 | ||
1426 | Shared shared() const noexcept | |
1427 | { | |
c9c0b6e2 | 1428 | return Shared::createWithRef(*this); |
12435a68 PP |
1429 | } |
1430 | }; | |
1431 | ||
1432 | using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>; | |
1433 | ||
1434 | using ConstDynamicArrayWithLengthFieldClass = | |
1435 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class>; | |
1436 | ||
1437 | namespace internal { | |
1438 | ||
4927bae7 PP |
1439 | struct DynamicArrayWithLengthFieldClassTypeDescr |
1440 | { | |
1441 | using Const = ConstDynamicArrayWithLengthFieldClass; | |
1442 | using NonConst = DynamicArrayWithLengthFieldClass; | |
1443 | }; | |
1444 | ||
1445 | template <> | |
1446 | struct TypeDescr<DynamicArrayWithLengthFieldClass> : | |
1447 | public DynamicArrayWithLengthFieldClassTypeDescr | |
1448 | { | |
1449 | }; | |
1450 | ||
1451 | template <> | |
1452 | struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> : | |
1453 | public DynamicArrayWithLengthFieldClassTypeDescr | |
1454 | { | |
1455 | }; | |
1456 | ||
12435a68 PP |
1457 | template <typename LibObjT> |
1458 | struct CommonOptionFieldClassSpec; | |
1459 | ||
b5f55e9f | 1460 | /* Functions specific to mutable option field classes */ |
12435a68 PP |
1461 | template <> |
1462 | struct CommonOptionFieldClassSpec<bt_field_class> final | |
1463 | { | |
1464 | static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept | |
1465 | { | |
1466 | return bt_field_class_option_borrow_field_class(libObjPtr); | |
1467 | } | |
1468 | }; | |
1469 | ||
b5f55e9f | 1470 | /* Functions specific to constant option field classes */ |
12435a68 PP |
1471 | template <> |
1472 | struct CommonOptionFieldClassSpec<const bt_field_class> final | |
1473 | { | |
1474 | static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept | |
1475 | { | |
1476 | return bt_field_class_option_borrow_field_class_const(libObjPtr); | |
1477 | } | |
1478 | }; | |
1479 | ||
b5f55e9f | 1480 | } /* namespace internal */ |
12435a68 PP |
1481 | |
1482 | template <typename LibObjT> | |
1483 | class CommonOptionFieldClass : public CommonFieldClass<LibObjT> | |
1484 | { | |
1485 | private: | |
1486 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
8047a175 | 1487 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1488 | |
1489 | protected: | |
12435a68 PP |
1490 | using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>; |
1491 | ||
1492 | public: | |
d246c457 | 1493 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1494 | using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1495 | |
d246c457 | 1496 | explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1497 | _ThisCommonFieldClass {libObjPtr} |
1498 | { | |
1499 | BT_ASSERT_DBG(this->isOption()); | |
1500 | } | |
1501 | ||
1502 | template <typename OtherLibObjT> | |
100fa861 | 1503 | CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1504 | _ThisCommonFieldClass {fc} |
1505 | { | |
1506 | } | |
1507 | ||
1508 | template <typename OtherLibObjT> | |
ac30a470 | 1509 | CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1510 | { |
1511 | _ThisCommonFieldClass::operator=(fc); | |
1512 | return *this; | |
1513 | } | |
1514 | ||
328a274a PP |
1515 | CommonOptionFieldClass<const bt_field_class> asConst() const noexcept |
1516 | { | |
1517 | return CommonOptionFieldClass<const bt_field_class> {*this}; | |
1518 | } | |
1519 | ||
dcb8ae9b | 1520 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1521 | { |
1522 | return _FieldClass { | |
341a67c4 | 1523 | internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 PP |
1524 | } |
1525 | ||
1526 | Shared shared() const noexcept | |
1527 | { | |
c9c0b6e2 | 1528 | return Shared::createWithRef(*this); |
12435a68 PP |
1529 | } |
1530 | }; | |
1531 | ||
1532 | using OptionFieldClass = CommonOptionFieldClass<bt_field_class>; | |
1533 | using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>; | |
1534 | ||
4927bae7 PP |
1535 | namespace internal { |
1536 | ||
1537 | struct OptionFieldClassTypeDescr | |
1538 | { | |
1539 | using Const = ConstOptionFieldClass; | |
1540 | using NonConst = OptionFieldClass; | |
1541 | }; | |
1542 | ||
1543 | template <> | |
1544 | struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr | |
1545 | { | |
1546 | }; | |
1547 | ||
1548 | template <> | |
1549 | struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr | |
1550 | { | |
1551 | }; | |
1552 | ||
1553 | } /* namespace internal */ | |
1554 | ||
12435a68 PP |
1555 | template <typename LibObjT> |
1556 | class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT> | |
1557 | { | |
1558 | private: | |
1559 | using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass; | |
1560 | ||
1561 | protected: | |
12435a68 PP |
1562 | using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>; |
1563 | ||
1564 | public: | |
d246c457 | 1565 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1566 | using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1567 | |
d246c457 | 1568 | explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1569 | _ThisCommonOptionFieldClass {libObjPtr} |
1570 | { | |
1571 | BT_ASSERT_DBG(this->isOptionWithSelector()); | |
1572 | } | |
1573 | ||
1574 | template <typename OtherLibObjT> | |
1575 | CommonOptionWithSelectorFieldClass( | |
100fa861 | 1576 | const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1577 | _ThisCommonOptionFieldClass {fc} |
1578 | { | |
1579 | } | |
1580 | ||
1581 | template <typename OtherLibObjT> | |
ac30a470 | 1582 | CommonOptionWithSelectorFieldClass |
100fa861 | 1583 | operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1584 | { |
1585 | _ThisCommonOptionFieldClass::operator=(fc); | |
1586 | return *this; | |
1587 | } | |
1588 | ||
328a274a PP |
1589 | CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
1590 | { | |
1591 | return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this}; | |
1592 | } | |
1593 | ||
12435a68 PP |
1594 | ConstFieldPath selectorFieldPath() const noexcept |
1595 | { | |
1596 | return ConstFieldPath { | |
1597 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( | |
341a67c4 | 1598 | this->libObjPtr())}; |
12435a68 PP |
1599 | } |
1600 | ||
1601 | Shared shared() const noexcept | |
1602 | { | |
c9c0b6e2 | 1603 | return Shared::createWithRef(*this); |
12435a68 PP |
1604 | } |
1605 | }; | |
1606 | ||
1607 | using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>; | |
1608 | using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>; | |
1609 | ||
4927bae7 PP |
1610 | namespace internal { |
1611 | ||
1612 | struct OptionWithSelectorFieldClassTypeDescr | |
1613 | { | |
1614 | using Const = ConstOptionWithSelectorFieldClass; | |
1615 | using NonConst = OptionWithSelectorFieldClass; | |
1616 | }; | |
1617 | ||
1618 | template <> | |
1619 | struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr | |
1620 | { | |
1621 | }; | |
1622 | ||
1623 | template <> | |
1624 | struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr | |
1625 | { | |
1626 | }; | |
1627 | ||
1628 | } /* namespace internal */ | |
1629 | ||
12435a68 PP |
1630 | template <typename LibObjT> |
1631 | class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1632 | { | |
1633 | private: | |
12435a68 PP |
1634 | using typename CommonOptionWithSelectorFieldClass< |
1635 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1636 | ||
1637 | public: | |
d246c457 | 1638 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1639 | using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1640 | |
d246c457 | 1641 | explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1642 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
1643 | { | |
1644 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); | |
1645 | } | |
1646 | ||
1647 | template <typename OtherLibObjT> | |
1648 | CommonOptionWithBoolSelectorFieldClass( | |
100fa861 | 1649 | const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1650 | _ThisCommonOptionWithSelectorFieldClass {fc} |
1651 | { | |
1652 | } | |
1653 | ||
1654 | template <typename OtherLibObjT> | |
ac30a470 | 1655 | CommonOptionWithBoolSelectorFieldClass |
100fa861 | 1656 | operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1657 | { |
1658 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1659 | return *this; | |
1660 | } | |
1661 | ||
328a274a PP |
1662 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept |
1663 | { | |
1664 | return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this}; | |
1665 | } | |
1666 | ||
12435a68 PP |
1667 | bool selectorIsReversed() const noexcept |
1668 | { | |
1669 | return bt_field_class_option_with_selector_field_bool_selector_is_reversed( | |
341a67c4 | 1670 | this->libObjPtr()); |
12435a68 PP |
1671 | } |
1672 | ||
1673 | Shared shared() const noexcept | |
1674 | { | |
c9c0b6e2 | 1675 | return Shared::createWithRef(*this); |
12435a68 PP |
1676 | } |
1677 | }; | |
1678 | ||
1679 | using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>; | |
1680 | ||
1681 | using ConstOptionWithBoolSelectorFieldClass = | |
1682 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class>; | |
1683 | ||
1684 | namespace internal { | |
1685 | ||
4927bae7 PP |
1686 | struct OptionWithBoolSelectorFieldClassTypeDescr |
1687 | { | |
1688 | using Const = ConstOptionWithBoolSelectorFieldClass; | |
1689 | using NonConst = OptionWithBoolSelectorFieldClass; | |
1690 | }; | |
1691 | ||
1692 | template <> | |
1693 | struct TypeDescr<OptionWithBoolSelectorFieldClass> : | |
1694 | public OptionWithBoolSelectorFieldClassTypeDescr | |
1695 | { | |
1696 | }; | |
1697 | ||
1698 | template <> | |
1699 | struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> : | |
1700 | public OptionWithBoolSelectorFieldClassTypeDescr | |
1701 | { | |
1702 | }; | |
1703 | ||
12435a68 PP |
1704 | template <typename RangeSetT> |
1705 | struct CommonOptionWithIntegerSelectorFieldClassSpec; | |
1706 | ||
b5f55e9f | 1707 | /* Functions specific to option field classes with unsigned integer ranges */ |
12435a68 PP |
1708 | template <> |
1709 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final | |
1710 | { | |
1711 | static const bt_integer_range_set_unsigned * | |
1712 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1713 | { | |
1714 | return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( | |
1715 | libObjPtr); | |
1716 | } | |
1717 | }; | |
1718 | ||
b5f55e9f | 1719 | /* Functions specific to option field classes with signed ranges */ |
12435a68 PP |
1720 | template <> |
1721 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final | |
1722 | { | |
1723 | static const bt_integer_range_set_signed * | |
1724 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1725 | { | |
1726 | return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( | |
1727 | libObjPtr); | |
1728 | } | |
1729 | }; | |
1730 | ||
b5f55e9f | 1731 | } /* namespace internal */ |
12435a68 PP |
1732 | |
1733 | template <typename LibObjT, typename RangeSetT> | |
1734 | class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1735 | { | |
1736 | private: | |
12435a68 PP |
1737 | using typename CommonOptionWithSelectorFieldClass< |
1738 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1739 | ||
12435a68 | 1740 | public: |
d246c457 | 1741 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
ac19444e | 1742 | using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>; |
12435a68 PP |
1743 | using RangeSet = RangeSetT; |
1744 | ||
d246c457 | 1745 | explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1746 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
1747 | { | |
1748 | BT_ASSERT_DBG(this->isOptionWithIntegerSelector()); | |
1749 | } | |
1750 | ||
1751 | template <typename OtherLibObjT> | |
1752 | CommonOptionWithIntegerSelectorFieldClass( | |
100fa861 | 1753 | const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept : |
12435a68 PP |
1754 | _ThisCommonOptionWithSelectorFieldClass {fc} |
1755 | { | |
1756 | } | |
1757 | ||
1758 | template <typename OtherLibObjT> | |
ac30a470 | 1759 | CommonOptionWithIntegerSelectorFieldClass |
100fa861 | 1760 | operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept |
12435a68 PP |
1761 | { |
1762 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1763 | return *this; | |
1764 | } | |
1765 | ||
1766 | RangeSet ranges() const noexcept | |
1767 | { | |
1768 | return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges( | |
341a67c4 | 1769 | this->libObjPtr())}; |
12435a68 PP |
1770 | } |
1771 | ||
1772 | Shared shared() const noexcept | |
1773 | { | |
c9c0b6e2 | 1774 | return Shared::createWithRef(*this); |
12435a68 PP |
1775 | } |
1776 | }; | |
1777 | ||
1778 | using OptionWithUnsignedIntegerSelectorFieldClass = | |
1779 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1780 | ||
1781 | using ConstOptionWithUnsignedIntegerSelectorFieldClass = | |
1782 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1783 | ||
1784 | using OptionWithSignedIntegerSelectorFieldClass = | |
1785 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>; | |
1786 | ||
1787 | using ConstOptionWithSignedIntegerSelectorFieldClass = | |
1788 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>; | |
1789 | ||
1790 | namespace internal { | |
1791 | ||
4927bae7 PP |
1792 | struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
1793 | { | |
1794 | using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass; | |
1795 | using NonConst = OptionWithUnsignedIntegerSelectorFieldClass; | |
1796 | }; | |
1797 | ||
1798 | template <> | |
1799 | struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> : | |
1800 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr | |
1801 | { | |
1802 | }; | |
1803 | ||
1804 | template <> | |
1805 | struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> : | |
1806 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr | |
1807 | { | |
1808 | }; | |
1809 | ||
1810 | struct OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1811 | { | |
1812 | using Const = ConstOptionWithSignedIntegerSelectorFieldClass; | |
1813 | using NonConst = OptionWithSignedIntegerSelectorFieldClass; | |
1814 | }; | |
1815 | ||
1816 | template <> | |
1817 | struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> : | |
1818 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1819 | { | |
1820 | }; | |
1821 | ||
1822 | template <> | |
1823 | struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> : | |
1824 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1825 | { | |
1826 | }; | |
1827 | ||
12435a68 PP |
1828 | template <typename LibObjT> |
1829 | struct CommonVariantFieldClassOptionSpec; | |
1830 | ||
b5f55e9f | 1831 | /* Functions specific to mutable variant field class options */ |
12435a68 PP |
1832 | template <> |
1833 | struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final | |
1834 | { | |
1835 | static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept | |
1836 | { | |
1837 | return bt_field_class_variant_option_borrow_field_class(libObjPtr); | |
1838 | } | |
8e557120 PP |
1839 | |
1840 | static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept | |
1841 | { | |
1842 | return bt_field_class_variant_option_borrow_user_attributes(libObjPtr); | |
1843 | } | |
12435a68 PP |
1844 | }; |
1845 | ||
b5f55e9f | 1846 | /* Functions specific to constant variant field class options */ |
12435a68 PP |
1847 | template <> |
1848 | struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final | |
1849 | { | |
1850 | static const bt_field_class * | |
1851 | fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept | |
1852 | { | |
1853 | return bt_field_class_variant_option_borrow_field_class_const(libObjPtr); | |
1854 | } | |
8e557120 PP |
1855 | |
1856 | static const bt_value * | |
1857 | userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept | |
1858 | { | |
1859 | return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr); | |
1860 | } | |
12435a68 PP |
1861 | }; |
1862 | ||
b5f55e9f | 1863 | } /* namespace internal */ |
12435a68 PP |
1864 | |
1865 | template <typename LibObjT> | |
0d218157 | 1866 | class CommonVariantFieldClassOption : public BorrowedObject<LibObjT> |
12435a68 PP |
1867 | { |
1868 | private: | |
0d218157 | 1869 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
8047a175 | 1870 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1871 | |
1872 | public: | |
d246c457 | 1873 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
8047a175 | 1874 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
8e557120 | 1875 | |
d246c457 | 1876 | explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 1877 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
1878 | { |
1879 | } | |
1880 | ||
1881 | template <typename OtherLibObjT> | |
100fa861 | 1882 | CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept : |
0d218157 | 1883 | _ThisBorrowedObject {fc} |
12435a68 PP |
1884 | { |
1885 | } | |
1886 | ||
1887 | template <typename OtherLibObjT> | |
ac30a470 | 1888 | CommonVariantFieldClassOption |
100fa861 | 1889 | operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept |
12435a68 | 1890 | { |
0d218157 | 1891 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
1892 | return *this; |
1893 | } | |
1894 | ||
328a274a PP |
1895 | CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept |
1896 | { | |
1897 | return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this}; | |
1898 | } | |
1899 | ||
e7f0f07b | 1900 | bt2c::CStringView name() const noexcept |
12435a68 | 1901 | { |
5cc5088c | 1902 | return bt_field_class_variant_option_get_name(this->libObjPtr()); |
12435a68 PP |
1903 | } |
1904 | ||
dcb8ae9b | 1905 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1906 | { |
1907 | return _FieldClass { | |
341a67c4 | 1908 | internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 | 1909 | } |
8e557120 PP |
1910 | |
1911 | template <typename LibValT> | |
2a24eba8 SM |
1912 | CommonVariantFieldClassOption |
1913 | userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept | |
8e557120 | 1914 | { |
5c895f64 PP |
1915 | static_assert(!std::is_const<LibObjT>::value, |
1916 | "Not available with `bt2::ConstVariantFieldClassOption`."); | |
8e557120 PP |
1917 | |
1918 | bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); | |
2a24eba8 | 1919 | return *this; |
8e557120 PP |
1920 | } |
1921 | ||
dcb8ae9b | 1922 | UserAttributes userAttributes() const noexcept |
8e557120 PP |
1923 | { |
1924 | return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes( | |
1925 | this->libObjPtr())}; | |
1926 | } | |
12435a68 PP |
1927 | }; |
1928 | ||
1929 | using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>; | |
1930 | ||
1931 | using ConstVariantFieldClassOption = | |
1932 | CommonVariantFieldClassOption<const bt_field_class_variant_option>; | |
1933 | ||
1934 | namespace internal { | |
1935 | ||
4927bae7 PP |
1936 | struct VariantFieldClassOptionTypeDescr |
1937 | { | |
1938 | using Const = ConstVariantFieldClassOption; | |
1939 | using NonConst = VariantFieldClassOption; | |
1940 | }; | |
1941 | ||
1942 | template <> | |
1943 | struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr | |
1944 | { | |
1945 | }; | |
1946 | ||
1947 | template <> | |
1948 | struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr | |
1949 | { | |
1950 | }; | |
1951 | ||
12435a68 PP |
1952 | template <typename LibObjT> |
1953 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; | |
1954 | ||
b5f55e9f | 1955 | /* Functions specific to variant field class options with unsigned integer selector */ |
12435a68 PP |
1956 | template <> |
1957 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1958 | const bt_field_class_variant_with_selector_field_integer_unsigned_option> | |
1959 | final | |
1960 | { | |
1961 | static const bt_integer_range_set_unsigned * | |
1962 | ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1963 | * const libObjPtr) noexcept | |
1964 | { | |
1965 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( | |
1966 | libObjPtr); | |
1967 | } | |
1968 | ||
1969 | static const bt_field_class_variant_option * | |
1970 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1971 | * const libObjPtr) noexcept | |
1972 | { | |
1973 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const( | |
1974 | libObjPtr); | |
1975 | } | |
1976 | }; | |
1977 | ||
b5f55e9f | 1978 | /* Functions specific to variant field class options with signed integer selector */ |
12435a68 PP |
1979 | template <> |
1980 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1981 | const bt_field_class_variant_with_selector_field_integer_signed_option> | |
1982 | final | |
1983 | { | |
1984 | static const bt_integer_range_set_signed * | |
1985 | ranges(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1986 | * const libObjPtr) noexcept | |
1987 | { | |
1988 | return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( | |
1989 | libObjPtr); | |
1990 | } | |
1991 | ||
1992 | static const bt_field_class_variant_option * | |
1993 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1994 | * const libObjPtr) noexcept | |
1995 | { | |
1996 | return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const( | |
1997 | libObjPtr); | |
1998 | } | |
1999 | }; | |
2000 | ||
b5f55e9f | 2001 | } /* namespace internal */ |
12435a68 PP |
2002 | |
2003 | template <typename LibObjT> | |
0d218157 | 2004 | class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT> |
12435a68 PP |
2005 | { |
2006 | private: | |
0d218157 | 2007 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
12435a68 PP |
2008 | using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>; |
2009 | ||
2010 | public: | |
d246c457 PP |
2011 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
2012 | ||
12435a68 PP |
2013 | using RangeSet = typename std::conditional< |
2014 | std::is_same< | |
2015 | LibObjT, | |
2016 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value, | |
2017 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; | |
2018 | ||
d246c457 | 2019 | explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 2020 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
2021 | { |
2022 | } | |
2023 | ||
2024 | template <typename OtherLibObjT> | |
2025 | ConstVariantWithIntegerSelectorFieldClassOption( | |
100fa861 | 2026 | const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept : |
0d218157 | 2027 | _ThisBorrowedObject {fc} |
12435a68 PP |
2028 | { |
2029 | } | |
2030 | ||
2031 | template <typename OtherLibObjT> | |
ac30a470 | 2032 | ConstVariantWithIntegerSelectorFieldClassOption |
100fa861 | 2033 | operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept |
12435a68 | 2034 | { |
0d218157 | 2035 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
2036 | return *this; |
2037 | } | |
2038 | ||
2039 | ConstVariantFieldClassOption asBaseOption() const noexcept | |
2040 | { | |
341a67c4 | 2041 | return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())}; |
12435a68 PP |
2042 | } |
2043 | ||
e7f0f07b | 2044 | bt2c::CStringView name() const noexcept |
12435a68 PP |
2045 | { |
2046 | return this->asBaseOption().name(); | |
2047 | } | |
2048 | ||
2049 | ConstFieldClass fieldClass() const noexcept | |
2050 | { | |
2051 | return this->asBaseOption().fieldClass(); | |
2052 | } | |
2053 | ||
2054 | RangeSet ranges() const noexcept | |
2055 | { | |
341a67c4 | 2056 | return RangeSet {_Spec::ranges(this->libObjPtr())}; |
12435a68 PP |
2057 | } |
2058 | }; | |
2059 | ||
2060 | using ConstVariantWithUnsignedIntegerSelectorFieldClassOption = | |
2061 | ConstVariantWithIntegerSelectorFieldClassOption< | |
2062 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>; | |
2063 | ||
2064 | using ConstVariantWithSignedIntegerSelectorFieldClassOption = | |
2065 | ConstVariantWithIntegerSelectorFieldClassOption< | |
2066 | const bt_field_class_variant_with_selector_field_integer_signed_option>; | |
2067 | ||
2068 | namespace internal { | |
2069 | ||
2070 | template <typename LibObjT> | |
2071 | struct CommonVariantFieldClassSpec; | |
2072 | ||
b5f55e9f | 2073 | /* Functions specific to mutable variant field classes */ |
12435a68 PP |
2074 | template <> |
2075 | struct CommonVariantFieldClassSpec<bt_field_class> final | |
2076 | { | |
2077 | static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr, | |
2078 | const std::uint64_t index) noexcept | |
2079 | { | |
2080 | return bt_field_class_variant_borrow_option_by_index(libObjPtr, index); | |
2081 | } | |
2082 | ||
2083 | static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr, | |
2084 | const char * const name) noexcept | |
2085 | { | |
2086 | return bt_field_class_variant_borrow_option_by_name(libObjPtr, name); | |
2087 | } | |
2088 | }; | |
2089 | ||
b5f55e9f | 2090 | /* Functions specific to constant variant field classes */ |
12435a68 PP |
2091 | template <> |
2092 | struct CommonVariantFieldClassSpec<const bt_field_class> final | |
2093 | { | |
2094 | static const bt_field_class_variant_option * | |
2095 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2096 | { | |
2097 | return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index); | |
2098 | } | |
2099 | ||
2100 | static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr, | |
2101 | const char * const name) noexcept | |
2102 | { | |
2103 | return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name); | |
2104 | } | |
2105 | }; | |
2106 | ||
b5f55e9f | 2107 | } /* namespace internal */ |
12435a68 PP |
2108 | |
2109 | template <typename LibObjT> | |
2110 | class CommonVariantFieldClass : public CommonFieldClass<LibObjT> | |
2111 | { | |
2112 | private: | |
2113 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
2114 | ||
2115 | protected: | |
12435a68 PP |
2116 | using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>; |
2117 | ||
2118 | public: | |
d246c457 | 2119 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2120 | using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>; |
56862ee2 | 2121 | using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>; |
12435a68 PP |
2122 | |
2123 | using Option = | |
8047a175 | 2124 | internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>; |
12435a68 | 2125 | |
d246c457 | 2126 | explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
2127 | _ThisCommonFieldClass {libObjPtr} |
2128 | { | |
2129 | BT_ASSERT_DBG(this->isVariant()); | |
2130 | } | |
2131 | ||
2132 | template <typename OtherLibObjT> | |
100fa861 | 2133 | CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
2134 | _ThisCommonFieldClass {fc} |
2135 | { | |
2136 | } | |
2137 | ||
2138 | template <typename OtherLibObjT> | |
ac30a470 | 2139 | CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
2140 | { |
2141 | _ThisCommonFieldClass::operator=(fc); | |
2142 | return *this; | |
2143 | } | |
2144 | ||
328a274a PP |
2145 | CommonVariantFieldClass<const bt_field_class> asConst() const noexcept |
2146 | { | |
2147 | return CommonVariantFieldClass<const bt_field_class> {*this}; | |
2148 | } | |
2149 | ||
c0b73c63 | 2150 | std::uint64_t length() const noexcept |
12435a68 | 2151 | { |
341a67c4 | 2152 | return bt_field_class_variant_get_option_count(this->libObjPtr()); |
12435a68 PP |
2153 | } |
2154 | ||
5046c776 FD |
2155 | Iterator begin() const noexcept |
2156 | { | |
2157 | return Iterator {*this, 0}; | |
2158 | } | |
2159 | ||
2160 | Iterator end() const noexcept | |
2161 | { | |
c0b73c63 | 2162 | return Iterator {*this, this->length()}; |
5046c776 FD |
2163 | } |
2164 | ||
dcb8ae9b | 2165 | Option operator[](const std::uint64_t index) const noexcept |
12435a68 PP |
2166 | { |
2167 | return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex( | |
341a67c4 | 2168 | this->libObjPtr(), index)}; |
12435a68 PP |
2169 | } |
2170 | ||
15030982 | 2171 | OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 2172 | { |
ca61ecbc PP |
2173 | return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), |
2174 | name); | |
12435a68 PP |
2175 | } |
2176 | ||
12435a68 PP |
2177 | Shared shared() const noexcept |
2178 | { | |
c9c0b6e2 | 2179 | return Shared::createWithRef(*this); |
12435a68 PP |
2180 | } |
2181 | }; | |
2182 | ||
2183 | using VariantFieldClass = CommonVariantFieldClass<bt_field_class>; | |
2184 | using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>; | |
2185 | ||
4927bae7 PP |
2186 | namespace internal { |
2187 | ||
2188 | struct VariantFieldClassTypeDescr | |
2189 | { | |
2190 | using Const = ConstVariantFieldClass; | |
2191 | using NonConst = VariantFieldClass; | |
2192 | }; | |
2193 | ||
2194 | template <> | |
2195 | struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr | |
2196 | { | |
2197 | }; | |
2198 | ||
2199 | template <> | |
2200 | struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr | |
2201 | { | |
2202 | }; | |
2203 | ||
2204 | } /* namespace internal */ | |
2205 | ||
12435a68 PP |
2206 | template <typename LibObjT> |
2207 | class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
2208 | { | |
2209 | private: | |
2210 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
12435a68 PP |
2211 | |
2212 | public: | |
d246c457 | 2213 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2214 | using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 2215 | |
d246c457 | 2216 | explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
2217 | _ThisCommonVariantFieldClass {libObjPtr} |
2218 | { | |
2219 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); | |
2220 | } | |
2221 | ||
2222 | template <typename OtherLibObjT> | |
2223 | CommonVariantWithoutSelectorFieldClass( | |
100fa861 | 2224 | const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
2225 | _ThisCommonVariantFieldClass {fc} |
2226 | { | |
2227 | } | |
2228 | ||
2229 | template <typename OtherLibObjT> | |
ac30a470 | 2230 | CommonVariantWithoutSelectorFieldClass |
100fa861 | 2231 | operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
2232 | { |
2233 | _ThisCommonVariantFieldClass::operator=(fc); | |
2234 | return *this; | |
2235 | } | |
2236 | ||
328a274a PP |
2237 | CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept |
2238 | { | |
2239 | return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this}; | |
2240 | } | |
2241 | ||
2a24eba8 SM |
2242 | CommonVariantWithoutSelectorFieldClass appendOption(const char * const name, |
2243 | const FieldClass fc) const | |
12435a68 | 2244 | { |
5c895f64 PP |
2245 | static_assert(!std::is_const<LibObjT>::value, |
2246 | "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`."); | |
12435a68 PP |
2247 | |
2248 | const auto status = bt_field_class_variant_without_selector_append_option( | |
341a67c4 | 2249 | this->libObjPtr(), name, fc.libObjPtr()); |
12435a68 PP |
2250 | |
2251 | if (status == | |
2252 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
39278ebc | 2253 | throw MemoryError {}; |
12435a68 | 2254 | } |
2a24eba8 SM |
2255 | |
2256 | return *this; | |
12435a68 PP |
2257 | } |
2258 | ||
2a24eba8 SM |
2259 | CommonVariantWithoutSelectorFieldClass appendOption(const bt2c::CStringView name, |
2260 | const FieldClass fc) const | |
15030982 SM |
2261 | { |
2262 | return this->appendOption(name.data(), fc); | |
2263 | } | |
2264 | ||
2a24eba8 SM |
2265 | CommonVariantWithoutSelectorFieldClass appendOption(const bt2s::optional<std::string>& name, |
2266 | const FieldClass fc) const | |
12435a68 | 2267 | { |
2a24eba8 | 2268 | return this->appendOption(name ? name->data() : nullptr, fc); |
12435a68 PP |
2269 | } |
2270 | ||
2271 | Shared shared() const noexcept | |
2272 | { | |
c9c0b6e2 | 2273 | return Shared::createWithRef(*this); |
12435a68 PP |
2274 | } |
2275 | }; | |
2276 | ||
2277 | using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>; | |
2278 | using ConstVariantWithoutSelectorFieldClass = | |
2279 | CommonVariantWithoutSelectorFieldClass<const bt_field_class>; | |
2280 | ||
2281 | namespace internal { | |
2282 | ||
4927bae7 PP |
2283 | struct VariantWithoutSelectorFieldClassTypeDescr |
2284 | { | |
2285 | using Const = ConstVariantWithoutSelectorFieldClass; | |
2286 | using NonConst = VariantWithoutSelectorFieldClass; | |
2287 | }; | |
2288 | ||
2289 | template <> | |
2290 | struct TypeDescr<VariantWithoutSelectorFieldClass> : | |
2291 | public VariantWithoutSelectorFieldClassTypeDescr | |
2292 | { | |
2293 | }; | |
2294 | ||
2295 | template <> | |
2296 | struct TypeDescr<ConstVariantWithoutSelectorFieldClass> : | |
2297 | public VariantWithoutSelectorFieldClassTypeDescr | |
2298 | { | |
2299 | }; | |
2300 | ||
12435a68 PP |
2301 | template <typename OptionT> |
2302 | struct CommonVariantWithIntegerSelectorFieldClassSpec; | |
2303 | ||
b5f55e9f | 2304 | /* Functions specific to variant field classes with unsigned integer selector */ |
12435a68 PP |
2305 | template <> |
2306 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
2307 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
2308 | final | |
2309 | { | |
2310 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
2311 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2312 | { | |
2313 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( | |
2314 | libObjPtr, index); | |
2315 | } | |
2316 | ||
2317 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
2318 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
2319 | { | |
2320 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( | |
2321 | libObjPtr, name); | |
2322 | } | |
2323 | ||
2324 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
2325 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
2326 | bt_field_class * const libOptFcPtr, | |
2327 | const bt_integer_range_set_unsigned * const libRangesPtr) | |
2328 | { | |
2329 | return bt_field_class_variant_with_selector_field_integer_unsigned_append_option( | |
2330 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
2331 | } | |
2332 | }; | |
2333 | ||
b5f55e9f | 2334 | /* Functions specific to variant field classes with signed integer selector */ |
12435a68 PP |
2335 | template <> |
2336 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
2337 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
2338 | final | |
2339 | { | |
2340 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
2341 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2342 | { | |
2343 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( | |
2344 | libObjPtr, index); | |
2345 | } | |
2346 | ||
2347 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
2348 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
2349 | { | |
2350 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( | |
2351 | libObjPtr, name); | |
2352 | } | |
2353 | ||
2354 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
2355 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
2356 | bt_field_class * const libOptFcPtr, | |
2357 | const bt_integer_range_set_signed * const libRangesPtr) | |
2358 | { | |
2359 | return bt_field_class_variant_with_selector_field_integer_signed_append_option( | |
2360 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
2361 | } | |
2362 | }; | |
2363 | ||
b5f55e9f | 2364 | } /* namespace internal */ |
12435a68 | 2365 | |
cefe03a2 FD |
2366 | template <typename LibObjT> |
2367 | class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
12435a68 PP |
2368 | { |
2369 | private: | |
2370 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
cefe03a2 FD |
2371 | |
2372 | protected: | |
cefe03a2 FD |
2373 | using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>; |
2374 | ||
2375 | public: | |
d246c457 | 2376 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2377 | using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>; |
cefe03a2 | 2378 | |
d246c457 | 2379 | explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
cefe03a2 FD |
2380 | _ThisCommonVariantFieldClass {libObjPtr} |
2381 | { | |
2382 | BT_ASSERT_DBG(this->isVariantWithSelector()); | |
2383 | } | |
2384 | ||
2385 | template <typename OtherLibObjT> | |
2386 | CommonVariantWithSelectorFieldClass( | |
100fa861 | 2387 | const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
cefe03a2 FD |
2388 | _ThisCommonVariantFieldClass {fc} |
2389 | { | |
2390 | } | |
2391 | ||
2392 | template <typename OtherLibObjT> | |
ac30a470 | 2393 | CommonVariantWithSelectorFieldClass |
100fa861 | 2394 | operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
cefe03a2 FD |
2395 | { |
2396 | _ThisCommonVariantFieldClass::operator=(fc); | |
2397 | return *this; | |
2398 | } | |
2399 | ||
328a274a PP |
2400 | CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
2401 | { | |
2402 | return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this}; | |
2403 | } | |
2404 | ||
cefe03a2 FD |
2405 | ConstFieldPath selectorFieldPath() const noexcept |
2406 | { | |
2407 | return ConstFieldPath { | |
2408 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( | |
341a67c4 | 2409 | this->libObjPtr())}; |
cefe03a2 FD |
2410 | } |
2411 | ||
2412 | Shared shared() const noexcept | |
2413 | { | |
c9c0b6e2 | 2414 | return Shared::createWithRef(*this); |
cefe03a2 FD |
2415 | } |
2416 | }; | |
12435a68 | 2417 | |
3c02a7cb FD |
2418 | using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>; |
2419 | using ConstVariantWithSelectorFieldClass = | |
2420 | CommonVariantWithSelectorFieldClass<const bt_field_class>; | |
2421 | ||
cefe03a2 FD |
2422 | template <typename LibObjT, typename OptionT> |
2423 | class CommonVariantWithIntegerSelectorFieldClass : | |
2424 | public CommonVariantWithSelectorFieldClass<LibObjT> | |
2425 | { | |
2426 | private: | |
2427 | using typename CommonVariantWithSelectorFieldClass< | |
2428 | LibObjT>::_ThisCommonVariantWithSelectorFieldClass; | |
12435a68 PP |
2429 | |
2430 | using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>; | |
2431 | ||
2432 | public: | |
d246c457 | 2433 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
ac19444e | 2434 | using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>; |
12435a68 | 2435 | using Option = OptionT; |
56862ee2 | 2436 | |
3c02a7cb | 2437 | using Iterator = |
56862ee2 | 2438 | BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>; |
12435a68 | 2439 | |
d246c457 | 2440 | explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
cefe03a2 | 2441 | _ThisCommonVariantWithSelectorFieldClass {libObjPtr} |
12435a68 | 2442 | { |
5ca48ae9 | 2443 | BT_ASSERT_DBG(this->isVariantWithIntegerSelector()); |
12435a68 PP |
2444 | } |
2445 | ||
2446 | template <typename OtherLibObjT> | |
2447 | CommonVariantWithIntegerSelectorFieldClass( | |
100fa861 | 2448 | const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept : |
cefe03a2 | 2449 | _ThisCommonVariantWithSelectorFieldClass {fc} |
12435a68 PP |
2450 | { |
2451 | } | |
2452 | ||
2453 | template <typename OtherLibObjT> | |
ac30a470 | 2454 | CommonVariantWithIntegerSelectorFieldClass |
100fa861 | 2455 | operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept |
12435a68 | 2456 | { |
cefe03a2 | 2457 | _ThisCommonVariantWithSelectorFieldClass::operator=(fc); |
12435a68 PP |
2458 | return *this; |
2459 | } | |
2460 | ||
12435a68 PP |
2461 | Option operator[](const std::uint64_t index) const noexcept |
2462 | { | |
341a67c4 | 2463 | return Option {_Spec::optionByIndex(this->libObjPtr(), index)}; |
12435a68 PP |
2464 | } |
2465 | ||
15030982 | 2466 | OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 2467 | { |
ca61ecbc | 2468 | return _Spec::optionByName(this->libObjPtr(), name); |
12435a68 PP |
2469 | } |
2470 | ||
2a24eba8 SM |
2471 | CommonVariantWithIntegerSelectorFieldClass |
2472 | appendOption(const char * const name, const FieldClass fc, | |
2473 | const typename Option::RangeSet ranges) const | |
12435a68 | 2474 | { |
5c895f64 PP |
2475 | static_assert( |
2476 | !std::is_const<LibObjT>::value, | |
2477 | "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`."); | |
12435a68 PP |
2478 | |
2479 | const auto status = | |
341a67c4 | 2480 | _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr()); |
12435a68 PP |
2481 | |
2482 | if (status == | |
2483 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
39278ebc | 2484 | throw MemoryError {}; |
12435a68 | 2485 | } |
2a24eba8 SM |
2486 | |
2487 | return *this; | |
12435a68 PP |
2488 | } |
2489 | ||
2a24eba8 SM |
2490 | CommonVariantWithIntegerSelectorFieldClass |
2491 | appendOption(const bt2c::CStringView name, const FieldClass fc, | |
2492 | const typename Option::RangeSet ranges) const | |
15030982 SM |
2493 | { |
2494 | return this->appendOption(name.data(), fc, ranges); | |
2495 | } | |
2496 | ||
2a24eba8 SM |
2497 | CommonVariantWithIntegerSelectorFieldClass |
2498 | appendOption(const bt2s::optional<std::string>& name, const FieldClass fc, | |
2499 | const typename Option::RangeSet ranges) const | |
12435a68 | 2500 | { |
2a24eba8 | 2501 | return this->appendOption(name ? name->data() : nullptr, fc, ranges); |
12435a68 PP |
2502 | } |
2503 | ||
3c02a7cb FD |
2504 | Iterator begin() const noexcept |
2505 | { | |
2506 | return Iterator {*this, 0}; | |
2507 | } | |
2508 | ||
2509 | Iterator end() const noexcept | |
2510 | { | |
c0b73c63 | 2511 | return Iterator {*this, this->length()}; |
3c02a7cb FD |
2512 | } |
2513 | ||
12435a68 PP |
2514 | Shared shared() const noexcept |
2515 | { | |
c9c0b6e2 | 2516 | return Shared::createWithRef(*this); |
12435a68 PP |
2517 | } |
2518 | }; | |
2519 | ||
2520 | using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2521 | bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2522 | ||
2523 | using ConstVariantWithUnsignedIntegerSelectorFieldClass = | |
2524 | CommonVariantWithIntegerSelectorFieldClass< | |
2525 | const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2526 | ||
2527 | using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2528 | bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2529 | ||
2530 | using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2531 | const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2532 | ||
4927bae7 PP |
2533 | namespace internal { |
2534 | ||
2535 | struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2536 | { | |
2537 | using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass; | |
2538 | using NonConst = VariantWithUnsignedIntegerSelectorFieldClass; | |
2539 | }; | |
2540 | ||
2541 | template <> | |
2542 | struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> : | |
2543 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2544 | { | |
2545 | }; | |
2546 | ||
2547 | template <> | |
2548 | struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> : | |
2549 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2550 | { | |
2551 | }; | |
2552 | ||
2553 | struct VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2554 | { | |
2555 | using Const = ConstVariantWithSignedIntegerSelectorFieldClass; | |
2556 | using NonConst = VariantWithSignedIntegerSelectorFieldClass; | |
2557 | }; | |
2558 | ||
2559 | template <> | |
2560 | struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> : | |
2561 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2562 | { | |
2563 | }; | |
2564 | ||
2565 | template <> | |
2566 | struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> : | |
2567 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2568 | { | |
2569 | }; | |
2570 | ||
2571 | } /* namespace internal */ | |
2572 | ||
12435a68 PP |
2573 | template <typename LibObjT> |
2574 | CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept | |
2575 | { | |
341a67c4 | 2576 | return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2577 | } |
2578 | ||
2579 | template <typename LibObjT> | |
2580 | CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept | |
2581 | { | |
341a67c4 | 2582 | return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2583 | } |
2584 | ||
be6aa636 FD |
2585 | template <typename LibObjT> |
2586 | CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept | |
2587 | { | |
341a67c4 | 2588 | return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()}; |
be6aa636 FD |
2589 | } |
2590 | ||
12435a68 PP |
2591 | template <typename LibObjT> |
2592 | CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> | |
2593 | CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept | |
2594 | { | |
2595 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); | |
2596 | return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> { | |
341a67c4 | 2597 | this->libObjPtr()}; |
12435a68 PP |
2598 | } |
2599 | ||
2600 | template <typename LibObjT> | |
2601 | CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> | |
2602 | CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept | |
2603 | { | |
2604 | BT_ASSERT_DBG(this->isSignedEnumeration()); | |
2605 | return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> { | |
341a67c4 | 2606 | this->libObjPtr()}; |
12435a68 PP |
2607 | } |
2608 | ||
2609 | template <typename LibObjT> | |
2610 | CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept | |
2611 | { | |
341a67c4 | 2612 | return CommonStructureFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2613 | } |
2614 | ||
2615 | template <typename LibObjT> | |
2616 | CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept | |
2617 | { | |
341a67c4 | 2618 | return CommonArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2619 | } |
2620 | ||
2621 | template <typename LibObjT> | |
2622 | CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept | |
2623 | { | |
341a67c4 | 2624 | return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2625 | } |
2626 | ||
2627 | template <typename LibObjT> | |
2628 | CommonDynamicArrayWithLengthFieldClass<LibObjT> | |
2629 | CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept | |
2630 | { | |
341a67c4 | 2631 | return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2632 | } |
2633 | ||
2634 | template <typename LibObjT> | |
2635 | CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept | |
2636 | { | |
341a67c4 | 2637 | return CommonOptionFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2638 | } |
2639 | ||
2640 | template <typename LibObjT> | |
2641 | CommonOptionWithSelectorFieldClass<LibObjT> | |
2642 | CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept | |
2643 | { | |
341a67c4 | 2644 | return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2645 | } |
2646 | ||
2647 | template <typename LibObjT> | |
2648 | CommonOptionWithBoolSelectorFieldClass<LibObjT> | |
2649 | CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept | |
2650 | { | |
341a67c4 | 2651 | return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2652 | } |
2653 | ||
2654 | template <typename LibObjT> | |
2655 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> | |
2656 | CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept | |
2657 | { | |
2658 | BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector()); | |
2659 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> { | |
341a67c4 | 2660 | this->libObjPtr()}; |
12435a68 PP |
2661 | } |
2662 | ||
2663 | template <typename LibObjT> | |
2664 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> | |
2665 | CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept | |
2666 | { | |
2667 | BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector()); | |
2668 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> { | |
341a67c4 | 2669 | this->libObjPtr()}; |
12435a68 PP |
2670 | } |
2671 | ||
2672 | template <typename LibObjT> | |
2673 | CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept | |
2674 | { | |
341a67c4 | 2675 | return CommonVariantFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2676 | } |
2677 | ||
2678 | template <typename LibObjT> | |
2679 | CommonVariantWithoutSelectorFieldClass<LibObjT> | |
2680 | CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept | |
2681 | { | |
341a67c4 | 2682 | return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2683 | } |
2684 | ||
2685 | template <typename LibObjT> | |
cefe03a2 FD |
2686 | CommonVariantWithSelectorFieldClass<LibObjT> |
2687 | CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept | |
2688 | { | |
341a67c4 | 2689 | return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
cefe03a2 FD |
2690 | } |
2691 | ||
2692 | template <typename LibObjT> | |
12435a68 PP |
2693 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
2694 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
2695 | CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept | |
2696 | { | |
2697 | BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector()); | |
2698 | return CommonVariantWithIntegerSelectorFieldClass< | |
341a67c4 | 2699 | LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
12435a68 PP |
2700 | } |
2701 | ||
2702 | template <typename LibObjT> | |
2703 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, | |
2704 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
2705 | CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept | |
2706 | { | |
2707 | BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector()); | |
2708 | return CommonVariantWithIntegerSelectorFieldClass< | |
341a67c4 | 2709 | LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
12435a68 PP |
2710 | } |
2711 | ||
b5f55e9f | 2712 | } /* namespace bt2 */ |
12435a68 | 2713 | |
b5f55e9f | 2714 | #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */ |