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