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