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 PP |
866 | { |
867 | const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping( | |
868 | this->libObjPtr(), label, ranges.libObjPtr()); | |
869 | ||
870 | if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) { | |
39278ebc | 871 | throw MemoryError {}; |
5d6ccdae | 872 | } |
2a24eba8 SM |
873 | |
874 | return *this; | |
5d6ccdae PP |
875 | } |
876 | ||
e5a8a7c4 FD |
877 | Iterator begin() const noexcept |
878 | { | |
879 | return Iterator {*this, 0}; | |
880 | } | |
881 | ||
882 | Iterator end() const noexcept | |
883 | { | |
c0b73c63 | 884 | return Iterator {*this, this->length()}; |
e5a8a7c4 FD |
885 | } |
886 | ||
12435a68 PP |
887 | Shared shared() const noexcept |
888 | { | |
c9c0b6e2 | 889 | return Shared::createWithRef(*this); |
12435a68 PP |
890 | } |
891 | }; | |
892 | ||
be6aa636 FD |
893 | using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>; |
894 | using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>; | |
895 | ||
12435a68 PP |
896 | using UnsignedEnumerationFieldClass = |
897 | CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
898 | ||
899 | using ConstUnsignedEnumerationFieldClass = | |
900 | CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
901 | ||
902 | using SignedEnumerationFieldClass = | |
903 | CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
904 | ||
905 | using ConstSignedEnumerationFieldClass = | |
906 | CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
907 | ||
908 | namespace internal { | |
909 | ||
4927bae7 PP |
910 | struct UnsignedEnumerationFieldClassTypeDescr |
911 | { | |
912 | using Const = ConstUnsignedEnumerationFieldClass; | |
913 | using NonConst = UnsignedEnumerationFieldClass; | |
914 | }; | |
915 | ||
916 | template <> | |
917 | struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr | |
918 | { | |
919 | }; | |
920 | ||
921 | template <> | |
922 | struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr | |
923 | { | |
924 | }; | |
925 | ||
926 | struct SignedEnumerationFieldClassTypeDescr | |
927 | { | |
928 | using Const = ConstSignedEnumerationFieldClass; | |
929 | using NonConst = SignedEnumerationFieldClass; | |
930 | }; | |
931 | ||
932 | template <> | |
933 | struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr | |
934 | { | |
935 | }; | |
936 | ||
937 | template <> | |
938 | struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr | |
939 | { | |
940 | }; | |
941 | ||
12435a68 PP |
942 | template <typename LibObjT> |
943 | struct CommonStructureFieldClassMemberSpec; | |
944 | ||
b5f55e9f | 945 | /* Functions specific to mutable structure field class members */ |
12435a68 PP |
946 | template <> |
947 | struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final | |
948 | { | |
949 | static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept | |
950 | { | |
951 | return bt_field_class_structure_member_borrow_field_class(libObjPtr); | |
952 | } | |
8e557120 PP |
953 | |
954 | static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept | |
955 | { | |
956 | return bt_field_class_structure_member_borrow_user_attributes(libObjPtr); | |
957 | } | |
12435a68 PP |
958 | }; |
959 | ||
b5f55e9f | 960 | /* Functions specific to constant structure field class members */ |
12435a68 PP |
961 | template <> |
962 | struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final | |
963 | { | |
964 | static const bt_field_class * | |
965 | fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept | |
966 | { | |
967 | return bt_field_class_structure_member_borrow_field_class_const(libObjPtr); | |
968 | } | |
8e557120 PP |
969 | |
970 | static const bt_value * | |
971 | userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept | |
972 | { | |
973 | return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr); | |
974 | } | |
12435a68 PP |
975 | }; |
976 | ||
b5f55e9f | 977 | } /* namespace internal */ |
12435a68 PP |
978 | |
979 | template <typename LibObjT> | |
0d218157 | 980 | class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT> |
12435a68 PP |
981 | { |
982 | private: | |
0d218157 | 983 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
8047a175 | 984 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
985 | |
986 | public: | |
d246c457 | 987 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
8047a175 | 988 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
8e557120 | 989 | |
d246c457 | 990 | explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 991 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
992 | { |
993 | } | |
994 | ||
995 | template <typename OtherLibObjT> | |
100fa861 PP |
996 | CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
997 | : | |
0d218157 | 998 | _ThisBorrowedObject {fc} |
12435a68 PP |
999 | { |
1000 | } | |
1001 | ||
1002 | template <typename OtherLibObjT> | |
ac30a470 | 1003 | CommonStructureFieldClassMember<LibObjT> |
100fa861 | 1004 | operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
12435a68 | 1005 | { |
0d218157 | 1006 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
1007 | return *this; |
1008 | } | |
1009 | ||
328a274a PP |
1010 | CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept |
1011 | { | |
1012 | return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this}; | |
1013 | } | |
1014 | ||
e7f0f07b | 1015 | bt2c::CStringView name() const noexcept |
12435a68 | 1016 | { |
341a67c4 | 1017 | return bt_field_class_structure_member_get_name(this->libObjPtr()); |
12435a68 PP |
1018 | } |
1019 | ||
dcb8ae9b | 1020 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1021 | { |
1022 | return _FieldClass { | |
341a67c4 | 1023 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 | 1024 | } |
8e557120 PP |
1025 | |
1026 | template <typename LibValT> | |
2a24eba8 SM |
1027 | CommonStructureFieldClassMember |
1028 | userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept | |
8e557120 | 1029 | { |
5c895f64 PP |
1030 | static_assert(!std::is_const<LibObjT>::value, |
1031 | "Not available with `bt2::ConstStructureFieldClassMember`."); | |
8e557120 PP |
1032 | |
1033 | bt_field_class_structure_member_set_user_attributes(this->libObjPtr(), | |
1034 | userAttrs.libObjPtr()); | |
2a24eba8 | 1035 | return *this; |
8e557120 PP |
1036 | } |
1037 | ||
dcb8ae9b | 1038 | UserAttributes userAttributes() const noexcept |
8e557120 PP |
1039 | { |
1040 | return UserAttributes { | |
1041 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes( | |
1042 | this->libObjPtr())}; | |
1043 | } | |
12435a68 PP |
1044 | }; |
1045 | ||
1046 | using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>; | |
1047 | ||
1048 | using ConstStructureFieldClassMember = | |
1049 | CommonStructureFieldClassMember<const bt_field_class_structure_member>; | |
1050 | ||
1051 | namespace internal { | |
1052 | ||
4927bae7 PP |
1053 | struct StructureFieldClassMemberTypeDescr |
1054 | { | |
1055 | using Const = ConstStructureFieldClassMember; | |
1056 | using NonConst = StructureFieldClassMember; | |
1057 | }; | |
1058 | ||
1059 | template <> | |
1060 | struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr | |
1061 | { | |
1062 | }; | |
1063 | ||
1064 | template <> | |
1065 | struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr | |
1066 | { | |
1067 | }; | |
1068 | ||
12435a68 PP |
1069 | template <typename LibObjT> |
1070 | struct CommonStructureFieldClassSpec; | |
1071 | ||
b5f55e9f | 1072 | /* Functions specific to mutable structure field classes */ |
12435a68 PP |
1073 | template <> |
1074 | struct CommonStructureFieldClassSpec<bt_field_class> final | |
1075 | { | |
1076 | static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr, | |
1077 | const std::uint64_t index) noexcept | |
1078 | { | |
1079 | return bt_field_class_structure_borrow_member_by_index(libObjPtr, index); | |
1080 | } | |
1081 | ||
1082 | static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr, | |
1083 | const char * const name) noexcept | |
1084 | { | |
1085 | return bt_field_class_structure_borrow_member_by_name(libObjPtr, name); | |
1086 | } | |
1087 | }; | |
1088 | ||
b5f55e9f | 1089 | /* Functions specific to constant structure field classes */ |
12435a68 PP |
1090 | template <> |
1091 | struct CommonStructureFieldClassSpec<const bt_field_class> final | |
1092 | { | |
1093 | static const bt_field_class_structure_member * | |
1094 | memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
1095 | { | |
1096 | return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index); | |
1097 | } | |
1098 | ||
1099 | static const bt_field_class_structure_member * | |
1100 | memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
1101 | { | |
1102 | return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name); | |
1103 | } | |
1104 | }; | |
1105 | ||
b5f55e9f | 1106 | } /* namespace internal */ |
12435a68 PP |
1107 | |
1108 | template <typename LibObjT> | |
1109 | class CommonStructureFieldClass final : public CommonFieldClass<LibObjT> | |
1110 | { | |
1111 | private: | |
12435a68 PP |
1112 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
1113 | ||
1114 | public: | |
d246c457 | 1115 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1116 | using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>; |
56862ee2 | 1117 | using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>; |
8047a175 | 1118 | |
12435a68 | 1119 | using Member = |
8047a175 | 1120 | internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>; |
12435a68 | 1121 | |
d246c457 | 1122 | explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1123 | _ThisCommonFieldClass {libObjPtr} |
1124 | { | |
1125 | BT_ASSERT_DBG(this->isStructure()); | |
1126 | } | |
1127 | ||
1128 | template <typename OtherLibObjT> | |
100fa861 | 1129 | CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1130 | _ThisCommonFieldClass {fc} |
1131 | { | |
1132 | } | |
1133 | ||
1134 | template <typename OtherLibObjT> | |
ac30a470 | 1135 | CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1136 | { |
1137 | _ThisCommonFieldClass::operator=(fc); | |
1138 | return *this; | |
1139 | } | |
1140 | ||
328a274a PP |
1141 | CommonStructureFieldClass<const bt_field_class> asConst() const noexcept |
1142 | { | |
1143 | return CommonStructureFieldClass<const bt_field_class> {*this}; | |
1144 | } | |
1145 | ||
2a24eba8 | 1146 | CommonStructureFieldClass appendMember(const bt2c::CStringView name, const FieldClass fc) const |
12435a68 | 1147 | { |
5c895f64 PP |
1148 | static_assert(!std::is_const<LibObjT>::value, |
1149 | "Not available with `bt2::ConstStructureFieldClass`."); | |
12435a68 PP |
1150 | |
1151 | const auto status = | |
341a67c4 | 1152 | bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr()); |
12435a68 PP |
1153 | |
1154 | if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { | |
39278ebc | 1155 | throw MemoryError {}; |
12435a68 | 1156 | } |
2a24eba8 SM |
1157 | |
1158 | return *this; | |
12435a68 PP |
1159 | } |
1160 | ||
c0b73c63 | 1161 | std::uint64_t length() const noexcept |
12435a68 | 1162 | { |
341a67c4 | 1163 | return bt_field_class_structure_get_member_count(this->libObjPtr()); |
12435a68 PP |
1164 | } |
1165 | ||
5046c776 FD |
1166 | Iterator begin() const noexcept |
1167 | { | |
1168 | return Iterator {*this, 0}; | |
1169 | } | |
1170 | ||
1171 | Iterator end() const noexcept | |
1172 | { | |
c0b73c63 | 1173 | return Iterator {*this, this->length()}; |
5046c776 FD |
1174 | } |
1175 | ||
dcb8ae9b | 1176 | Member operator[](const std::uint64_t index) const noexcept |
12435a68 PP |
1177 | { |
1178 | return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex( | |
341a67c4 | 1179 | this->libObjPtr(), index)}; |
12435a68 PP |
1180 | } |
1181 | ||
15030982 | 1182 | OptionalBorrowedObject<Member> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 1183 | { |
ca61ecbc PP |
1184 | return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), |
1185 | name); | |
12435a68 PP |
1186 | } |
1187 | ||
12435a68 PP |
1188 | Shared shared() const noexcept |
1189 | { | |
c9c0b6e2 | 1190 | return Shared::createWithRef(*this); |
12435a68 PP |
1191 | } |
1192 | }; | |
1193 | ||
1194 | using StructureFieldClass = CommonStructureFieldClass<bt_field_class>; | |
1195 | using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>; | |
1196 | ||
1197 | namespace internal { | |
1198 | ||
4927bae7 PP |
1199 | struct StructureFieldClassTypeDescr |
1200 | { | |
1201 | using Const = ConstStructureFieldClass; | |
1202 | using NonConst = StructureFieldClass; | |
1203 | }; | |
1204 | ||
1205 | template <> | |
1206 | struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr | |
1207 | { | |
1208 | }; | |
1209 | ||
1210 | template <> | |
1211 | struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr | |
1212 | { | |
1213 | }; | |
1214 | ||
12435a68 PP |
1215 | template <typename LibObjT> |
1216 | struct CommonArrayFieldClassSpec; | |
1217 | ||
b5f55e9f | 1218 | /* Functions specific to mutable array field classes */ |
12435a68 PP |
1219 | template <> |
1220 | struct CommonArrayFieldClassSpec<bt_field_class> final | |
1221 | { | |
1222 | static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept | |
1223 | { | |
1224 | return bt_field_class_array_borrow_element_field_class(libObjPtr); | |
1225 | } | |
1226 | }; | |
1227 | ||
b5f55e9f | 1228 | /* Functions specific to constant array field classes */ |
12435a68 PP |
1229 | template <> |
1230 | struct CommonArrayFieldClassSpec<const bt_field_class> final | |
1231 | { | |
1232 | static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept | |
1233 | { | |
1234 | return bt_field_class_array_borrow_element_field_class_const(libObjPtr); | |
1235 | } | |
1236 | }; | |
1237 | ||
b5f55e9f | 1238 | } /* namespace internal */ |
12435a68 PP |
1239 | |
1240 | template <typename LibObjT> | |
1241 | class CommonArrayFieldClass : public CommonFieldClass<LibObjT> | |
1242 | { | |
1243 | private: | |
1244 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
8047a175 | 1245 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1246 | |
1247 | protected: | |
12435a68 PP |
1248 | using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>; |
1249 | ||
1250 | public: | |
d246c457 | 1251 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1252 | using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1253 | |
d246c457 | 1254 | explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1255 | _ThisCommonFieldClass {libObjPtr} |
1256 | { | |
1257 | BT_ASSERT_DBG(this->isArray()); | |
1258 | } | |
1259 | ||
1260 | template <typename OtherLibObjT> | |
100fa861 | 1261 | CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1262 | _ThisCommonFieldClass {fc} |
1263 | { | |
1264 | } | |
1265 | ||
1266 | template <typename OtherLibObjT> | |
ac30a470 | 1267 | CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1268 | { |
1269 | _ThisCommonFieldClass::operator=(fc); | |
1270 | return *this; | |
1271 | } | |
1272 | ||
328a274a PP |
1273 | CommonArrayFieldClass<const bt_field_class> asConst() const noexcept |
1274 | { | |
1275 | return CommonArrayFieldClass<const bt_field_class> {*this}; | |
1276 | } | |
1277 | ||
dcb8ae9b | 1278 | _FieldClass elementFieldClass() const noexcept |
12435a68 PP |
1279 | { |
1280 | return _FieldClass { | |
341a67c4 | 1281 | internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())}; |
12435a68 PP |
1282 | } |
1283 | ||
1284 | Shared shared() const noexcept | |
1285 | { | |
c9c0b6e2 | 1286 | return Shared::createWithRef(*this); |
12435a68 PP |
1287 | } |
1288 | }; | |
1289 | ||
1290 | using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>; | |
1291 | using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>; | |
1292 | ||
4927bae7 PP |
1293 | namespace internal { |
1294 | ||
1295 | struct ArrayFieldClassTypeDescr | |
1296 | { | |
1297 | using Const = ConstArrayFieldClass; | |
1298 | using NonConst = ArrayFieldClass; | |
1299 | }; | |
1300 | ||
1301 | template <> | |
1302 | struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr | |
1303 | { | |
1304 | }; | |
1305 | ||
1306 | template <> | |
1307 | struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr | |
1308 | { | |
1309 | }; | |
1310 | ||
1311 | } /* namespace internal */ | |
1312 | ||
12435a68 PP |
1313 | template <typename LibObjT> |
1314 | class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1315 | { | |
1316 | private: | |
1317 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
12435a68 PP |
1318 | |
1319 | public: | |
d246c457 | 1320 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1321 | using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1322 | |
d246c457 | 1323 | explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1324 | _ThisCommonArrayFieldClass {libObjPtr} |
1325 | { | |
1326 | BT_ASSERT_DBG(this->isStaticArray()); | |
1327 | } | |
1328 | ||
1329 | template <typename OtherLibObjT> | |
100fa861 | 1330 | CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1331 | _ThisCommonArrayFieldClass {fc} |
1332 | { | |
1333 | } | |
1334 | ||
1335 | template <typename OtherLibObjT> | |
ac30a470 | 1336 | CommonStaticArrayFieldClass |
100fa861 | 1337 | operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1338 | { |
1339 | _ThisCommonArrayFieldClass::operator=(fc); | |
1340 | return *this; | |
1341 | } | |
1342 | ||
328a274a PP |
1343 | CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept |
1344 | { | |
1345 | return CommonStaticArrayFieldClass<const bt_field_class> {*this}; | |
1346 | } | |
1347 | ||
12435a68 PP |
1348 | std::uint64_t length() const noexcept |
1349 | { | |
341a67c4 | 1350 | return bt_field_class_array_static_get_length(this->libObjPtr()); |
12435a68 PP |
1351 | } |
1352 | ||
1353 | Shared shared() const noexcept | |
1354 | { | |
c9c0b6e2 | 1355 | return Shared::createWithRef(*this); |
12435a68 PP |
1356 | } |
1357 | }; | |
1358 | ||
1359 | using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>; | |
1360 | using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>; | |
1361 | ||
4927bae7 PP |
1362 | namespace internal { |
1363 | ||
1364 | struct StaticArrayFieldClassTypeDescr | |
1365 | { | |
1366 | using Const = ConstStaticArrayFieldClass; | |
1367 | using NonConst = StaticArrayFieldClass; | |
1368 | }; | |
1369 | ||
1370 | template <> | |
1371 | struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr | |
1372 | { | |
1373 | }; | |
1374 | ||
1375 | template <> | |
1376 | struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr | |
1377 | { | |
1378 | }; | |
1379 | ||
1380 | } /* namespace internal */ | |
1381 | ||
12435a68 PP |
1382 | template <typename LibObjT> |
1383 | class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1384 | { | |
1385 | private: | |
1386 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
12435a68 PP |
1387 | |
1388 | public: | |
d246c457 | 1389 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1390 | using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1391 | |
d246c457 | 1392 | explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1393 | _ThisCommonArrayFieldClass {libObjPtr} |
1394 | { | |
1395 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); | |
1396 | } | |
1397 | ||
1398 | template <typename OtherLibObjT> | |
1399 | CommonDynamicArrayWithLengthFieldClass( | |
100fa861 | 1400 | const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1401 | _ThisCommonArrayFieldClass {fc} |
1402 | { | |
1403 | } | |
1404 | ||
1405 | template <typename OtherLibObjT> | |
ac30a470 | 1406 | CommonDynamicArrayWithLengthFieldClass |
100fa861 | 1407 | operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1408 | { |
1409 | _ThisCommonArrayFieldClass::operator=(fc); | |
1410 | return *this; | |
1411 | } | |
1412 | ||
328a274a PP |
1413 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept |
1414 | { | |
1415 | return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this}; | |
1416 | } | |
1417 | ||
12435a68 PP |
1418 | ConstFieldPath lengthFieldPath() const noexcept |
1419 | { | |
1420 | return ConstFieldPath { | |
1421 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( | |
341a67c4 | 1422 | this->libObjPtr())}; |
12435a68 PP |
1423 | } |
1424 | ||
1425 | Shared shared() const noexcept | |
1426 | { | |
c9c0b6e2 | 1427 | return Shared::createWithRef(*this); |
12435a68 PP |
1428 | } |
1429 | }; | |
1430 | ||
1431 | using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>; | |
1432 | ||
1433 | using ConstDynamicArrayWithLengthFieldClass = | |
1434 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class>; | |
1435 | ||
1436 | namespace internal { | |
1437 | ||
4927bae7 PP |
1438 | struct DynamicArrayWithLengthFieldClassTypeDescr |
1439 | { | |
1440 | using Const = ConstDynamicArrayWithLengthFieldClass; | |
1441 | using NonConst = DynamicArrayWithLengthFieldClass; | |
1442 | }; | |
1443 | ||
1444 | template <> | |
1445 | struct TypeDescr<DynamicArrayWithLengthFieldClass> : | |
1446 | public DynamicArrayWithLengthFieldClassTypeDescr | |
1447 | { | |
1448 | }; | |
1449 | ||
1450 | template <> | |
1451 | struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> : | |
1452 | public DynamicArrayWithLengthFieldClassTypeDescr | |
1453 | { | |
1454 | }; | |
1455 | ||
12435a68 PP |
1456 | template <typename LibObjT> |
1457 | struct CommonOptionFieldClassSpec; | |
1458 | ||
b5f55e9f | 1459 | /* Functions specific to mutable option field classes */ |
12435a68 PP |
1460 | template <> |
1461 | struct CommonOptionFieldClassSpec<bt_field_class> final | |
1462 | { | |
1463 | static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept | |
1464 | { | |
1465 | return bt_field_class_option_borrow_field_class(libObjPtr); | |
1466 | } | |
1467 | }; | |
1468 | ||
b5f55e9f | 1469 | /* Functions specific to constant option field classes */ |
12435a68 PP |
1470 | template <> |
1471 | struct CommonOptionFieldClassSpec<const bt_field_class> final | |
1472 | { | |
1473 | static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept | |
1474 | { | |
1475 | return bt_field_class_option_borrow_field_class_const(libObjPtr); | |
1476 | } | |
1477 | }; | |
1478 | ||
b5f55e9f | 1479 | } /* namespace internal */ |
12435a68 PP |
1480 | |
1481 | template <typename LibObjT> | |
1482 | class CommonOptionFieldClass : public CommonFieldClass<LibObjT> | |
1483 | { | |
1484 | private: | |
1485 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
8047a175 | 1486 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1487 | |
1488 | protected: | |
12435a68 PP |
1489 | using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>; |
1490 | ||
1491 | public: | |
d246c457 | 1492 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1493 | using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1494 | |
d246c457 | 1495 | explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1496 | _ThisCommonFieldClass {libObjPtr} |
1497 | { | |
1498 | BT_ASSERT_DBG(this->isOption()); | |
1499 | } | |
1500 | ||
1501 | template <typename OtherLibObjT> | |
100fa861 | 1502 | CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1503 | _ThisCommonFieldClass {fc} |
1504 | { | |
1505 | } | |
1506 | ||
1507 | template <typename OtherLibObjT> | |
ac30a470 | 1508 | CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1509 | { |
1510 | _ThisCommonFieldClass::operator=(fc); | |
1511 | return *this; | |
1512 | } | |
1513 | ||
328a274a PP |
1514 | CommonOptionFieldClass<const bt_field_class> asConst() const noexcept |
1515 | { | |
1516 | return CommonOptionFieldClass<const bt_field_class> {*this}; | |
1517 | } | |
1518 | ||
dcb8ae9b | 1519 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1520 | { |
1521 | return _FieldClass { | |
341a67c4 | 1522 | internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 PP |
1523 | } |
1524 | ||
1525 | Shared shared() const noexcept | |
1526 | { | |
c9c0b6e2 | 1527 | return Shared::createWithRef(*this); |
12435a68 PP |
1528 | } |
1529 | }; | |
1530 | ||
1531 | using OptionFieldClass = CommonOptionFieldClass<bt_field_class>; | |
1532 | using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>; | |
1533 | ||
4927bae7 PP |
1534 | namespace internal { |
1535 | ||
1536 | struct OptionFieldClassTypeDescr | |
1537 | { | |
1538 | using Const = ConstOptionFieldClass; | |
1539 | using NonConst = OptionFieldClass; | |
1540 | }; | |
1541 | ||
1542 | template <> | |
1543 | struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr | |
1544 | { | |
1545 | }; | |
1546 | ||
1547 | template <> | |
1548 | struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr | |
1549 | { | |
1550 | }; | |
1551 | ||
1552 | } /* namespace internal */ | |
1553 | ||
12435a68 PP |
1554 | template <typename LibObjT> |
1555 | class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT> | |
1556 | { | |
1557 | private: | |
1558 | using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass; | |
1559 | ||
1560 | protected: | |
12435a68 PP |
1561 | using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>; |
1562 | ||
1563 | public: | |
d246c457 | 1564 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1565 | using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1566 | |
d246c457 | 1567 | explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1568 | _ThisCommonOptionFieldClass {libObjPtr} |
1569 | { | |
1570 | BT_ASSERT_DBG(this->isOptionWithSelector()); | |
1571 | } | |
1572 | ||
1573 | template <typename OtherLibObjT> | |
1574 | CommonOptionWithSelectorFieldClass( | |
100fa861 | 1575 | const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1576 | _ThisCommonOptionFieldClass {fc} |
1577 | { | |
1578 | } | |
1579 | ||
1580 | template <typename OtherLibObjT> | |
ac30a470 | 1581 | CommonOptionWithSelectorFieldClass |
100fa861 | 1582 | operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1583 | { |
1584 | _ThisCommonOptionFieldClass::operator=(fc); | |
1585 | return *this; | |
1586 | } | |
1587 | ||
328a274a PP |
1588 | CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
1589 | { | |
1590 | return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this}; | |
1591 | } | |
1592 | ||
12435a68 PP |
1593 | ConstFieldPath selectorFieldPath() const noexcept |
1594 | { | |
1595 | return ConstFieldPath { | |
1596 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( | |
341a67c4 | 1597 | this->libObjPtr())}; |
12435a68 PP |
1598 | } |
1599 | ||
1600 | Shared shared() const noexcept | |
1601 | { | |
c9c0b6e2 | 1602 | return Shared::createWithRef(*this); |
12435a68 PP |
1603 | } |
1604 | }; | |
1605 | ||
1606 | using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>; | |
1607 | using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>; | |
1608 | ||
4927bae7 PP |
1609 | namespace internal { |
1610 | ||
1611 | struct OptionWithSelectorFieldClassTypeDescr | |
1612 | { | |
1613 | using Const = ConstOptionWithSelectorFieldClass; | |
1614 | using NonConst = OptionWithSelectorFieldClass; | |
1615 | }; | |
1616 | ||
1617 | template <> | |
1618 | struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr | |
1619 | { | |
1620 | }; | |
1621 | ||
1622 | template <> | |
1623 | struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr | |
1624 | { | |
1625 | }; | |
1626 | ||
1627 | } /* namespace internal */ | |
1628 | ||
12435a68 PP |
1629 | template <typename LibObjT> |
1630 | class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1631 | { | |
1632 | private: | |
12435a68 PP |
1633 | using typename CommonOptionWithSelectorFieldClass< |
1634 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1635 | ||
1636 | public: | |
d246c457 | 1637 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 1638 | using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 1639 | |
d246c457 | 1640 | explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1641 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
1642 | { | |
1643 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); | |
1644 | } | |
1645 | ||
1646 | template <typename OtherLibObjT> | |
1647 | CommonOptionWithBoolSelectorFieldClass( | |
100fa861 | 1648 | const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
1649 | _ThisCommonOptionWithSelectorFieldClass {fc} |
1650 | { | |
1651 | } | |
1652 | ||
1653 | template <typename OtherLibObjT> | |
ac30a470 | 1654 | CommonOptionWithBoolSelectorFieldClass |
100fa861 | 1655 | operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
1656 | { |
1657 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1658 | return *this; | |
1659 | } | |
1660 | ||
328a274a PP |
1661 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept |
1662 | { | |
1663 | return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this}; | |
1664 | } | |
1665 | ||
12435a68 PP |
1666 | bool selectorIsReversed() const noexcept |
1667 | { | |
1668 | return bt_field_class_option_with_selector_field_bool_selector_is_reversed( | |
341a67c4 | 1669 | this->libObjPtr()); |
12435a68 PP |
1670 | } |
1671 | ||
1672 | Shared shared() const noexcept | |
1673 | { | |
c9c0b6e2 | 1674 | return Shared::createWithRef(*this); |
12435a68 PP |
1675 | } |
1676 | }; | |
1677 | ||
1678 | using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>; | |
1679 | ||
1680 | using ConstOptionWithBoolSelectorFieldClass = | |
1681 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class>; | |
1682 | ||
1683 | namespace internal { | |
1684 | ||
4927bae7 PP |
1685 | struct OptionWithBoolSelectorFieldClassTypeDescr |
1686 | { | |
1687 | using Const = ConstOptionWithBoolSelectorFieldClass; | |
1688 | using NonConst = OptionWithBoolSelectorFieldClass; | |
1689 | }; | |
1690 | ||
1691 | template <> | |
1692 | struct TypeDescr<OptionWithBoolSelectorFieldClass> : | |
1693 | public OptionWithBoolSelectorFieldClassTypeDescr | |
1694 | { | |
1695 | }; | |
1696 | ||
1697 | template <> | |
1698 | struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> : | |
1699 | public OptionWithBoolSelectorFieldClassTypeDescr | |
1700 | { | |
1701 | }; | |
1702 | ||
12435a68 PP |
1703 | template <typename RangeSetT> |
1704 | struct CommonOptionWithIntegerSelectorFieldClassSpec; | |
1705 | ||
b5f55e9f | 1706 | /* Functions specific to option field classes with unsigned integer ranges */ |
12435a68 PP |
1707 | template <> |
1708 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final | |
1709 | { | |
1710 | static const bt_integer_range_set_unsigned * | |
1711 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1712 | { | |
1713 | return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( | |
1714 | libObjPtr); | |
1715 | } | |
1716 | }; | |
1717 | ||
b5f55e9f | 1718 | /* Functions specific to option field classes with signed ranges */ |
12435a68 PP |
1719 | template <> |
1720 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final | |
1721 | { | |
1722 | static const bt_integer_range_set_signed * | |
1723 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1724 | { | |
1725 | return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( | |
1726 | libObjPtr); | |
1727 | } | |
1728 | }; | |
1729 | ||
b5f55e9f | 1730 | } /* namespace internal */ |
12435a68 PP |
1731 | |
1732 | template <typename LibObjT, typename RangeSetT> | |
1733 | class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1734 | { | |
1735 | private: | |
12435a68 PP |
1736 | using typename CommonOptionWithSelectorFieldClass< |
1737 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1738 | ||
12435a68 | 1739 | public: |
d246c457 | 1740 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
ac19444e | 1741 | using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>; |
12435a68 PP |
1742 | using RangeSet = RangeSetT; |
1743 | ||
d246c457 | 1744 | explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
1745 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
1746 | { | |
1747 | BT_ASSERT_DBG(this->isOptionWithIntegerSelector()); | |
1748 | } | |
1749 | ||
1750 | template <typename OtherLibObjT> | |
1751 | CommonOptionWithIntegerSelectorFieldClass( | |
100fa861 | 1752 | const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept : |
12435a68 PP |
1753 | _ThisCommonOptionWithSelectorFieldClass {fc} |
1754 | { | |
1755 | } | |
1756 | ||
1757 | template <typename OtherLibObjT> | |
ac30a470 | 1758 | CommonOptionWithIntegerSelectorFieldClass |
100fa861 | 1759 | operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept |
12435a68 PP |
1760 | { |
1761 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1762 | return *this; | |
1763 | } | |
1764 | ||
1765 | RangeSet ranges() const noexcept | |
1766 | { | |
1767 | return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges( | |
341a67c4 | 1768 | this->libObjPtr())}; |
12435a68 PP |
1769 | } |
1770 | ||
1771 | Shared shared() const noexcept | |
1772 | { | |
c9c0b6e2 | 1773 | return Shared::createWithRef(*this); |
12435a68 PP |
1774 | } |
1775 | }; | |
1776 | ||
1777 | using OptionWithUnsignedIntegerSelectorFieldClass = | |
1778 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1779 | ||
1780 | using ConstOptionWithUnsignedIntegerSelectorFieldClass = | |
1781 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1782 | ||
1783 | using OptionWithSignedIntegerSelectorFieldClass = | |
1784 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>; | |
1785 | ||
1786 | using ConstOptionWithSignedIntegerSelectorFieldClass = | |
1787 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>; | |
1788 | ||
1789 | namespace internal { | |
1790 | ||
4927bae7 PP |
1791 | struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
1792 | { | |
1793 | using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass; | |
1794 | using NonConst = OptionWithUnsignedIntegerSelectorFieldClass; | |
1795 | }; | |
1796 | ||
1797 | template <> | |
1798 | struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> : | |
1799 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr | |
1800 | { | |
1801 | }; | |
1802 | ||
1803 | template <> | |
1804 | struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> : | |
1805 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr | |
1806 | { | |
1807 | }; | |
1808 | ||
1809 | struct OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1810 | { | |
1811 | using Const = ConstOptionWithSignedIntegerSelectorFieldClass; | |
1812 | using NonConst = OptionWithSignedIntegerSelectorFieldClass; | |
1813 | }; | |
1814 | ||
1815 | template <> | |
1816 | struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> : | |
1817 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1818 | { | |
1819 | }; | |
1820 | ||
1821 | template <> | |
1822 | struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> : | |
1823 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr | |
1824 | { | |
1825 | }; | |
1826 | ||
12435a68 PP |
1827 | template <typename LibObjT> |
1828 | struct CommonVariantFieldClassOptionSpec; | |
1829 | ||
b5f55e9f | 1830 | /* Functions specific to mutable variant field class options */ |
12435a68 PP |
1831 | template <> |
1832 | struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final | |
1833 | { | |
1834 | static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept | |
1835 | { | |
1836 | return bt_field_class_variant_option_borrow_field_class(libObjPtr); | |
1837 | } | |
8e557120 PP |
1838 | |
1839 | static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept | |
1840 | { | |
1841 | return bt_field_class_variant_option_borrow_user_attributes(libObjPtr); | |
1842 | } | |
12435a68 PP |
1843 | }; |
1844 | ||
b5f55e9f | 1845 | /* Functions specific to constant variant field class options */ |
12435a68 PP |
1846 | template <> |
1847 | struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final | |
1848 | { | |
1849 | static const bt_field_class * | |
1850 | fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept | |
1851 | { | |
1852 | return bt_field_class_variant_option_borrow_field_class_const(libObjPtr); | |
1853 | } | |
8e557120 PP |
1854 | |
1855 | static const bt_value * | |
1856 | userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept | |
1857 | { | |
1858 | return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr); | |
1859 | } | |
12435a68 PP |
1860 | }; |
1861 | ||
b5f55e9f | 1862 | } /* namespace internal */ |
12435a68 PP |
1863 | |
1864 | template <typename LibObjT> | |
0d218157 | 1865 | class CommonVariantFieldClassOption : public BorrowedObject<LibObjT> |
12435a68 PP |
1866 | { |
1867 | private: | |
0d218157 | 1868 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
8047a175 | 1869 | using _FieldClass = internal::DepFc<LibObjT>; |
12435a68 PP |
1870 | |
1871 | public: | |
d246c457 | 1872 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
8047a175 | 1873 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
8e557120 | 1874 | |
d246c457 | 1875 | explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 1876 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
1877 | { |
1878 | } | |
1879 | ||
1880 | template <typename OtherLibObjT> | |
100fa861 | 1881 | CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept : |
0d218157 | 1882 | _ThisBorrowedObject {fc} |
12435a68 PP |
1883 | { |
1884 | } | |
1885 | ||
1886 | template <typename OtherLibObjT> | |
ac30a470 | 1887 | CommonVariantFieldClassOption |
100fa861 | 1888 | operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept |
12435a68 | 1889 | { |
0d218157 | 1890 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
1891 | return *this; |
1892 | } | |
1893 | ||
328a274a PP |
1894 | CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept |
1895 | { | |
1896 | return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this}; | |
1897 | } | |
1898 | ||
e7f0f07b | 1899 | bt2c::CStringView name() const noexcept |
12435a68 | 1900 | { |
5cc5088c | 1901 | return bt_field_class_variant_option_get_name(this->libObjPtr()); |
12435a68 PP |
1902 | } |
1903 | ||
dcb8ae9b | 1904 | _FieldClass fieldClass() const noexcept |
12435a68 PP |
1905 | { |
1906 | return _FieldClass { | |
341a67c4 | 1907 | internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
12435a68 | 1908 | } |
8e557120 PP |
1909 | |
1910 | template <typename LibValT> | |
2a24eba8 SM |
1911 | CommonVariantFieldClassOption |
1912 | userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept | |
8e557120 | 1913 | { |
5c895f64 PP |
1914 | static_assert(!std::is_const<LibObjT>::value, |
1915 | "Not available with `bt2::ConstVariantFieldClassOption`."); | |
8e557120 PP |
1916 | |
1917 | bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); | |
2a24eba8 | 1918 | return *this; |
8e557120 PP |
1919 | } |
1920 | ||
dcb8ae9b | 1921 | UserAttributes userAttributes() const noexcept |
8e557120 PP |
1922 | { |
1923 | return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes( | |
1924 | this->libObjPtr())}; | |
1925 | } | |
12435a68 PP |
1926 | }; |
1927 | ||
1928 | using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>; | |
1929 | ||
1930 | using ConstVariantFieldClassOption = | |
1931 | CommonVariantFieldClassOption<const bt_field_class_variant_option>; | |
1932 | ||
1933 | namespace internal { | |
1934 | ||
4927bae7 PP |
1935 | struct VariantFieldClassOptionTypeDescr |
1936 | { | |
1937 | using Const = ConstVariantFieldClassOption; | |
1938 | using NonConst = VariantFieldClassOption; | |
1939 | }; | |
1940 | ||
1941 | template <> | |
1942 | struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr | |
1943 | { | |
1944 | }; | |
1945 | ||
1946 | template <> | |
1947 | struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr | |
1948 | { | |
1949 | }; | |
1950 | ||
12435a68 PP |
1951 | template <typename LibObjT> |
1952 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; | |
1953 | ||
b5f55e9f | 1954 | /* Functions specific to variant field class options with unsigned integer selector */ |
12435a68 PP |
1955 | template <> |
1956 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1957 | const bt_field_class_variant_with_selector_field_integer_unsigned_option> | |
1958 | final | |
1959 | { | |
1960 | static const bt_integer_range_set_unsigned * | |
1961 | ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1962 | * const libObjPtr) noexcept | |
1963 | { | |
1964 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( | |
1965 | libObjPtr); | |
1966 | } | |
1967 | ||
1968 | static const bt_field_class_variant_option * | |
1969 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1970 | * const libObjPtr) noexcept | |
1971 | { | |
1972 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const( | |
1973 | libObjPtr); | |
1974 | } | |
1975 | }; | |
1976 | ||
b5f55e9f | 1977 | /* Functions specific to variant field class options with signed integer selector */ |
12435a68 PP |
1978 | template <> |
1979 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1980 | const bt_field_class_variant_with_selector_field_integer_signed_option> | |
1981 | final | |
1982 | { | |
1983 | static const bt_integer_range_set_signed * | |
1984 | ranges(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1985 | * const libObjPtr) noexcept | |
1986 | { | |
1987 | return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( | |
1988 | libObjPtr); | |
1989 | } | |
1990 | ||
1991 | static const bt_field_class_variant_option * | |
1992 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1993 | * const libObjPtr) noexcept | |
1994 | { | |
1995 | return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const( | |
1996 | libObjPtr); | |
1997 | } | |
1998 | }; | |
1999 | ||
b5f55e9f | 2000 | } /* namespace internal */ |
12435a68 PP |
2001 | |
2002 | template <typename LibObjT> | |
0d218157 | 2003 | class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT> |
12435a68 PP |
2004 | { |
2005 | private: | |
0d218157 | 2006 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
12435a68 PP |
2007 | using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>; |
2008 | ||
2009 | public: | |
d246c457 PP |
2010 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
2011 | ||
12435a68 PP |
2012 | using RangeSet = typename std::conditional< |
2013 | std::is_same< | |
2014 | LibObjT, | |
2015 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value, | |
2016 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; | |
2017 | ||
d246c457 | 2018 | explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
0d218157 | 2019 | _ThisBorrowedObject {libObjPtr} |
12435a68 PP |
2020 | { |
2021 | } | |
2022 | ||
2023 | template <typename OtherLibObjT> | |
2024 | ConstVariantWithIntegerSelectorFieldClassOption( | |
100fa861 | 2025 | const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept : |
0d218157 | 2026 | _ThisBorrowedObject {fc} |
12435a68 PP |
2027 | { |
2028 | } | |
2029 | ||
2030 | template <typename OtherLibObjT> | |
ac30a470 | 2031 | ConstVariantWithIntegerSelectorFieldClassOption |
100fa861 | 2032 | operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept |
12435a68 | 2033 | { |
0d218157 | 2034 | _ThisBorrowedObject::operator=(fc); |
12435a68 PP |
2035 | return *this; |
2036 | } | |
2037 | ||
2038 | ConstVariantFieldClassOption asBaseOption() const noexcept | |
2039 | { | |
341a67c4 | 2040 | return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())}; |
12435a68 PP |
2041 | } |
2042 | ||
e7f0f07b | 2043 | bt2c::CStringView name() const noexcept |
12435a68 PP |
2044 | { |
2045 | return this->asBaseOption().name(); | |
2046 | } | |
2047 | ||
2048 | ConstFieldClass fieldClass() const noexcept | |
2049 | { | |
2050 | return this->asBaseOption().fieldClass(); | |
2051 | } | |
2052 | ||
2053 | RangeSet ranges() const noexcept | |
2054 | { | |
341a67c4 | 2055 | return RangeSet {_Spec::ranges(this->libObjPtr())}; |
12435a68 PP |
2056 | } |
2057 | }; | |
2058 | ||
2059 | using ConstVariantWithUnsignedIntegerSelectorFieldClassOption = | |
2060 | ConstVariantWithIntegerSelectorFieldClassOption< | |
2061 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>; | |
2062 | ||
2063 | using ConstVariantWithSignedIntegerSelectorFieldClassOption = | |
2064 | ConstVariantWithIntegerSelectorFieldClassOption< | |
2065 | const bt_field_class_variant_with_selector_field_integer_signed_option>; | |
2066 | ||
2067 | namespace internal { | |
2068 | ||
2069 | template <typename LibObjT> | |
2070 | struct CommonVariantFieldClassSpec; | |
2071 | ||
b5f55e9f | 2072 | /* Functions specific to mutable variant field classes */ |
12435a68 PP |
2073 | template <> |
2074 | struct CommonVariantFieldClassSpec<bt_field_class> final | |
2075 | { | |
2076 | static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr, | |
2077 | const std::uint64_t index) noexcept | |
2078 | { | |
2079 | return bt_field_class_variant_borrow_option_by_index(libObjPtr, index); | |
2080 | } | |
2081 | ||
2082 | static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr, | |
2083 | const char * const name) noexcept | |
2084 | { | |
2085 | return bt_field_class_variant_borrow_option_by_name(libObjPtr, name); | |
2086 | } | |
2087 | }; | |
2088 | ||
b5f55e9f | 2089 | /* Functions specific to constant variant field classes */ |
12435a68 PP |
2090 | template <> |
2091 | struct CommonVariantFieldClassSpec<const bt_field_class> final | |
2092 | { | |
2093 | static const bt_field_class_variant_option * | |
2094 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2095 | { | |
2096 | return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index); | |
2097 | } | |
2098 | ||
2099 | static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr, | |
2100 | const char * const name) noexcept | |
2101 | { | |
2102 | return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name); | |
2103 | } | |
2104 | }; | |
2105 | ||
b5f55e9f | 2106 | } /* namespace internal */ |
12435a68 PP |
2107 | |
2108 | template <typename LibObjT> | |
2109 | class CommonVariantFieldClass : public CommonFieldClass<LibObjT> | |
2110 | { | |
2111 | private: | |
2112 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
2113 | ||
2114 | protected: | |
12435a68 PP |
2115 | using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>; |
2116 | ||
2117 | public: | |
d246c457 | 2118 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2119 | using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>; |
56862ee2 | 2120 | using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>; |
12435a68 PP |
2121 | |
2122 | using Option = | |
8047a175 | 2123 | internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>; |
12435a68 | 2124 | |
d246c457 | 2125 | explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
2126 | _ThisCommonFieldClass {libObjPtr} |
2127 | { | |
2128 | BT_ASSERT_DBG(this->isVariant()); | |
2129 | } | |
2130 | ||
2131 | template <typename OtherLibObjT> | |
100fa861 | 2132 | CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
2133 | _ThisCommonFieldClass {fc} |
2134 | { | |
2135 | } | |
2136 | ||
2137 | template <typename OtherLibObjT> | |
ac30a470 | 2138 | CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
2139 | { |
2140 | _ThisCommonFieldClass::operator=(fc); | |
2141 | return *this; | |
2142 | } | |
2143 | ||
328a274a PP |
2144 | CommonVariantFieldClass<const bt_field_class> asConst() const noexcept |
2145 | { | |
2146 | return CommonVariantFieldClass<const bt_field_class> {*this}; | |
2147 | } | |
2148 | ||
c0b73c63 | 2149 | std::uint64_t length() const noexcept |
12435a68 | 2150 | { |
341a67c4 | 2151 | return bt_field_class_variant_get_option_count(this->libObjPtr()); |
12435a68 PP |
2152 | } |
2153 | ||
5046c776 FD |
2154 | Iterator begin() const noexcept |
2155 | { | |
2156 | return Iterator {*this, 0}; | |
2157 | } | |
2158 | ||
2159 | Iterator end() const noexcept | |
2160 | { | |
c0b73c63 | 2161 | return Iterator {*this, this->length()}; |
5046c776 FD |
2162 | } |
2163 | ||
dcb8ae9b | 2164 | Option operator[](const std::uint64_t index) const noexcept |
12435a68 PP |
2165 | { |
2166 | return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex( | |
341a67c4 | 2167 | this->libObjPtr(), index)}; |
12435a68 PP |
2168 | } |
2169 | ||
15030982 | 2170 | OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 2171 | { |
ca61ecbc PP |
2172 | return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), |
2173 | name); | |
12435a68 PP |
2174 | } |
2175 | ||
12435a68 PP |
2176 | Shared shared() const noexcept |
2177 | { | |
c9c0b6e2 | 2178 | return Shared::createWithRef(*this); |
12435a68 PP |
2179 | } |
2180 | }; | |
2181 | ||
2182 | using VariantFieldClass = CommonVariantFieldClass<bt_field_class>; | |
2183 | using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>; | |
2184 | ||
4927bae7 PP |
2185 | namespace internal { |
2186 | ||
2187 | struct VariantFieldClassTypeDescr | |
2188 | { | |
2189 | using Const = ConstVariantFieldClass; | |
2190 | using NonConst = VariantFieldClass; | |
2191 | }; | |
2192 | ||
2193 | template <> | |
2194 | struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr | |
2195 | { | |
2196 | }; | |
2197 | ||
2198 | template <> | |
2199 | struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr | |
2200 | { | |
2201 | }; | |
2202 | ||
2203 | } /* namespace internal */ | |
2204 | ||
12435a68 PP |
2205 | template <typename LibObjT> |
2206 | class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
2207 | { | |
2208 | private: | |
2209 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
12435a68 PP |
2210 | |
2211 | public: | |
d246c457 | 2212 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2213 | using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>; |
12435a68 | 2214 | |
d246c457 | 2215 | explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
12435a68 PP |
2216 | _ThisCommonVariantFieldClass {libObjPtr} |
2217 | { | |
2218 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); | |
2219 | } | |
2220 | ||
2221 | template <typename OtherLibObjT> | |
2222 | CommonVariantWithoutSelectorFieldClass( | |
100fa861 | 2223 | const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept : |
12435a68 PP |
2224 | _ThisCommonVariantFieldClass {fc} |
2225 | { | |
2226 | } | |
2227 | ||
2228 | template <typename OtherLibObjT> | |
ac30a470 | 2229 | CommonVariantWithoutSelectorFieldClass |
100fa861 | 2230 | operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept |
12435a68 PP |
2231 | { |
2232 | _ThisCommonVariantFieldClass::operator=(fc); | |
2233 | return *this; | |
2234 | } | |
2235 | ||
328a274a PP |
2236 | CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept |
2237 | { | |
2238 | return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this}; | |
2239 | } | |
2240 | ||
2a24eba8 SM |
2241 | CommonVariantWithoutSelectorFieldClass appendOption(const char * const name, |
2242 | const FieldClass fc) const | |
12435a68 | 2243 | { |
5c895f64 PP |
2244 | static_assert(!std::is_const<LibObjT>::value, |
2245 | "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`."); | |
12435a68 PP |
2246 | |
2247 | const auto status = bt_field_class_variant_without_selector_append_option( | |
341a67c4 | 2248 | this->libObjPtr(), name, fc.libObjPtr()); |
12435a68 PP |
2249 | |
2250 | if (status == | |
2251 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
39278ebc | 2252 | throw MemoryError {}; |
12435a68 | 2253 | } |
2a24eba8 SM |
2254 | |
2255 | return *this; | |
12435a68 PP |
2256 | } |
2257 | ||
2a24eba8 SM |
2258 | CommonVariantWithoutSelectorFieldClass appendOption(const bt2c::CStringView name, |
2259 | const FieldClass fc) const | |
15030982 SM |
2260 | { |
2261 | return this->appendOption(name.data(), fc); | |
2262 | } | |
2263 | ||
2a24eba8 SM |
2264 | CommonVariantWithoutSelectorFieldClass appendOption(const bt2s::optional<std::string>& name, |
2265 | const FieldClass fc) const | |
12435a68 | 2266 | { |
2a24eba8 | 2267 | return this->appendOption(name ? name->data() : nullptr, fc); |
12435a68 PP |
2268 | } |
2269 | ||
2270 | Shared shared() const noexcept | |
2271 | { | |
c9c0b6e2 | 2272 | return Shared::createWithRef(*this); |
12435a68 PP |
2273 | } |
2274 | }; | |
2275 | ||
2276 | using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>; | |
2277 | using ConstVariantWithoutSelectorFieldClass = | |
2278 | CommonVariantWithoutSelectorFieldClass<const bt_field_class>; | |
2279 | ||
2280 | namespace internal { | |
2281 | ||
4927bae7 PP |
2282 | struct VariantWithoutSelectorFieldClassTypeDescr |
2283 | { | |
2284 | using Const = ConstVariantWithoutSelectorFieldClass; | |
2285 | using NonConst = VariantWithoutSelectorFieldClass; | |
2286 | }; | |
2287 | ||
2288 | template <> | |
2289 | struct TypeDescr<VariantWithoutSelectorFieldClass> : | |
2290 | public VariantWithoutSelectorFieldClassTypeDescr | |
2291 | { | |
2292 | }; | |
2293 | ||
2294 | template <> | |
2295 | struct TypeDescr<ConstVariantWithoutSelectorFieldClass> : | |
2296 | public VariantWithoutSelectorFieldClassTypeDescr | |
2297 | { | |
2298 | }; | |
2299 | ||
12435a68 PP |
2300 | template <typename OptionT> |
2301 | struct CommonVariantWithIntegerSelectorFieldClassSpec; | |
2302 | ||
b5f55e9f | 2303 | /* Functions specific to variant field classes with unsigned integer selector */ |
12435a68 PP |
2304 | template <> |
2305 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
2306 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
2307 | final | |
2308 | { | |
2309 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
2310 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2311 | { | |
2312 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( | |
2313 | libObjPtr, index); | |
2314 | } | |
2315 | ||
2316 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
2317 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
2318 | { | |
2319 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( | |
2320 | libObjPtr, name); | |
2321 | } | |
2322 | ||
2323 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
2324 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
2325 | bt_field_class * const libOptFcPtr, | |
2326 | const bt_integer_range_set_unsigned * const libRangesPtr) | |
2327 | { | |
2328 | return bt_field_class_variant_with_selector_field_integer_unsigned_append_option( | |
2329 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
2330 | } | |
2331 | }; | |
2332 | ||
b5f55e9f | 2333 | /* Functions specific to variant field classes with signed integer selector */ |
12435a68 PP |
2334 | template <> |
2335 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
2336 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
2337 | final | |
2338 | { | |
2339 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
2340 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
2341 | { | |
2342 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( | |
2343 | libObjPtr, index); | |
2344 | } | |
2345 | ||
2346 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
2347 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
2348 | { | |
2349 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( | |
2350 | libObjPtr, name); | |
2351 | } | |
2352 | ||
2353 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
2354 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
2355 | bt_field_class * const libOptFcPtr, | |
2356 | const bt_integer_range_set_signed * const libRangesPtr) | |
2357 | { | |
2358 | return bt_field_class_variant_with_selector_field_integer_signed_append_option( | |
2359 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
2360 | } | |
2361 | }; | |
2362 | ||
b5f55e9f | 2363 | } /* namespace internal */ |
12435a68 | 2364 | |
cefe03a2 FD |
2365 | template <typename LibObjT> |
2366 | class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
12435a68 PP |
2367 | { |
2368 | private: | |
2369 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
cefe03a2 FD |
2370 | |
2371 | protected: | |
cefe03a2 FD |
2372 | using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>; |
2373 | ||
2374 | public: | |
d246c457 | 2375 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
26b9d24c | 2376 | using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>; |
cefe03a2 | 2377 | |
d246c457 | 2378 | explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
cefe03a2 FD |
2379 | _ThisCommonVariantFieldClass {libObjPtr} |
2380 | { | |
2381 | BT_ASSERT_DBG(this->isVariantWithSelector()); | |
2382 | } | |
2383 | ||
2384 | template <typename OtherLibObjT> | |
2385 | CommonVariantWithSelectorFieldClass( | |
100fa861 | 2386 | const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
cefe03a2 FD |
2387 | _ThisCommonVariantFieldClass {fc} |
2388 | { | |
2389 | } | |
2390 | ||
2391 | template <typename OtherLibObjT> | |
ac30a470 | 2392 | CommonVariantWithSelectorFieldClass |
100fa861 | 2393 | operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
cefe03a2 FD |
2394 | { |
2395 | _ThisCommonVariantFieldClass::operator=(fc); | |
2396 | return *this; | |
2397 | } | |
2398 | ||
328a274a PP |
2399 | CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
2400 | { | |
2401 | return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this}; | |
2402 | } | |
2403 | ||
cefe03a2 FD |
2404 | ConstFieldPath selectorFieldPath() const noexcept |
2405 | { | |
2406 | return ConstFieldPath { | |
2407 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( | |
341a67c4 | 2408 | this->libObjPtr())}; |
cefe03a2 FD |
2409 | } |
2410 | ||
2411 | Shared shared() const noexcept | |
2412 | { | |
c9c0b6e2 | 2413 | return Shared::createWithRef(*this); |
cefe03a2 FD |
2414 | } |
2415 | }; | |
12435a68 | 2416 | |
3c02a7cb FD |
2417 | using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>; |
2418 | using ConstVariantWithSelectorFieldClass = | |
2419 | CommonVariantWithSelectorFieldClass<const bt_field_class>; | |
2420 | ||
cefe03a2 FD |
2421 | template <typename LibObjT, typename OptionT> |
2422 | class CommonVariantWithIntegerSelectorFieldClass : | |
2423 | public CommonVariantWithSelectorFieldClass<LibObjT> | |
2424 | { | |
2425 | private: | |
2426 | using typename CommonVariantWithSelectorFieldClass< | |
2427 | LibObjT>::_ThisCommonVariantWithSelectorFieldClass; | |
12435a68 PP |
2428 | |
2429 | using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>; | |
2430 | ||
2431 | public: | |
d246c457 | 2432 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
ac19444e | 2433 | using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>; |
12435a68 | 2434 | using Option = OptionT; |
56862ee2 | 2435 | |
3c02a7cb | 2436 | using Iterator = |
56862ee2 | 2437 | BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>; |
12435a68 | 2438 | |
d246c457 | 2439 | explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
cefe03a2 | 2440 | _ThisCommonVariantWithSelectorFieldClass {libObjPtr} |
12435a68 | 2441 | { |
5ca48ae9 | 2442 | BT_ASSERT_DBG(this->isVariantWithIntegerSelector()); |
12435a68 PP |
2443 | } |
2444 | ||
2445 | template <typename OtherLibObjT> | |
2446 | CommonVariantWithIntegerSelectorFieldClass( | |
100fa861 | 2447 | const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept : |
cefe03a2 | 2448 | _ThisCommonVariantWithSelectorFieldClass {fc} |
12435a68 PP |
2449 | { |
2450 | } | |
2451 | ||
2452 | template <typename OtherLibObjT> | |
ac30a470 | 2453 | CommonVariantWithIntegerSelectorFieldClass |
100fa861 | 2454 | operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept |
12435a68 | 2455 | { |
cefe03a2 | 2456 | _ThisCommonVariantWithSelectorFieldClass::operator=(fc); |
12435a68 PP |
2457 | return *this; |
2458 | } | |
2459 | ||
12435a68 PP |
2460 | Option operator[](const std::uint64_t index) const noexcept |
2461 | { | |
341a67c4 | 2462 | return Option {_Spec::optionByIndex(this->libObjPtr(), index)}; |
12435a68 PP |
2463 | } |
2464 | ||
15030982 | 2465 | OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept |
12435a68 | 2466 | { |
ca61ecbc | 2467 | return _Spec::optionByName(this->libObjPtr(), name); |
12435a68 PP |
2468 | } |
2469 | ||
2a24eba8 SM |
2470 | CommonVariantWithIntegerSelectorFieldClass |
2471 | appendOption(const char * const name, const FieldClass fc, | |
2472 | const typename Option::RangeSet ranges) const | |
12435a68 | 2473 | { |
5c895f64 PP |
2474 | static_assert( |
2475 | !std::is_const<LibObjT>::value, | |
2476 | "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`."); | |
12435a68 PP |
2477 | |
2478 | const auto status = | |
341a67c4 | 2479 | _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr()); |
12435a68 PP |
2480 | |
2481 | if (status == | |
2482 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
39278ebc | 2483 | throw MemoryError {}; |
12435a68 | 2484 | } |
2a24eba8 SM |
2485 | |
2486 | return *this; | |
12435a68 PP |
2487 | } |
2488 | ||
2a24eba8 SM |
2489 | CommonVariantWithIntegerSelectorFieldClass |
2490 | appendOption(const bt2c::CStringView name, const FieldClass fc, | |
2491 | const typename Option::RangeSet ranges) const | |
15030982 SM |
2492 | { |
2493 | return this->appendOption(name.data(), fc, ranges); | |
2494 | } | |
2495 | ||
2a24eba8 SM |
2496 | CommonVariantWithIntegerSelectorFieldClass |
2497 | appendOption(const bt2s::optional<std::string>& name, const FieldClass fc, | |
2498 | const typename Option::RangeSet ranges) const | |
12435a68 | 2499 | { |
2a24eba8 | 2500 | return this->appendOption(name ? name->data() : nullptr, fc, ranges); |
12435a68 PP |
2501 | } |
2502 | ||
3c02a7cb FD |
2503 | Iterator begin() const noexcept |
2504 | { | |
2505 | return Iterator {*this, 0}; | |
2506 | } | |
2507 | ||
2508 | Iterator end() const noexcept | |
2509 | { | |
c0b73c63 | 2510 | return Iterator {*this, this->length()}; |
3c02a7cb FD |
2511 | } |
2512 | ||
12435a68 PP |
2513 | Shared shared() const noexcept |
2514 | { | |
c9c0b6e2 | 2515 | return Shared::createWithRef(*this); |
12435a68 PP |
2516 | } |
2517 | }; | |
2518 | ||
2519 | using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2520 | bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2521 | ||
2522 | using ConstVariantWithUnsignedIntegerSelectorFieldClass = | |
2523 | CommonVariantWithIntegerSelectorFieldClass< | |
2524 | const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2525 | ||
2526 | using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2527 | bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2528 | ||
2529 | using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2530 | const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2531 | ||
4927bae7 PP |
2532 | namespace internal { |
2533 | ||
2534 | struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2535 | { | |
2536 | using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass; | |
2537 | using NonConst = VariantWithUnsignedIntegerSelectorFieldClass; | |
2538 | }; | |
2539 | ||
2540 | template <> | |
2541 | struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> : | |
2542 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2543 | { | |
2544 | }; | |
2545 | ||
2546 | template <> | |
2547 | struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> : | |
2548 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr | |
2549 | { | |
2550 | }; | |
2551 | ||
2552 | struct VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2553 | { | |
2554 | using Const = ConstVariantWithSignedIntegerSelectorFieldClass; | |
2555 | using NonConst = VariantWithSignedIntegerSelectorFieldClass; | |
2556 | }; | |
2557 | ||
2558 | template <> | |
2559 | struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> : | |
2560 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2561 | { | |
2562 | }; | |
2563 | ||
2564 | template <> | |
2565 | struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> : | |
2566 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr | |
2567 | { | |
2568 | }; | |
2569 | ||
2570 | } /* namespace internal */ | |
2571 | ||
12435a68 PP |
2572 | template <typename LibObjT> |
2573 | CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept | |
2574 | { | |
341a67c4 | 2575 | return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2576 | } |
2577 | ||
2578 | template <typename LibObjT> | |
2579 | CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept | |
2580 | { | |
341a67c4 | 2581 | return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2582 | } |
2583 | ||
be6aa636 FD |
2584 | template <typename LibObjT> |
2585 | CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept | |
2586 | { | |
341a67c4 | 2587 | return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()}; |
be6aa636 FD |
2588 | } |
2589 | ||
12435a68 PP |
2590 | template <typename LibObjT> |
2591 | CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> | |
2592 | CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept | |
2593 | { | |
2594 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); | |
2595 | return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> { | |
341a67c4 | 2596 | this->libObjPtr()}; |
12435a68 PP |
2597 | } |
2598 | ||
2599 | template <typename LibObjT> | |
2600 | CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> | |
2601 | CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept | |
2602 | { | |
2603 | BT_ASSERT_DBG(this->isSignedEnumeration()); | |
2604 | return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> { | |
341a67c4 | 2605 | this->libObjPtr()}; |
12435a68 PP |
2606 | } |
2607 | ||
2608 | template <typename LibObjT> | |
2609 | CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept | |
2610 | { | |
341a67c4 | 2611 | return CommonStructureFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2612 | } |
2613 | ||
2614 | template <typename LibObjT> | |
2615 | CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept | |
2616 | { | |
341a67c4 | 2617 | return CommonArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2618 | } |
2619 | ||
2620 | template <typename LibObjT> | |
2621 | CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept | |
2622 | { | |
341a67c4 | 2623 | return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2624 | } |
2625 | ||
2626 | template <typename LibObjT> | |
2627 | CommonDynamicArrayWithLengthFieldClass<LibObjT> | |
2628 | CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept | |
2629 | { | |
341a67c4 | 2630 | return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2631 | } |
2632 | ||
2633 | template <typename LibObjT> | |
2634 | CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept | |
2635 | { | |
341a67c4 | 2636 | return CommonOptionFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2637 | } |
2638 | ||
2639 | template <typename LibObjT> | |
2640 | CommonOptionWithSelectorFieldClass<LibObjT> | |
2641 | CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept | |
2642 | { | |
341a67c4 | 2643 | return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2644 | } |
2645 | ||
2646 | template <typename LibObjT> | |
2647 | CommonOptionWithBoolSelectorFieldClass<LibObjT> | |
2648 | CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept | |
2649 | { | |
341a67c4 | 2650 | return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2651 | } |
2652 | ||
2653 | template <typename LibObjT> | |
2654 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> | |
2655 | CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept | |
2656 | { | |
2657 | BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector()); | |
2658 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> { | |
341a67c4 | 2659 | this->libObjPtr()}; |
12435a68 PP |
2660 | } |
2661 | ||
2662 | template <typename LibObjT> | |
2663 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> | |
2664 | CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept | |
2665 | { | |
2666 | BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector()); | |
2667 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> { | |
341a67c4 | 2668 | this->libObjPtr()}; |
12435a68 PP |
2669 | } |
2670 | ||
2671 | template <typename LibObjT> | |
2672 | CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept | |
2673 | { | |
341a67c4 | 2674 | return CommonVariantFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2675 | } |
2676 | ||
2677 | template <typename LibObjT> | |
2678 | CommonVariantWithoutSelectorFieldClass<LibObjT> | |
2679 | CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept | |
2680 | { | |
341a67c4 | 2681 | return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
12435a68 PP |
2682 | } |
2683 | ||
2684 | template <typename LibObjT> | |
cefe03a2 FD |
2685 | CommonVariantWithSelectorFieldClass<LibObjT> |
2686 | CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept | |
2687 | { | |
341a67c4 | 2688 | return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
cefe03a2 FD |
2689 | } |
2690 | ||
2691 | template <typename LibObjT> | |
12435a68 PP |
2692 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
2693 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
2694 | CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept | |
2695 | { | |
2696 | BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector()); | |
2697 | return CommonVariantWithIntegerSelectorFieldClass< | |
341a67c4 | 2698 | LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
12435a68 PP |
2699 | } |
2700 | ||
2701 | template <typename LibObjT> | |
2702 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, | |
2703 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
2704 | CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept | |
2705 | { | |
2706 | BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector()); | |
2707 | return CommonVariantWithIntegerSelectorFieldClass< | |
341a67c4 | 2708 | LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
12435a68 PP |
2709 | } |
2710 | ||
b5f55e9f | 2711 | } /* namespace bt2 */ |
12435a68 | 2712 | |
b5f55e9f | 2713 | #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */ |