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" | |
17 | #include "cpp-common/optional.hpp" | |
18 | #include "cpp-common/string_view.hpp" | |
19 | #include "lib-error.hpp" | |
20 | #include "integer-range-set.hpp" | |
21 | #include "field-path.hpp" | |
22 | ||
23 | namespace bt2 { | |
24 | ||
25 | namespace internal { | |
26 | ||
27 | struct FieldClassRefFuncs final | |
28 | { | |
29 | static void get(const bt_field_class * const libObjPtr) | |
30 | { | |
31 | bt_field_class_get_ref(libObjPtr); | |
32 | } | |
33 | ||
34 | static void put(const bt_field_class * const libObjPtr) | |
35 | { | |
36 | bt_field_class_put_ref(libObjPtr); | |
37 | } | |
38 | }; | |
39 | ||
40 | template <typename ObjT, typename LibObjT> | |
41 | using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>; | |
42 | ||
43 | template <typename LibObjT> | |
44 | struct CommonFieldClassSpec; | |
45 | ||
46 | // Functions specific to mutable field classes | |
47 | template <> | |
48 | struct CommonFieldClassSpec<bt_field_class> final | |
49 | { | |
50 | static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept | |
51 | { | |
52 | return bt_field_class_borrow_user_attributes(libObjPtr); | |
53 | } | |
54 | }; | |
55 | ||
56 | // Functions specific to constant field classes | |
57 | template <> | |
58 | struct CommonFieldClassSpec<const bt_field_class> final | |
59 | { | |
60 | static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept | |
61 | { | |
62 | return bt_field_class_borrow_user_attributes_const(libObjPtr); | |
63 | } | |
64 | }; | |
65 | ||
66 | } // namespace internal | |
67 | ||
68 | template <typename LibObjT> | |
69 | class CommonBitArrayFieldClass; | |
70 | ||
71 | template <typename LibObjT> | |
72 | class CommonIntegerFieldClass; | |
73 | ||
74 | template <typename LibObjT> | |
75 | class ConstEnumerationFieldClassMapping; | |
76 | ||
77 | template <typename LibObjT, typename MappingT> | |
78 | class CommonEnumerationFieldClass; | |
79 | ||
80 | template <typename LibObjT> | |
81 | class CommonStructureFieldClass; | |
82 | ||
83 | template <typename LibObjT> | |
84 | class CommonArrayFieldClass; | |
85 | ||
86 | template <typename LibObjT> | |
87 | class CommonStaticArrayFieldClass; | |
88 | ||
89 | template <typename LibObjT> | |
90 | class CommonDynamicArrayWithLengthFieldClass; | |
91 | ||
92 | template <typename LibObjT> | |
93 | class CommonOptionFieldClass; | |
94 | ||
95 | template <typename LibObjT> | |
96 | class CommonOptionWithSelectorFieldClass; | |
97 | ||
98 | template <typename LibObjT> | |
99 | class CommonOptionWithBoolSelectorFieldClass; | |
100 | ||
101 | template <typename LibObjT> | |
102 | class CommonVariantFieldClass; | |
103 | ||
104 | template <typename LibObjT, typename RangeSetT> | |
105 | class CommonOptionWithIntegerSelectorFieldClass; | |
106 | ||
107 | template <typename LibObjT> | |
108 | class CommonVariantWithoutSelectorFieldClass; | |
109 | ||
110 | template <typename LibObjT> | |
111 | class ConstVariantWithIntegerSelectorFieldClassOption; | |
112 | ||
113 | template <typename LibObjT, typename RangeSetT> | |
114 | class CommonVariantWithIntegerSelectorFieldClass; | |
115 | ||
116 | enum class FieldClassType | |
117 | { | |
118 | BOOL = BT_FIELD_CLASS_TYPE_BOOL, | |
119 | BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY, | |
120 | UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER, | |
121 | SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER, | |
122 | UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
123 | SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
124 | SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, | |
125 | DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, | |
126 | STRING = BT_FIELD_CLASS_TYPE_STRING, | |
127 | STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE, | |
128 | STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
129 | DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, | |
130 | DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, | |
131 | OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD, | |
132 | OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, | |
133 | OPTION_WITH_UNSIGNED_INTEGER_SELECTOR = | |
134 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, | |
135 | OPTION_WITH_SIGNED_INTEGER_SELECTOR = | |
136 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD, | |
137 | VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, | |
138 | VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR = | |
139 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, | |
140 | VARIANT_WITH_SIGNED_INTEGER_SELECTOR = | |
141 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, | |
142 | }; | |
143 | ||
144 | template <typename LibObjT> | |
145 | class CommonFieldClass : public internal::BorrowedObj<LibObjT> | |
146 | { | |
147 | // Allow appendMember() to call `fc._libObjPtr()` | |
148 | friend class CommonStructureFieldClass<bt_field_class>; | |
149 | ||
150 | // Allow appendOption() to call `fc._libObjPtr()` | |
151 | friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>; | |
152 | ||
153 | friend class CommonVariantWithIntegerSelectorFieldClass< | |
154 | bt_field_class, | |
155 | ConstVariantWithIntegerSelectorFieldClassOption< | |
156 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>>; | |
157 | ||
158 | friend class CommonVariantWithIntegerSelectorFieldClass< | |
159 | bt_field_class, | |
160 | ConstVariantWithIntegerSelectorFieldClassOption< | |
161 | const bt_field_class_variant_with_selector_field_integer_signed_option>>; | |
162 | ||
163 | private: | |
164 | using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj; | |
165 | ||
166 | protected: | |
167 | using typename internal::BorrowedObj<LibObjT>::_LibObjPtr; | |
168 | using _ThisCommonFieldClass = CommonFieldClass<LibObjT>; | |
169 | ||
170 | public: | |
171 | using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>; | |
172 | ||
173 | using UserAttributes = | |
174 | typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type; | |
175 | ||
176 | explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} | |
177 | { | |
178 | } | |
179 | ||
180 | template <typename OtherLibObjT> | |
181 | CommonFieldClass(const CommonFieldClass<OtherLibObjT>& fc) noexcept : _ThisBorrowedObj {fc} | |
182 | { | |
183 | } | |
184 | ||
185 | template <typename OtherLibObjT> | |
186 | _ThisCommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT>& fc) noexcept | |
187 | { | |
188 | _ThisBorrowedObj::operator=(fc); | |
189 | return *this; | |
190 | } | |
191 | ||
192 | FieldClassType type() const noexcept | |
193 | { | |
194 | return static_cast<FieldClassType>(bt_field_class_get_type(this->_libObjPtr())); | |
195 | } | |
196 | ||
197 | bool isBool() const noexcept | |
198 | { | |
199 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL); | |
200 | } | |
201 | ||
202 | bool isBitArray() const noexcept | |
203 | { | |
204 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY); | |
205 | } | |
206 | ||
207 | bool isInteger() const noexcept | |
208 | { | |
209 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER); | |
210 | } | |
211 | ||
212 | bool isUnsignedInteger() const noexcept | |
213 | { | |
214 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); | |
215 | } | |
216 | ||
217 | bool isSignedInteger() const noexcept | |
218 | { | |
219 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); | |
220 | } | |
221 | ||
222 | bool isEnumeration() const noexcept | |
223 | { | |
224 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION); | |
225 | } | |
226 | ||
227 | bool isUnsignedEnumeration() const noexcept | |
228 | { | |
229 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); | |
230 | } | |
231 | ||
232 | bool isSignedEnumeration() const noexcept | |
233 | { | |
234 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); | |
235 | } | |
236 | ||
237 | bool isSinglePrecisionReal() const noexcept | |
238 | { | |
239 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); | |
240 | } | |
241 | ||
242 | bool isDoublePrecisionReal() const noexcept | |
243 | { | |
244 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); | |
245 | } | |
246 | ||
247 | bool isString() const noexcept | |
248 | { | |
249 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING); | |
250 | } | |
251 | ||
252 | bool isStructure() const noexcept | |
253 | { | |
254 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE); | |
255 | } | |
256 | ||
257 | bool isArray() const noexcept | |
258 | { | |
259 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY); | |
260 | } | |
261 | ||
262 | bool isStaticArray() const noexcept | |
263 | { | |
264 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY); | |
265 | } | |
266 | ||
267 | bool isDynamicArray() const noexcept | |
268 | { | |
269 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY); | |
270 | } | |
271 | ||
272 | bool isDynamicArrayWithoutLength() const noexcept | |
273 | { | |
274 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD); | |
275 | } | |
276 | ||
277 | bool isDynamicArrayWithLength() const noexcept | |
278 | { | |
279 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); | |
280 | } | |
281 | ||
282 | bool isOption() const noexcept | |
283 | { | |
284 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION); | |
285 | } | |
286 | ||
287 | bool isOptionWithoutSelector() const noexcept | |
288 | { | |
289 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD); | |
290 | } | |
291 | ||
292 | bool isOptionWithSelector() const noexcept | |
293 | { | |
294 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD); | |
295 | } | |
296 | ||
297 | bool isOptionWithBoolSelector() const noexcept | |
298 | { | |
299 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD); | |
300 | } | |
301 | ||
302 | bool isOptionWithIntegerSelector() const noexcept | |
303 | { | |
304 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD); | |
305 | } | |
306 | ||
307 | bool isOptionWithUnsignedIntegerSelector() const noexcept | |
308 | { | |
309 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); | |
310 | } | |
311 | ||
312 | bool isOptionWithSignedIntegerSelector() const noexcept | |
313 | { | |
314 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD); | |
315 | } | |
316 | ||
317 | bool isVariant() const noexcept | |
318 | { | |
319 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT); | |
320 | } | |
321 | ||
322 | bool isVariantWithoutSelector() const noexcept | |
323 | { | |
324 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); | |
325 | } | |
326 | ||
327 | bool isVariantWithSelector() const noexcept | |
328 | { | |
329 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD); | |
330 | } | |
331 | ||
332 | bool isVariantWithIntegerSelector() const noexcept | |
333 | { | |
334 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD); | |
335 | } | |
336 | ||
337 | bool isVariantWithUnsignedIntegerSelector() const noexcept | |
338 | { | |
339 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); | |
340 | } | |
341 | ||
342 | bool isVariantWithSignedIntegerSelector() const noexcept | |
343 | { | |
344 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD); | |
345 | } | |
346 | ||
347 | CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept; | |
348 | CommonIntegerFieldClass<LibObjT> asInteger() const noexcept; | |
349 | ||
350 | CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping< | |
351 | const bt_field_class_enumeration_unsigned_mapping>> | |
352 | asUnsignedEnumeration() const noexcept; | |
353 | ||
354 | CommonEnumerationFieldClass< | |
355 | LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>> | |
356 | asSignedEnumeration() const noexcept; | |
357 | ||
358 | CommonStructureFieldClass<LibObjT> asStructure() const noexcept; | |
359 | CommonArrayFieldClass<LibObjT> asArray() const noexcept; | |
360 | CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept; | |
361 | CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept; | |
362 | CommonOptionFieldClass<LibObjT> asOption() const noexcept; | |
363 | CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept; | |
364 | CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept; | |
365 | ||
366 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> | |
367 | asOptionWithUnsignedIntegerSelector() const noexcept; | |
368 | ||
369 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> | |
370 | asOptionWithSignedIntegerSelector() const noexcept; | |
371 | ||
372 | CommonVariantFieldClass<LibObjT> asVariant() const noexcept; | |
373 | CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept; | |
374 | ||
375 | CommonVariantWithIntegerSelectorFieldClass< | |
376 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< | |
377 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>> | |
378 | asVariantWithUnsignedIntegerSelector() const noexcept; | |
379 | ||
380 | CommonVariantWithIntegerSelectorFieldClass< | |
381 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< | |
382 | const bt_field_class_variant_with_selector_field_integer_signed_option>> | |
383 | asVariantWithSignedIntegerSelector() const noexcept; | |
384 | ||
385 | template <typename LibValT> | |
386 | void userAttributes(const CommonMapValue<LibValT>& userAttrs) | |
387 | { | |
388 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
389 | ||
390 | bt_field_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr()); | |
391 | } | |
392 | ||
393 | ConstMapValue userAttributes() const noexcept | |
394 | { | |
395 | return ConstMapValue {internal::CommonFieldClassSpec<const bt_field_class>::userAttributes( | |
396 | this->_libObjPtr())}; | |
397 | } | |
398 | ||
399 | UserAttributes userAttributes() noexcept | |
400 | { | |
401 | return UserAttributes { | |
402 | internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->_libObjPtr())}; | |
403 | } | |
404 | ||
405 | Shared shared() const noexcept | |
406 | { | |
407 | return Shared {*this}; | |
408 | } | |
409 | ||
410 | protected: | |
411 | bool _libTypeIs(const bt_field_class_type type) const noexcept | |
412 | { | |
413 | return bt_field_class_type_is(bt_field_class_get_type(this->_libObjPtr()), type); | |
414 | } | |
415 | }; | |
416 | ||
417 | using FieldClass = CommonFieldClass<bt_field_class>; | |
418 | using ConstFieldClass = CommonFieldClass<const bt_field_class>; | |
419 | ||
420 | template <typename LibObjT> | |
421 | class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT> | |
422 | { | |
423 | private: | |
424 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
425 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
426 | ||
427 | public: | |
428 | using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>; | |
429 | ||
430 | explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
431 | _ThisCommonFieldClass {libObjPtr} | |
432 | { | |
433 | BT_ASSERT_DBG(this->isBitArray()); | |
434 | } | |
435 | ||
436 | template <typename OtherLibObjT> | |
437 | CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept : | |
438 | _ThisCommonFieldClass {fc} | |
439 | { | |
440 | } | |
441 | ||
442 | template <typename OtherLibObjT> | |
443 | CommonBitArrayFieldClass<LibObjT>& | |
444 | operator=(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept | |
445 | { | |
446 | _ThisCommonFieldClass::operator=(fc); | |
447 | return *this; | |
448 | } | |
449 | ||
450 | std::uint64_t length() const noexcept | |
451 | { | |
452 | return bt_field_class_bit_array_get_length(this->_libObjPtr()); | |
453 | } | |
454 | ||
455 | Shared shared() const noexcept | |
456 | { | |
457 | return Shared {*this}; | |
458 | } | |
459 | }; | |
460 | ||
461 | using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>; | |
462 | using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>; | |
463 | ||
464 | enum class DisplayBase | |
465 | { | |
466 | BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY, | |
467 | OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL, | |
468 | DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL, | |
469 | HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL, | |
470 | }; | |
471 | ||
472 | template <typename LibObjT> | |
473 | class CommonIntegerFieldClass : public CommonFieldClass<LibObjT> | |
474 | { | |
475 | private: | |
476 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
477 | ||
478 | protected: | |
479 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
480 | using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>; | |
481 | ||
482 | public: | |
483 | using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>; | |
484 | ||
485 | explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
486 | _ThisCommonFieldClass {libObjPtr} | |
487 | { | |
488 | BT_ASSERT_DBG(this->isInteger()); | |
489 | } | |
490 | ||
491 | template <typename OtherLibObjT> | |
492 | CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept : | |
493 | _ThisCommonFieldClass {fc} | |
494 | { | |
495 | } | |
496 | ||
497 | template <typename OtherLibObjT> | |
498 | _ThisCommonIntegerFieldClass& | |
499 | operator=(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept | |
500 | { | |
501 | _ThisCommonFieldClass::operator=(fc); | |
502 | return *this; | |
503 | } | |
504 | ||
505 | void fieldValueRange(const std::uint64_t n) noexcept | |
506 | { | |
507 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
508 | ||
509 | bt_field_class_integer_get_field_value_range(this->_libObjPtr(), n); | |
510 | } | |
511 | ||
512 | std::uint64_t fieldValueRange() const noexcept | |
513 | { | |
514 | return bt_field_class_integer_get_field_value_range(this->_libObjPtr()); | |
515 | } | |
516 | ||
517 | void preferredDisplayBase(const DisplayBase base) noexcept | |
518 | { | |
519 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
520 | ||
521 | bt_field_class_integer_set_preferred_display_base( | |
522 | this->_libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base)); | |
523 | } | |
524 | ||
525 | DisplayBase preferredDisplayBase() const noexcept | |
526 | { | |
527 | return static_cast<DisplayBase>( | |
528 | bt_field_class_integer_get_preferred_display_base(this->_libObjPtr())); | |
529 | } | |
530 | ||
531 | Shared shared() const noexcept | |
532 | { | |
533 | return Shared {*this}; | |
534 | } | |
535 | }; | |
536 | ||
537 | using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>; | |
538 | using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>; | |
539 | ||
540 | namespace internal { | |
541 | ||
542 | template <typename LibObjT> | |
543 | struct ConstEnumerationFieldClassMappingSpec; | |
544 | ||
545 | // Functions specific to unsigned enumeration field class mappings | |
546 | template <> | |
547 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping> | |
548 | final | |
549 | { | |
550 | static const bt_integer_range_set_unsigned * | |
551 | ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept | |
552 | { | |
553 | return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr); | |
554 | } | |
555 | ||
556 | static const char * | |
557 | label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept | |
558 | { | |
559 | return bt_field_class_enumeration_mapping_get_label( | |
560 | bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr)); | |
561 | } | |
562 | }; | |
563 | ||
564 | // Functions specific to signed enumeration field class mappings | |
565 | template <> | |
566 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final | |
567 | { | |
568 | static const bt_integer_range_set_signed * | |
569 | ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept | |
570 | { | |
571 | return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr); | |
572 | } | |
573 | ||
574 | static const char * | |
575 | label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept | |
576 | { | |
577 | return bt_field_class_enumeration_mapping_get_label( | |
578 | bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr)); | |
579 | } | |
580 | }; | |
581 | ||
582 | } // namespace internal | |
583 | ||
584 | template <typename LibObjT> | |
585 | class ConstEnumerationFieldClassMapping final : public internal::BorrowedObj<LibObjT> | |
586 | { | |
587 | private: | |
588 | using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj; | |
589 | using typename internal::BorrowedObj<LibObjT>::_LibObjPtr; | |
590 | using _ThisConstEnumerationFieldClassMapping = ConstEnumerationFieldClassMapping<LibObjT>; | |
591 | ||
592 | public: | |
593 | using RangeSet = typename std::conditional< | |
594 | std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value, | |
595 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; | |
596 | ||
597 | explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept : | |
598 | _ThisBorrowedObj {libObjPtr} | |
599 | { | |
600 | } | |
601 | ||
602 | ConstEnumerationFieldClassMapping( | |
603 | const _ThisConstEnumerationFieldClassMapping& mapping) noexcept : | |
604 | _ThisBorrowedObj {mapping} | |
605 | { | |
606 | } | |
607 | ||
608 | _ThisConstEnumerationFieldClassMapping& | |
609 | operator=(const _ThisConstEnumerationFieldClassMapping& mapping) noexcept | |
610 | { | |
611 | _ThisBorrowedObj::operator=(mapping); | |
612 | return *this; | |
613 | } | |
614 | ||
615 | RangeSet ranges() const noexcept | |
616 | { | |
617 | return RangeSet { | |
618 | internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->_libObjPtr())}; | |
619 | } | |
620 | ||
621 | bpstd::string_view label() const noexcept | |
622 | { | |
623 | return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->_libObjPtr()); | |
624 | } | |
625 | }; | |
626 | ||
627 | using ConstUnsignedEnumerationFieldClassMapping = | |
628 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>; | |
629 | ||
630 | using ConstSignedEnumerationFieldClassMapping = | |
631 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>; | |
632 | ||
633 | namespace internal { | |
634 | ||
635 | template <typename MappingT> | |
636 | struct CommonEnumerationFieldClassSpec; | |
637 | ||
638 | // Functions specific to unsigned enumeration field classes | |
639 | template <> | |
640 | struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final | |
641 | { | |
642 | static const bt_field_class_enumeration_unsigned_mapping * | |
643 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
644 | { | |
645 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index); | |
646 | } | |
647 | ||
648 | static const bt_field_class_enumeration_unsigned_mapping * | |
649 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept | |
650 | { | |
651 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label); | |
652 | } | |
653 | }; | |
654 | ||
655 | // Functions specific to signed enumeration field classes | |
656 | template <> | |
657 | struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final | |
658 | { | |
659 | static const bt_field_class_enumeration_signed_mapping * | |
660 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
661 | { | |
662 | return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index); | |
663 | } | |
664 | ||
665 | static const bt_field_class_enumeration_signed_mapping * | |
666 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept | |
667 | { | |
668 | return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label); | |
669 | } | |
670 | }; | |
671 | ||
672 | } // namespace internal | |
673 | ||
674 | template <typename LibObjT, typename MappingT> | |
675 | class CommonEnumerationFieldClass final : public CommonIntegerFieldClass<LibObjT> | |
676 | { | |
677 | private: | |
678 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
679 | using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass; | |
680 | using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>; | |
681 | ||
682 | public: | |
683 | using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>; | |
684 | using Mapping = MappingT; | |
685 | ||
686 | explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
687 | _ThisCommonIntegerFieldClass {libObjPtr} | |
688 | { | |
689 | BT_ASSERT_DBG(this->isEnumeration()); | |
690 | } | |
691 | ||
692 | template <typename OtherLibObjT> | |
693 | CommonEnumerationFieldClass( | |
694 | const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept : | |
695 | _ThisCommonIntegerFieldClass {fc} | |
696 | { | |
697 | } | |
698 | ||
699 | template <typename OtherLibObjT> | |
700 | _ThisCommonEnumerationFieldClass& | |
701 | operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept | |
702 | { | |
703 | _ThisCommonIntegerFieldClass::operator=(fc); | |
704 | return *this; | |
705 | } | |
706 | ||
707 | std::uint64_t size() const noexcept | |
708 | { | |
709 | return bt_field_class_enumeration_get_mapping_count(this->_libObjPtr()); | |
710 | } | |
711 | ||
712 | Mapping operator[](const std::uint64_t index) const noexcept | |
713 | { | |
714 | return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex( | |
715 | this->_libObjPtr(), index)}; | |
716 | } | |
717 | ||
718 | nonstd::optional<Mapping> operator[](const char * const label) const noexcept | |
719 | { | |
720 | const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel( | |
721 | this->_libObjPtr(), label); | |
722 | ||
723 | if (libObjPtr) { | |
724 | return Mapping {libObjPtr}; | |
725 | } | |
726 | ||
727 | return nonstd::nullopt; | |
728 | } | |
729 | ||
730 | nonstd::optional<Mapping> operator[](const std::string& label) const noexcept | |
731 | { | |
732 | return (*this)[label.data()]; | |
733 | } | |
734 | ||
735 | Shared shared() const noexcept | |
736 | { | |
737 | return Shared {*this}; | |
738 | } | |
739 | }; | |
740 | ||
741 | using UnsignedEnumerationFieldClass = | |
742 | CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
743 | ||
744 | using ConstUnsignedEnumerationFieldClass = | |
745 | CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; | |
746 | ||
747 | using SignedEnumerationFieldClass = | |
748 | CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
749 | ||
750 | using ConstSignedEnumerationFieldClass = | |
751 | CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>; | |
752 | ||
753 | namespace internal { | |
754 | ||
755 | template <typename LibObjT> | |
756 | struct CommonStructureFieldClassMemberSpec; | |
757 | ||
758 | // Functions specific to mutable structure field class members | |
759 | template <> | |
760 | struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final | |
761 | { | |
762 | static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept | |
763 | { | |
764 | return bt_field_class_structure_member_borrow_field_class(libObjPtr); | |
765 | } | |
766 | }; | |
767 | ||
768 | // Functions specific to constant structure field class members | |
769 | template <> | |
770 | struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final | |
771 | { | |
772 | static const bt_field_class * | |
773 | fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept | |
774 | { | |
775 | return bt_field_class_structure_member_borrow_field_class_const(libObjPtr); | |
776 | } | |
777 | }; | |
778 | ||
779 | } // namespace internal | |
780 | ||
781 | template <typename LibObjT> | |
782 | class CommonStructureFieldClassMember final : public internal::BorrowedObj<LibObjT> | |
783 | { | |
784 | private: | |
785 | using typename internal::BorrowedObj<LibObjT>::_LibObjPtr; | |
786 | using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj; | |
787 | ||
788 | using _FieldClass = | |
789 | typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type; | |
790 | ||
791 | public: | |
792 | explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept : | |
793 | _ThisBorrowedObj {libObjPtr} | |
794 | { | |
795 | } | |
796 | ||
797 | template <typename OtherLibObjT> | |
798 | CommonStructureFieldClassMember( | |
799 | const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept : | |
800 | _ThisBorrowedObj {fc} | |
801 | { | |
802 | } | |
803 | ||
804 | template <typename OtherLibObjT> | |
805 | CommonStructureFieldClassMember<LibObjT>& | |
806 | operator=(const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept | |
807 | { | |
808 | _ThisBorrowedObj::operator=(fc); | |
809 | return *this; | |
810 | } | |
811 | ||
812 | bpstd::string_view name() const noexcept | |
813 | { | |
814 | return bt_field_class_structure_member_get_name(this->_libObjPtr()); | |
815 | } | |
816 | ||
817 | ConstFieldClass fieldClass() const noexcept | |
818 | { | |
819 | return ConstFieldClass {internal::CommonStructureFieldClassMemberSpec< | |
820 | const bt_field_class_structure_member>::fieldClass(this->_libObjPtr())}; | |
821 | } | |
822 | ||
823 | _FieldClass fieldClass() noexcept | |
824 | { | |
825 | return _FieldClass { | |
826 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->_libObjPtr())}; | |
827 | } | |
828 | }; | |
829 | ||
830 | using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>; | |
831 | ||
832 | using ConstStructureFieldClassMember = | |
833 | CommonStructureFieldClassMember<const bt_field_class_structure_member>; | |
834 | ||
835 | namespace internal { | |
836 | ||
837 | template <typename LibObjT> | |
838 | struct CommonStructureFieldClassSpec; | |
839 | ||
840 | // Functions specific to mutable structure field classes | |
841 | template <> | |
842 | struct CommonStructureFieldClassSpec<bt_field_class> final | |
843 | { | |
844 | static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr, | |
845 | const std::uint64_t index) noexcept | |
846 | { | |
847 | return bt_field_class_structure_borrow_member_by_index(libObjPtr, index); | |
848 | } | |
849 | ||
850 | static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr, | |
851 | const char * const name) noexcept | |
852 | { | |
853 | return bt_field_class_structure_borrow_member_by_name(libObjPtr, name); | |
854 | } | |
855 | }; | |
856 | ||
857 | // Functions specific to constant structure field classes | |
858 | template <> | |
859 | struct CommonStructureFieldClassSpec<const bt_field_class> final | |
860 | { | |
861 | static const bt_field_class_structure_member * | |
862 | memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
863 | { | |
864 | return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index); | |
865 | } | |
866 | ||
867 | static const bt_field_class_structure_member * | |
868 | memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
869 | { | |
870 | return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name); | |
871 | } | |
872 | }; | |
873 | ||
874 | } // namespace internal | |
875 | ||
876 | template <typename LibObjT> | |
877 | class CommonStructureFieldClass final : public CommonFieldClass<LibObjT> | |
878 | { | |
879 | private: | |
880 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
881 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
882 | ||
883 | public: | |
884 | using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>; | |
885 | ||
886 | using Member = | |
887 | typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember, | |
888 | StructureFieldClassMember>::type; | |
889 | ||
890 | explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
891 | _ThisCommonFieldClass {libObjPtr} | |
892 | { | |
893 | BT_ASSERT_DBG(this->isStructure()); | |
894 | } | |
895 | ||
896 | template <typename OtherLibObjT> | |
897 | CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept : | |
898 | _ThisCommonFieldClass {fc} | |
899 | { | |
900 | } | |
901 | ||
902 | template <typename OtherLibObjT> | |
903 | CommonStructureFieldClass<LibObjT>& | |
904 | operator=(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept | |
905 | { | |
906 | _ThisCommonFieldClass::operator=(fc); | |
907 | return *this; | |
908 | } | |
909 | ||
910 | void appendMember(const char * const name, const FieldClass& fc) | |
911 | { | |
912 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
913 | ||
914 | const auto status = | |
915 | bt_field_class_structure_append_member(this->_libObjPtr(), name, fc._libObjPtr()); | |
916 | ||
917 | if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { | |
918 | throw LibMemoryError {}; | |
919 | } | |
920 | } | |
921 | ||
922 | void appendMember(const std::string& name, const FieldClass& fc) | |
923 | { | |
924 | this->appendMember(name.data(), fc); | |
925 | } | |
926 | ||
927 | std::uint64_t size() const noexcept | |
928 | { | |
929 | return bt_field_class_structure_get_member_count(this->_libObjPtr()); | |
930 | } | |
931 | ||
932 | ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept | |
933 | { | |
934 | return ConstStructureFieldClassMember { | |
935 | internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByIndex( | |
936 | this->_libObjPtr(), index)}; | |
937 | } | |
938 | ||
939 | Member operator[](const std::uint64_t index) noexcept | |
940 | { | |
941 | return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex( | |
942 | this->_libObjPtr(), index)}; | |
943 | } | |
944 | ||
945 | nonstd::optional<ConstStructureFieldClassMember> | |
946 | operator[](const char * const name) const noexcept | |
947 | { | |
948 | const auto libObjPtr = | |
949 | internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByName( | |
950 | this->_libObjPtr(), name); | |
951 | ||
952 | if (libObjPtr) { | |
953 | return ConstStructureFieldClassMember {libObjPtr}; | |
954 | } | |
955 | ||
956 | return nonstd::nullopt; | |
957 | } | |
958 | ||
959 | nonstd::optional<ConstStructureFieldClassMember> | |
960 | operator[](const std::string& name) const noexcept | |
961 | { | |
962 | return (*this)[name.data()]; | |
963 | } | |
964 | ||
965 | nonstd::optional<Member> operator[](const char * const name) noexcept | |
966 | { | |
967 | const auto libObjPtr = internal::CommonStructureFieldClassSpec<LibObjT>::memberByName( | |
968 | this->_libObjPtr(), name); | |
969 | ||
970 | if (libObjPtr) { | |
971 | return Member {libObjPtr}; | |
972 | } | |
973 | ||
974 | return nonstd::nullopt; | |
975 | } | |
976 | ||
977 | nonstd::optional<Member> operator[](const std::string& name) noexcept | |
978 | { | |
979 | return (*this)[name.data()]; | |
980 | } | |
981 | ||
982 | Shared shared() const noexcept | |
983 | { | |
984 | return Shared {*this}; | |
985 | } | |
986 | }; | |
987 | ||
988 | using StructureFieldClass = CommonStructureFieldClass<bt_field_class>; | |
989 | using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>; | |
990 | ||
991 | namespace internal { | |
992 | ||
993 | template <typename LibObjT> | |
994 | struct CommonArrayFieldClassSpec; | |
995 | ||
996 | // Functions specific to mutable array field classes | |
997 | template <> | |
998 | struct CommonArrayFieldClassSpec<bt_field_class> final | |
999 | { | |
1000 | static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept | |
1001 | { | |
1002 | return bt_field_class_array_borrow_element_field_class(libObjPtr); | |
1003 | } | |
1004 | }; | |
1005 | ||
1006 | // Functions specific to constant array field classes | |
1007 | template <> | |
1008 | struct CommonArrayFieldClassSpec<const bt_field_class> final | |
1009 | { | |
1010 | static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept | |
1011 | { | |
1012 | return bt_field_class_array_borrow_element_field_class_const(libObjPtr); | |
1013 | } | |
1014 | }; | |
1015 | ||
1016 | } // namespace internal | |
1017 | ||
1018 | template <typename LibObjT> | |
1019 | class CommonArrayFieldClass : public CommonFieldClass<LibObjT> | |
1020 | { | |
1021 | private: | |
1022 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
1023 | ||
1024 | using _FieldClass = | |
1025 | typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type; | |
1026 | ||
1027 | protected: | |
1028 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1029 | using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>; | |
1030 | ||
1031 | public: | |
1032 | using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>; | |
1033 | ||
1034 | explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1035 | _ThisCommonFieldClass {libObjPtr} | |
1036 | { | |
1037 | BT_ASSERT_DBG(this->isArray()); | |
1038 | } | |
1039 | ||
1040 | template <typename OtherLibObjT> | |
1041 | CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept : | |
1042 | _ThisCommonFieldClass {fc} | |
1043 | { | |
1044 | } | |
1045 | ||
1046 | template <typename OtherLibObjT> | |
1047 | _ThisCommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept | |
1048 | { | |
1049 | _ThisCommonFieldClass::operator=(fc); | |
1050 | return *this; | |
1051 | } | |
1052 | ||
1053 | ConstFieldClass elementFieldClass() const noexcept | |
1054 | { | |
1055 | return ConstFieldClass { | |
1056 | internal::CommonArrayFieldClassSpec<const bt_field_class>::elementFieldClass( | |
1057 | this->_libObjPtr())}; | |
1058 | } | |
1059 | ||
1060 | _FieldClass elementFieldClass() noexcept | |
1061 | { | |
1062 | return _FieldClass { | |
1063 | internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->_libObjPtr())}; | |
1064 | } | |
1065 | ||
1066 | Shared shared() const noexcept | |
1067 | { | |
1068 | return Shared {*this}; | |
1069 | } | |
1070 | }; | |
1071 | ||
1072 | using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>; | |
1073 | using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>; | |
1074 | ||
1075 | template <typename LibObjT> | |
1076 | class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1077 | { | |
1078 | private: | |
1079 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
1080 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1081 | ||
1082 | public: | |
1083 | using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>; | |
1084 | ||
1085 | explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1086 | _ThisCommonArrayFieldClass {libObjPtr} | |
1087 | { | |
1088 | BT_ASSERT_DBG(this->isStaticArray()); | |
1089 | } | |
1090 | ||
1091 | template <typename OtherLibObjT> | |
1092 | CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept : | |
1093 | _ThisCommonArrayFieldClass {fc} | |
1094 | { | |
1095 | } | |
1096 | ||
1097 | template <typename OtherLibObjT> | |
1098 | CommonStaticArrayFieldClass<LibObjT>& | |
1099 | operator=(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept | |
1100 | { | |
1101 | _ThisCommonArrayFieldClass::operator=(fc); | |
1102 | return *this; | |
1103 | } | |
1104 | ||
1105 | std::uint64_t length() const noexcept | |
1106 | { | |
1107 | return bt_field_class_array_static_get_length(this->_libObjPtr()); | |
1108 | } | |
1109 | ||
1110 | Shared shared() const noexcept | |
1111 | { | |
1112 | return Shared {*this}; | |
1113 | } | |
1114 | }; | |
1115 | ||
1116 | using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>; | |
1117 | using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>; | |
1118 | ||
1119 | template <typename LibObjT> | |
1120 | class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT> | |
1121 | { | |
1122 | private: | |
1123 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; | |
1124 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1125 | ||
1126 | public: | |
1127 | using Shared = | |
1128 | internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>; | |
1129 | ||
1130 | explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1131 | _ThisCommonArrayFieldClass {libObjPtr} | |
1132 | { | |
1133 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); | |
1134 | } | |
1135 | ||
1136 | template <typename OtherLibObjT> | |
1137 | CommonDynamicArrayWithLengthFieldClass( | |
1138 | const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept : | |
1139 | _ThisCommonArrayFieldClass {fc} | |
1140 | { | |
1141 | } | |
1142 | ||
1143 | template <typename OtherLibObjT> | |
1144 | CommonDynamicArrayWithLengthFieldClass<LibObjT>& | |
1145 | operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept | |
1146 | { | |
1147 | _ThisCommonArrayFieldClass::operator=(fc); | |
1148 | return *this; | |
1149 | } | |
1150 | ||
1151 | ConstFieldPath lengthFieldPath() const noexcept | |
1152 | { | |
1153 | return ConstFieldPath { | |
1154 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( | |
1155 | this->_libObjPtr())}; | |
1156 | } | |
1157 | ||
1158 | Shared shared() const noexcept | |
1159 | { | |
1160 | return Shared {*this}; | |
1161 | } | |
1162 | }; | |
1163 | ||
1164 | using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>; | |
1165 | ||
1166 | using ConstDynamicArrayWithLengthFieldClass = | |
1167 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class>; | |
1168 | ||
1169 | namespace internal { | |
1170 | ||
1171 | template <typename LibObjT> | |
1172 | struct CommonOptionFieldClassSpec; | |
1173 | ||
1174 | // Functions specific to mutable option field classes | |
1175 | template <> | |
1176 | struct CommonOptionFieldClassSpec<bt_field_class> final | |
1177 | { | |
1178 | static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept | |
1179 | { | |
1180 | return bt_field_class_option_borrow_field_class(libObjPtr); | |
1181 | } | |
1182 | }; | |
1183 | ||
1184 | // Functions specific to constant option field classes | |
1185 | template <> | |
1186 | struct CommonOptionFieldClassSpec<const bt_field_class> final | |
1187 | { | |
1188 | static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept | |
1189 | { | |
1190 | return bt_field_class_option_borrow_field_class_const(libObjPtr); | |
1191 | } | |
1192 | }; | |
1193 | ||
1194 | } // namespace internal | |
1195 | ||
1196 | template <typename LibObjT> | |
1197 | class CommonOptionFieldClass : public CommonFieldClass<LibObjT> | |
1198 | { | |
1199 | private: | |
1200 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
1201 | ||
1202 | using _FieldClass = | |
1203 | typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type; | |
1204 | ||
1205 | protected: | |
1206 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1207 | using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>; | |
1208 | ||
1209 | public: | |
1210 | using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>; | |
1211 | ||
1212 | explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1213 | _ThisCommonFieldClass {libObjPtr} | |
1214 | { | |
1215 | BT_ASSERT_DBG(this->isOption()); | |
1216 | } | |
1217 | ||
1218 | template <typename OtherLibObjT> | |
1219 | CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept : | |
1220 | _ThisCommonFieldClass {fc} | |
1221 | { | |
1222 | } | |
1223 | ||
1224 | template <typename OtherLibObjT> | |
1225 | _ThisCommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept | |
1226 | { | |
1227 | _ThisCommonFieldClass::operator=(fc); | |
1228 | return *this; | |
1229 | } | |
1230 | ||
1231 | ConstFieldClass fieldClass() const noexcept | |
1232 | { | |
1233 | return ConstFieldClass { | |
1234 | internal::CommonOptionFieldClassSpec<const bt_field_class>::fieldClass( | |
1235 | this->_libObjPtr())}; | |
1236 | } | |
1237 | ||
1238 | _FieldClass fieldClass() noexcept | |
1239 | { | |
1240 | return _FieldClass { | |
1241 | internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->_libObjPtr())}; | |
1242 | } | |
1243 | ||
1244 | Shared shared() const noexcept | |
1245 | { | |
1246 | return Shared {*this}; | |
1247 | } | |
1248 | }; | |
1249 | ||
1250 | using OptionFieldClass = CommonOptionFieldClass<bt_field_class>; | |
1251 | using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>; | |
1252 | ||
1253 | template <typename LibObjT> | |
1254 | class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT> | |
1255 | { | |
1256 | private: | |
1257 | using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass; | |
1258 | ||
1259 | protected: | |
1260 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1261 | using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>; | |
1262 | ||
1263 | public: | |
1264 | using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>; | |
1265 | ||
1266 | explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1267 | _ThisCommonOptionFieldClass {libObjPtr} | |
1268 | { | |
1269 | BT_ASSERT_DBG(this->isOptionWithSelector()); | |
1270 | } | |
1271 | ||
1272 | template <typename OtherLibObjT> | |
1273 | CommonOptionWithSelectorFieldClass( | |
1274 | const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept : | |
1275 | _ThisCommonOptionFieldClass {fc} | |
1276 | { | |
1277 | } | |
1278 | ||
1279 | template <typename OtherLibObjT> | |
1280 | _ThisCommonOptionWithSelectorFieldClass& | |
1281 | operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept | |
1282 | { | |
1283 | _ThisCommonOptionFieldClass::operator=(fc); | |
1284 | return *this; | |
1285 | } | |
1286 | ||
1287 | ConstFieldPath selectorFieldPath() const noexcept | |
1288 | { | |
1289 | return ConstFieldPath { | |
1290 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( | |
1291 | this->_libObjPtr())}; | |
1292 | } | |
1293 | ||
1294 | Shared shared() const noexcept | |
1295 | { | |
1296 | return Shared {*this}; | |
1297 | } | |
1298 | }; | |
1299 | ||
1300 | using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>; | |
1301 | using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>; | |
1302 | ||
1303 | template <typename LibObjT> | |
1304 | class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1305 | { | |
1306 | private: | |
1307 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1308 | ||
1309 | using typename CommonOptionWithSelectorFieldClass< | |
1310 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1311 | ||
1312 | public: | |
1313 | using Shared = | |
1314 | internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>; | |
1315 | ||
1316 | explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1317 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} | |
1318 | { | |
1319 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); | |
1320 | } | |
1321 | ||
1322 | template <typename OtherLibObjT> | |
1323 | CommonOptionWithBoolSelectorFieldClass( | |
1324 | const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept : | |
1325 | _ThisCommonOptionWithSelectorFieldClass {fc} | |
1326 | { | |
1327 | } | |
1328 | ||
1329 | template <typename OtherLibObjT> | |
1330 | CommonOptionWithBoolSelectorFieldClass<LibObjT>& | |
1331 | operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept | |
1332 | { | |
1333 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1334 | return *this; | |
1335 | } | |
1336 | ||
1337 | bool selectorIsReversed() const noexcept | |
1338 | { | |
1339 | return bt_field_class_option_with_selector_field_bool_selector_is_reversed( | |
1340 | this->_libObjPtr()); | |
1341 | } | |
1342 | ||
1343 | Shared shared() const noexcept | |
1344 | { | |
1345 | return Shared {*this}; | |
1346 | } | |
1347 | }; | |
1348 | ||
1349 | using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>; | |
1350 | ||
1351 | using ConstOptionWithBoolSelectorFieldClass = | |
1352 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class>; | |
1353 | ||
1354 | namespace internal { | |
1355 | ||
1356 | template <typename RangeSetT> | |
1357 | struct CommonOptionWithIntegerSelectorFieldClassSpec; | |
1358 | ||
1359 | // Functions specific to option field classes with unsigned integer ranges | |
1360 | template <> | |
1361 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final | |
1362 | { | |
1363 | static const bt_integer_range_set_unsigned * | |
1364 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1365 | { | |
1366 | return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( | |
1367 | libObjPtr); | |
1368 | } | |
1369 | }; | |
1370 | ||
1371 | // Functions specific to option field classes with signed ranges | |
1372 | template <> | |
1373 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final | |
1374 | { | |
1375 | static const bt_integer_range_set_signed * | |
1376 | ranges(const bt_field_class * const libObjPtr) noexcept | |
1377 | { | |
1378 | return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( | |
1379 | libObjPtr); | |
1380 | } | |
1381 | }; | |
1382 | ||
1383 | } // namespace internal | |
1384 | ||
1385 | template <typename LibObjT, typename RangeSetT> | |
1386 | class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> | |
1387 | { | |
1388 | private: | |
1389 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1390 | ||
1391 | using typename CommonOptionWithSelectorFieldClass< | |
1392 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; | |
1393 | ||
1394 | using _ThisCommonOptionWithIntegerSelectorFieldClass = | |
1395 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>; | |
1396 | ||
1397 | public: | |
1398 | using Shared = | |
1399 | internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>; | |
1400 | ||
1401 | using RangeSet = RangeSetT; | |
1402 | ||
1403 | explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1404 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} | |
1405 | { | |
1406 | BT_ASSERT_DBG(this->isOptionWithIntegerSelector()); | |
1407 | } | |
1408 | ||
1409 | template <typename OtherLibObjT> | |
1410 | CommonOptionWithIntegerSelectorFieldClass( | |
1411 | const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept : | |
1412 | _ThisCommonOptionWithSelectorFieldClass {fc} | |
1413 | { | |
1414 | } | |
1415 | ||
1416 | template <typename OtherLibObjT> | |
1417 | _ThisCommonOptionWithIntegerSelectorFieldClass& | |
1418 | operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept | |
1419 | { | |
1420 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); | |
1421 | return *this; | |
1422 | } | |
1423 | ||
1424 | RangeSet ranges() const noexcept | |
1425 | { | |
1426 | return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges( | |
1427 | this->_libObjPtr())}; | |
1428 | } | |
1429 | ||
1430 | Shared shared() const noexcept | |
1431 | { | |
1432 | return Shared {*this}; | |
1433 | } | |
1434 | }; | |
1435 | ||
1436 | using OptionWithUnsignedIntegerSelectorFieldClass = | |
1437 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1438 | ||
1439 | using ConstOptionWithUnsignedIntegerSelectorFieldClass = | |
1440 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>; | |
1441 | ||
1442 | using OptionWithSignedIntegerSelectorFieldClass = | |
1443 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>; | |
1444 | ||
1445 | using ConstOptionWithSignedIntegerSelectorFieldClass = | |
1446 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>; | |
1447 | ||
1448 | namespace internal { | |
1449 | ||
1450 | template <typename LibObjT> | |
1451 | struct CommonVariantFieldClassOptionSpec; | |
1452 | ||
1453 | // Functions specific to mutable variant field class options | |
1454 | template <> | |
1455 | struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final | |
1456 | { | |
1457 | static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept | |
1458 | { | |
1459 | return bt_field_class_variant_option_borrow_field_class(libObjPtr); | |
1460 | } | |
1461 | }; | |
1462 | ||
1463 | // Functions specific to constant variant field class options | |
1464 | template <> | |
1465 | struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final | |
1466 | { | |
1467 | static const bt_field_class * | |
1468 | fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept | |
1469 | { | |
1470 | return bt_field_class_variant_option_borrow_field_class_const(libObjPtr); | |
1471 | } | |
1472 | }; | |
1473 | ||
1474 | } // namespace internal | |
1475 | ||
1476 | template <typename LibObjT> | |
1477 | class CommonVariantFieldClassOption : public internal::BorrowedObj<LibObjT> | |
1478 | { | |
1479 | private: | |
1480 | using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj; | |
1481 | using typename internal::BorrowedObj<LibObjT>::_LibObjPtr; | |
1482 | ||
1483 | using _FieldClass = | |
1484 | typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type; | |
1485 | ||
1486 | public: | |
1487 | explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept : | |
1488 | _ThisBorrowedObj {libObjPtr} | |
1489 | { | |
1490 | } | |
1491 | ||
1492 | template <typename OtherLibObjT> | |
1493 | CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept : | |
1494 | _ThisBorrowedObj {fc} | |
1495 | { | |
1496 | } | |
1497 | ||
1498 | template <typename OtherLibObjT> | |
1499 | CommonVariantFieldClassOption<LibObjT>& | |
1500 | operator=(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept | |
1501 | { | |
1502 | _ThisBorrowedObj::operator=(fc); | |
1503 | return *this; | |
1504 | } | |
1505 | ||
1506 | bpstd::string_view name() const noexcept | |
1507 | { | |
1508 | return bt_field_class_variant_option_get_name(this->_libObjPtr()); | |
1509 | } | |
1510 | ||
1511 | ConstFieldClass fieldClass() const noexcept | |
1512 | { | |
1513 | return ConstFieldClass {internal::CommonVariantFieldClassOptionSpec< | |
1514 | const bt_field_class_variant_option>::fieldClass(this->_libObjPtr())}; | |
1515 | } | |
1516 | ||
1517 | _FieldClass fieldClass() noexcept | |
1518 | { | |
1519 | return _FieldClass { | |
1520 | internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->_libObjPtr())}; | |
1521 | } | |
1522 | }; | |
1523 | ||
1524 | using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>; | |
1525 | ||
1526 | using ConstVariantFieldClassOption = | |
1527 | CommonVariantFieldClassOption<const bt_field_class_variant_option>; | |
1528 | ||
1529 | namespace internal { | |
1530 | ||
1531 | template <typename LibObjT> | |
1532 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; | |
1533 | ||
1534 | // Functions specific to variant field class options with unsigned integer selector | |
1535 | template <> | |
1536 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1537 | const bt_field_class_variant_with_selector_field_integer_unsigned_option> | |
1538 | final | |
1539 | { | |
1540 | static const bt_integer_range_set_unsigned * | |
1541 | ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1542 | * const libObjPtr) noexcept | |
1543 | { | |
1544 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( | |
1545 | libObjPtr); | |
1546 | } | |
1547 | ||
1548 | static const bt_field_class_variant_option * | |
1549 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option | |
1550 | * const libObjPtr) noexcept | |
1551 | { | |
1552 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const( | |
1553 | libObjPtr); | |
1554 | } | |
1555 | }; | |
1556 | ||
1557 | // Functions specific to variant field class options with signed integer selector | |
1558 | template <> | |
1559 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< | |
1560 | const bt_field_class_variant_with_selector_field_integer_signed_option> | |
1561 | final | |
1562 | { | |
1563 | static const bt_integer_range_set_signed * | |
1564 | ranges(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1565 | * const libObjPtr) noexcept | |
1566 | { | |
1567 | return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( | |
1568 | libObjPtr); | |
1569 | } | |
1570 | ||
1571 | static const bt_field_class_variant_option * | |
1572 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option | |
1573 | * const libObjPtr) noexcept | |
1574 | { | |
1575 | return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const( | |
1576 | libObjPtr); | |
1577 | } | |
1578 | }; | |
1579 | ||
1580 | } // namespace internal | |
1581 | ||
1582 | template <typename LibObjT> | |
1583 | class ConstVariantWithIntegerSelectorFieldClassOption : public internal::BorrowedObj<LibObjT> | |
1584 | { | |
1585 | private: | |
1586 | using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj; | |
1587 | using typename internal::BorrowedObj<LibObjT>::_LibObjPtr; | |
1588 | using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>; | |
1589 | ||
1590 | public: | |
1591 | using RangeSet = typename std::conditional< | |
1592 | std::is_same< | |
1593 | LibObjT, | |
1594 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value, | |
1595 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; | |
1596 | ||
1597 | explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept : | |
1598 | _ThisBorrowedObj {libObjPtr} | |
1599 | { | |
1600 | } | |
1601 | ||
1602 | template <typename OtherLibObjT> | |
1603 | ConstVariantWithIntegerSelectorFieldClassOption( | |
1604 | const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept : | |
1605 | _ThisBorrowedObj {fc} | |
1606 | { | |
1607 | } | |
1608 | ||
1609 | template <typename OtherLibObjT> | |
1610 | ConstVariantWithIntegerSelectorFieldClassOption<LibObjT>& | |
1611 | operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept | |
1612 | { | |
1613 | _ThisBorrowedObj::operator=(fc); | |
1614 | return *this; | |
1615 | } | |
1616 | ||
1617 | ConstVariantFieldClassOption asBaseOption() const noexcept | |
1618 | { | |
1619 | return ConstVariantFieldClassOption {_Spec::asBaseOption(this->_libObjPtr())}; | |
1620 | } | |
1621 | ||
1622 | bpstd::string_view name() const noexcept | |
1623 | { | |
1624 | return this->asBaseOption().name(); | |
1625 | } | |
1626 | ||
1627 | ConstFieldClass fieldClass() const noexcept | |
1628 | { | |
1629 | return this->asBaseOption().fieldClass(); | |
1630 | } | |
1631 | ||
1632 | RangeSet ranges() const noexcept | |
1633 | { | |
1634 | return RangeSet {_Spec::ranges(this->_libObjPtr())}; | |
1635 | } | |
1636 | }; | |
1637 | ||
1638 | using ConstVariantWithUnsignedIntegerSelectorFieldClassOption = | |
1639 | ConstVariantWithIntegerSelectorFieldClassOption< | |
1640 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>; | |
1641 | ||
1642 | using ConstVariantWithSignedIntegerSelectorFieldClassOption = | |
1643 | ConstVariantWithIntegerSelectorFieldClassOption< | |
1644 | const bt_field_class_variant_with_selector_field_integer_signed_option>; | |
1645 | ||
1646 | namespace internal { | |
1647 | ||
1648 | template <typename LibObjT> | |
1649 | struct CommonVariantFieldClassSpec; | |
1650 | ||
1651 | // Functions specific to mutable variant field classes | |
1652 | template <> | |
1653 | struct CommonVariantFieldClassSpec<bt_field_class> final | |
1654 | { | |
1655 | static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr, | |
1656 | const std::uint64_t index) noexcept | |
1657 | { | |
1658 | return bt_field_class_variant_borrow_option_by_index(libObjPtr, index); | |
1659 | } | |
1660 | ||
1661 | static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr, | |
1662 | const char * const name) noexcept | |
1663 | { | |
1664 | return bt_field_class_variant_borrow_option_by_name(libObjPtr, name); | |
1665 | } | |
1666 | }; | |
1667 | ||
1668 | // Functions specific to constant variant field classes | |
1669 | template <> | |
1670 | struct CommonVariantFieldClassSpec<const bt_field_class> final | |
1671 | { | |
1672 | static const bt_field_class_variant_option * | |
1673 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
1674 | { | |
1675 | return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index); | |
1676 | } | |
1677 | ||
1678 | static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr, | |
1679 | const char * const name) noexcept | |
1680 | { | |
1681 | return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name); | |
1682 | } | |
1683 | }; | |
1684 | ||
1685 | } // namespace internal | |
1686 | ||
1687 | template <typename LibObjT> | |
1688 | class CommonVariantFieldClass : public CommonFieldClass<LibObjT> | |
1689 | { | |
1690 | private: | |
1691 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; | |
1692 | ||
1693 | protected: | |
1694 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1695 | using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>; | |
1696 | ||
1697 | public: | |
1698 | using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>; | |
1699 | ||
1700 | using Option = | |
1701 | typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption, | |
1702 | VariantFieldClassOption>::type; | |
1703 | ||
1704 | explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1705 | _ThisCommonFieldClass {libObjPtr} | |
1706 | { | |
1707 | BT_ASSERT_DBG(this->isVariant()); | |
1708 | } | |
1709 | ||
1710 | template <typename OtherLibObjT> | |
1711 | CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept : | |
1712 | _ThisCommonFieldClass {fc} | |
1713 | { | |
1714 | } | |
1715 | ||
1716 | template <typename OtherLibObjT> | |
1717 | _ThisCommonVariantFieldClass& | |
1718 | operator=(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept | |
1719 | { | |
1720 | _ThisCommonFieldClass::operator=(fc); | |
1721 | return *this; | |
1722 | } | |
1723 | ||
1724 | std::uint64_t size() const noexcept | |
1725 | { | |
1726 | return bt_field_class_variant_get_option_count(this->_libObjPtr()); | |
1727 | } | |
1728 | ||
1729 | ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept | |
1730 | { | |
1731 | return ConstVariantFieldClassOption { | |
1732 | internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByIndex( | |
1733 | this->_libObjPtr(), index)}; | |
1734 | } | |
1735 | ||
1736 | Option operator[](const std::uint64_t index) noexcept | |
1737 | { | |
1738 | return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex( | |
1739 | this->_libObjPtr(), index)}; | |
1740 | } | |
1741 | ||
1742 | nonstd::optional<ConstVariantFieldClassOption> | |
1743 | operator[](const char * const name) const noexcept | |
1744 | { | |
1745 | const auto libObjPtr = | |
1746 | internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByName( | |
1747 | this->_libObjPtr(), name); | |
1748 | ||
1749 | if (libObjPtr) { | |
1750 | return ConstVariantFieldClassOption {libObjPtr}; | |
1751 | } | |
1752 | ||
1753 | return nonstd::nullopt; | |
1754 | } | |
1755 | ||
1756 | nonstd::optional<ConstVariantFieldClassOption> | |
1757 | operator[](const std::string& name) const noexcept | |
1758 | { | |
1759 | return (*this)[name.data()]; | |
1760 | } | |
1761 | ||
1762 | nonstd::optional<Option> operator[](const char * const name) noexcept | |
1763 | { | |
1764 | const auto libObjPtr = | |
1765 | internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->_libObjPtr(), name); | |
1766 | ||
1767 | if (libObjPtr) { | |
1768 | return Option {libObjPtr}; | |
1769 | } | |
1770 | ||
1771 | return nonstd::nullopt; | |
1772 | } | |
1773 | ||
1774 | nonstd::optional<Option> operator[](const std::string& name) noexcept | |
1775 | { | |
1776 | return (*this)[name.data()]; | |
1777 | } | |
1778 | ||
1779 | Shared shared() const noexcept | |
1780 | { | |
1781 | return Shared {*this}; | |
1782 | } | |
1783 | }; | |
1784 | ||
1785 | using VariantFieldClass = CommonVariantFieldClass<bt_field_class>; | |
1786 | using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>; | |
1787 | ||
1788 | template <typename LibObjT> | |
1789 | class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
1790 | { | |
1791 | private: | |
1792 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
1793 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1794 | ||
1795 | public: | |
1796 | using Shared = | |
1797 | internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>; | |
1798 | ||
1799 | explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1800 | _ThisCommonVariantFieldClass {libObjPtr} | |
1801 | { | |
1802 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); | |
1803 | } | |
1804 | ||
1805 | template <typename OtherLibObjT> | |
1806 | CommonVariantWithoutSelectorFieldClass( | |
1807 | const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept : | |
1808 | _ThisCommonVariantFieldClass {fc} | |
1809 | { | |
1810 | } | |
1811 | ||
1812 | template <typename OtherLibObjT> | |
1813 | CommonVariantWithoutSelectorFieldClass<LibObjT>& | |
1814 | operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept | |
1815 | { | |
1816 | _ThisCommonVariantFieldClass::operator=(fc); | |
1817 | return *this; | |
1818 | } | |
1819 | ||
1820 | void appendOption(const char * const name, const FieldClass& fc) | |
1821 | { | |
1822 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1823 | ||
1824 | const auto status = bt_field_class_variant_without_selector_append_option( | |
1825 | this->_libObjPtr(), name, fc._libObjPtr()); | |
1826 | ||
1827 | if (status == | |
1828 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
1829 | throw LibMemoryError {}; | |
1830 | } | |
1831 | } | |
1832 | ||
1833 | void appendOption(const std::string& name, const FieldClass& fc) | |
1834 | { | |
1835 | this->appendOption(name.data(), fc); | |
1836 | } | |
1837 | ||
1838 | Shared shared() const noexcept | |
1839 | { | |
1840 | return Shared {*this}; | |
1841 | } | |
1842 | }; | |
1843 | ||
1844 | using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>; | |
1845 | using ConstVariantWithoutSelectorFieldClass = | |
1846 | CommonVariantWithoutSelectorFieldClass<const bt_field_class>; | |
1847 | ||
1848 | namespace internal { | |
1849 | ||
1850 | template <typename OptionT> | |
1851 | struct CommonVariantWithIntegerSelectorFieldClassSpec; | |
1852 | ||
1853 | // Functions specific to variant field classes with unsigned integer selector | |
1854 | template <> | |
1855 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
1856 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
1857 | final | |
1858 | { | |
1859 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
1860 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
1861 | { | |
1862 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( | |
1863 | libObjPtr, index); | |
1864 | } | |
1865 | ||
1866 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * | |
1867 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
1868 | { | |
1869 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( | |
1870 | libObjPtr, name); | |
1871 | } | |
1872 | ||
1873 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
1874 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
1875 | bt_field_class * const libOptFcPtr, | |
1876 | const bt_integer_range_set_unsigned * const libRangesPtr) | |
1877 | { | |
1878 | return bt_field_class_variant_with_selector_field_integer_unsigned_append_option( | |
1879 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
1880 | } | |
1881 | }; | |
1882 | ||
1883 | // Functions specific to variant field classes with signed integer selector | |
1884 | template <> | |
1885 | struct CommonVariantWithIntegerSelectorFieldClassSpec< | |
1886 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
1887 | final | |
1888 | { | |
1889 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
1890 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept | |
1891 | { | |
1892 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( | |
1893 | libObjPtr, index); | |
1894 | } | |
1895 | ||
1896 | static const bt_field_class_variant_with_selector_field_integer_signed_option * | |
1897 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept | |
1898 | { | |
1899 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( | |
1900 | libObjPtr, name); | |
1901 | } | |
1902 | ||
1903 | static bt_field_class_variant_with_selector_field_integer_append_option_status | |
1904 | appendOption(bt_field_class * const libObjPtr, const char * const name, | |
1905 | bt_field_class * const libOptFcPtr, | |
1906 | const bt_integer_range_set_signed * const libRangesPtr) | |
1907 | { | |
1908 | return bt_field_class_variant_with_selector_field_integer_signed_append_option( | |
1909 | libObjPtr, name, libOptFcPtr, libRangesPtr); | |
1910 | } | |
1911 | }; | |
1912 | ||
1913 | } // namespace internal | |
1914 | ||
1915 | template <typename LibObjT, typename OptionT> | |
1916 | class CommonVariantWithIntegerSelectorFieldClass : public CommonVariantFieldClass<LibObjT> | |
1917 | { | |
1918 | private: | |
1919 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; | |
1920 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; | |
1921 | ||
1922 | using _ThisCommonVariantWithIntegerSelectorFieldClass = | |
1923 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>; | |
1924 | ||
1925 | using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>; | |
1926 | ||
1927 | public: | |
1928 | using Shared = | |
1929 | internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>; | |
1930 | ||
1931 | using Option = OptionT; | |
1932 | ||
1933 | explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : | |
1934 | _ThisCommonVariantFieldClass {libObjPtr} | |
1935 | { | |
1936 | BT_ASSERT_DBG(this->isVariant()); | |
1937 | } | |
1938 | ||
1939 | template <typename OtherLibObjT> | |
1940 | CommonVariantWithIntegerSelectorFieldClass( | |
1941 | const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept : | |
1942 | _ThisCommonVariantFieldClass {fc} | |
1943 | { | |
1944 | } | |
1945 | ||
1946 | template <typename OtherLibObjT> | |
1947 | _ThisCommonVariantWithIntegerSelectorFieldClass& | |
1948 | operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept | |
1949 | { | |
1950 | _ThisCommonVariantFieldClass::operator=(fc); | |
1951 | return *this; | |
1952 | } | |
1953 | ||
1954 | ConstFieldPath selectorFieldPath() const noexcept | |
1955 | { | |
1956 | return ConstFieldPath { | |
1957 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( | |
1958 | this->_libObjPtr())}; | |
1959 | } | |
1960 | ||
1961 | Option operator[](const std::uint64_t index) const noexcept | |
1962 | { | |
1963 | return Option {_Spec::optionByIndex(this->_libObjPtr(), index)}; | |
1964 | } | |
1965 | ||
1966 | nonstd::optional<Option> operator[](const char * const name) const noexcept | |
1967 | { | |
1968 | const auto libObjPtr = _Spec::optionByName(this->_libObjPtr(), name); | |
1969 | ||
1970 | if (libObjPtr) { | |
1971 | return Option {libObjPtr}; | |
1972 | } | |
1973 | ||
1974 | return nonstd::nullopt; | |
1975 | } | |
1976 | ||
1977 | nonstd::optional<Option> operator[](const std::string& name) const noexcept | |
1978 | { | |
1979 | return (*this)[name.data()]; | |
1980 | } | |
1981 | ||
1982 | void appendOption(const char * const name, const FieldClass& fc, | |
1983 | const typename Option::RangeSet& ranges) | |
1984 | { | |
1985 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1986 | ||
1987 | const auto status = | |
1988 | _Spec::appendOption(this->_libObjPtr(), name, fc._libObjPtr(), ranges._libObjPtr()); | |
1989 | ||
1990 | if (status == | |
1991 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { | |
1992 | throw LibMemoryError {}; | |
1993 | } | |
1994 | } | |
1995 | ||
1996 | void appendOption(const std::string& name, const FieldClass& fc) | |
1997 | { | |
1998 | this->appendOption(name.data(), fc); | |
1999 | } | |
2000 | ||
2001 | Shared shared() const noexcept | |
2002 | { | |
2003 | return Shared {*this}; | |
2004 | } | |
2005 | }; | |
2006 | ||
2007 | using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2008 | bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2009 | ||
2010 | using ConstVariantWithUnsignedIntegerSelectorFieldClass = | |
2011 | CommonVariantWithIntegerSelectorFieldClass< | |
2012 | const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; | |
2013 | ||
2014 | using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2015 | bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2016 | ||
2017 | using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< | |
2018 | const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; | |
2019 | ||
2020 | template <typename LibObjT> | |
2021 | CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept | |
2022 | { | |
2023 | BT_ASSERT_DBG(this->isBitArray()); | |
2024 | return CommonBitArrayFieldClass<LibObjT> {this->_libObjPtr()}; | |
2025 | } | |
2026 | ||
2027 | template <typename LibObjT> | |
2028 | CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept | |
2029 | { | |
2030 | BT_ASSERT_DBG(this->isInteger()); | |
2031 | return CommonIntegerFieldClass<LibObjT> {this->_libObjPtr()}; | |
2032 | } | |
2033 | ||
2034 | template <typename LibObjT> | |
2035 | CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> | |
2036 | CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept | |
2037 | { | |
2038 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); | |
2039 | return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> { | |
2040 | this->_libObjPtr()}; | |
2041 | } | |
2042 | ||
2043 | template <typename LibObjT> | |
2044 | CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> | |
2045 | CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept | |
2046 | { | |
2047 | BT_ASSERT_DBG(this->isSignedEnumeration()); | |
2048 | return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> { | |
2049 | this->_libObjPtr()}; | |
2050 | } | |
2051 | ||
2052 | template <typename LibObjT> | |
2053 | CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept | |
2054 | { | |
2055 | BT_ASSERT_DBG(this->isStructure()); | |
2056 | return CommonStructureFieldClass<LibObjT> {this->_libObjPtr()}; | |
2057 | } | |
2058 | ||
2059 | template <typename LibObjT> | |
2060 | CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept | |
2061 | { | |
2062 | BT_ASSERT_DBG(this->isArray()); | |
2063 | return CommonArrayFieldClass<LibObjT> {this->_libObjPtr()}; | |
2064 | } | |
2065 | ||
2066 | template <typename LibObjT> | |
2067 | CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept | |
2068 | { | |
2069 | BT_ASSERT_DBG(this->isStaticArray()); | |
2070 | return CommonStaticArrayFieldClass<LibObjT> {this->_libObjPtr()}; | |
2071 | } | |
2072 | ||
2073 | template <typename LibObjT> | |
2074 | CommonDynamicArrayWithLengthFieldClass<LibObjT> | |
2075 | CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept | |
2076 | { | |
2077 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); | |
2078 | return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->_libObjPtr()}; | |
2079 | } | |
2080 | ||
2081 | template <typename LibObjT> | |
2082 | CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept | |
2083 | { | |
2084 | BT_ASSERT_DBG(this->isOption()); | |
2085 | return CommonOptionFieldClass<LibObjT> {this->_libObjPtr()}; | |
2086 | } | |
2087 | ||
2088 | template <typename LibObjT> | |
2089 | CommonOptionWithSelectorFieldClass<LibObjT> | |
2090 | CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept | |
2091 | { | |
2092 | BT_ASSERT_DBG(this->isOptionWithSelector()); | |
2093 | return CommonOptionWithSelectorFieldClass<LibObjT> {this->_libObjPtr()}; | |
2094 | } | |
2095 | ||
2096 | template <typename LibObjT> | |
2097 | CommonOptionWithBoolSelectorFieldClass<LibObjT> | |
2098 | CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept | |
2099 | { | |
2100 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); | |
2101 | return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->_libObjPtr()}; | |
2102 | } | |
2103 | ||
2104 | template <typename LibObjT> | |
2105 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> | |
2106 | CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept | |
2107 | { | |
2108 | BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector()); | |
2109 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> { | |
2110 | this->_libObjPtr()}; | |
2111 | } | |
2112 | ||
2113 | template <typename LibObjT> | |
2114 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> | |
2115 | CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept | |
2116 | { | |
2117 | BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector()); | |
2118 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> { | |
2119 | this->_libObjPtr()}; | |
2120 | } | |
2121 | ||
2122 | template <typename LibObjT> | |
2123 | CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept | |
2124 | { | |
2125 | BT_ASSERT_DBG(this->isVariant()); | |
2126 | return CommonVariantFieldClass<LibObjT> {this->_libObjPtr()}; | |
2127 | } | |
2128 | ||
2129 | template <typename LibObjT> | |
2130 | CommonVariantWithoutSelectorFieldClass<LibObjT> | |
2131 | CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept | |
2132 | { | |
2133 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); | |
2134 | return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->_libObjPtr()}; | |
2135 | } | |
2136 | ||
2137 | template <typename LibObjT> | |
2138 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, | |
2139 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> | |
2140 | CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept | |
2141 | { | |
2142 | BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector()); | |
2143 | return CommonVariantWithIntegerSelectorFieldClass< | |
2144 | LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->_libObjPtr()}; | |
2145 | } | |
2146 | ||
2147 | template <typename LibObjT> | |
2148 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, | |
2149 | ConstVariantWithSignedIntegerSelectorFieldClassOption> | |
2150 | CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept | |
2151 | { | |
2152 | BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector()); | |
2153 | return CommonVariantWithIntegerSelectorFieldClass< | |
2154 | LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->_libObjPtr()}; | |
2155 | } | |
2156 | ||
2157 | } // namespace bt2 | |
2158 | ||
2159 | #endif // BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP |