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