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