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