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