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