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