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