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