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