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