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