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