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