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