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