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