Commit | Line | Data |
---|---|---|
a1e31878 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_HPP | |
8 | #define BABELTRACE_CPP_COMMON_BT2_FIELD_HPP | |
9 | ||
a1e31878 | 10 | #include <cstdint> |
c802cacb SM |
11 | #include <type_traits> |
12 | ||
a1e31878 PP |
13 | #include <babeltrace2/babeltrace.h> |
14 | ||
15 | #include "common/assert.h" | |
a1e31878 PP |
16 | #include "cpp-common/optional.hpp" |
17 | #include "cpp-common/string_view.hpp" | |
c802cacb | 18 | |
0d218157 | 19 | #include "borrowed-object.hpp" |
a1e31878 | 20 | #include "field-class.hpp" |
c802cacb | 21 | #include "internal/utils.hpp" |
7f7fbdb3 | 22 | #include "raw-value-proxy.hpp" |
a1e31878 PP |
23 | |
24 | namespace bt2 { | |
25 | ||
26 | template <typename LibObjT> | |
27 | class CommonBoolField; | |
28 | ||
29 | template <typename LibObjT> | |
30 | class CommonBitArrayField; | |
31 | ||
32 | template <typename LibObjT> | |
33 | class CommonUnsignedIntegerField; | |
34 | ||
35 | template <typename LibObjT> | |
36 | class CommonSignedIntegerField; | |
37 | ||
38 | template <typename LibObjT> | |
39 | class CommonUnsignedEnumerationField; | |
40 | ||
41 | template <typename LibObjT> | |
42 | class CommonSignedEnumerationField; | |
43 | ||
44 | template <typename LibObjT> | |
45 | class CommonSinglePrecisionRealField; | |
46 | ||
47 | template <typename LibObjT> | |
48 | class CommonDoublePrecisionRealField; | |
49 | ||
50 | template <typename LibObjT> | |
51 | class CommonStringField; | |
52 | ||
53 | template <typename LibObjT> | |
54 | class CommonStructureField; | |
55 | ||
56 | template <typename LibObjT> | |
57 | class CommonArrayField; | |
58 | ||
59 | template <typename LibObjT> | |
60 | class CommonDynamicArrayField; | |
61 | ||
62 | template <typename LibObjT> | |
63 | class CommonOptionField; | |
64 | ||
65 | template <typename LibObjT> | |
66 | class CommonVariantField; | |
67 | ||
68 | namespace internal { | |
69 | ||
70 | template <typename LibObjT> | |
71 | struct CommonFieldSpec; | |
72 | ||
b5f55e9f | 73 | /* Functions specific to mutable fields */ |
a1e31878 PP |
74 | template <> |
75 | struct CommonFieldSpec<bt_field> final | |
76 | { | |
77 | static bt_field_class *cls(bt_field * const libObjPtr) noexcept | |
78 | { | |
79 | return bt_field_borrow_class(libObjPtr); | |
80 | } | |
81 | }; | |
82 | ||
b5f55e9f | 83 | /* Functions specific to constant fields */ |
a1e31878 PP |
84 | template <> |
85 | struct CommonFieldSpec<const bt_field> final | |
86 | { | |
87 | static const bt_field_class *cls(const bt_field * const libObjPtr) noexcept | |
88 | { | |
89 | return bt_field_borrow_class_const(libObjPtr); | |
90 | } | |
91 | }; | |
92 | ||
b5f55e9f | 93 | } /* namespace internal */ |
a1e31878 PP |
94 | |
95 | template <typename LibObjT> | |
0d218157 | 96 | class CommonField : public BorrowedObject<LibObjT> |
a1e31878 PP |
97 | { |
98 | private: | |
0d218157 | 99 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
a1e31878 PP |
100 | |
101 | protected: | |
0d218157 | 102 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
a1e31878 PP |
103 | using _ThisCommonField = CommonField<LibObjT>; |
104 | ||
105 | public: | |
8047a175 | 106 | using Class = internal::DepFc<LibObjT>; |
a1e31878 | 107 | |
0d218157 | 108 | explicit CommonField(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
a1e31878 PP |
109 | { |
110 | } | |
111 | ||
112 | template <typename OtherLibObjT> | |
0d218157 | 113 | CommonField(const CommonField<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val} |
a1e31878 PP |
114 | { |
115 | } | |
116 | ||
117 | template <typename OtherLibObjT> | |
ac30a470 | 118 | _ThisCommonField operator=(const CommonField<OtherLibObjT> val) noexcept |
a1e31878 | 119 | { |
0d218157 | 120 | _ThisBorrowedObject::operator=(val); |
a1e31878 PP |
121 | return *this; |
122 | } | |
123 | ||
328a274a PP |
124 | CommonField<const bt_field> asConst() const noexcept |
125 | { | |
126 | return CommonField<const bt_field> {*this}; | |
127 | } | |
128 | ||
a1e31878 PP |
129 | FieldClassType classType() const noexcept |
130 | { | |
341a67c4 | 131 | return static_cast<FieldClassType>(bt_field_get_class_type(this->libObjPtr())); |
a1e31878 PP |
132 | } |
133 | ||
dcb8ae9b | 134 | Class cls() const noexcept |
a1e31878 | 135 | { |
341a67c4 | 136 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
137 | } |
138 | ||
139 | bool isBool() const noexcept | |
140 | { | |
141 | return this->cls().isBool(); | |
142 | } | |
143 | ||
144 | bool isBitArray() const noexcept | |
145 | { | |
146 | return this->cls().isBitArray(); | |
147 | } | |
148 | ||
149 | bool isUnsignedInteger() const noexcept | |
150 | { | |
151 | return this->cls().isUnsignedInteger(); | |
152 | } | |
153 | ||
154 | bool isSignedInteger() const noexcept | |
155 | { | |
156 | return this->cls().isSignedInteger(); | |
157 | } | |
158 | ||
159 | bool isUnsignedEnumeration() const noexcept | |
160 | { | |
161 | return this->cls().isUnsignedEnumeration(); | |
162 | } | |
163 | ||
164 | bool isSignedEnumeration() const noexcept | |
165 | { | |
166 | return this->cls().isSignedEnumeration(); | |
167 | } | |
168 | ||
169 | bool isSinglePrecisionReal() const noexcept | |
170 | { | |
171 | return this->cls().isSinglePrecisionReal(); | |
172 | } | |
173 | ||
174 | bool isDoublePrecisionReal() const noexcept | |
175 | { | |
176 | return this->cls().isDoublePrecisionReal(); | |
177 | } | |
178 | ||
179 | bool isString() const noexcept | |
180 | { | |
181 | return this->cls().isString(); | |
182 | } | |
183 | ||
184 | bool isStructure() const noexcept | |
185 | { | |
186 | return this->cls().isStructure(); | |
187 | } | |
188 | ||
189 | bool isArray() const noexcept | |
190 | { | |
191 | return this->cls().isArray(); | |
192 | } | |
193 | ||
194 | bool isDynamicArray() const noexcept | |
195 | { | |
196 | return this->cls().isDynamicArray(); | |
197 | } | |
198 | ||
199 | bool isOption() const noexcept | |
200 | { | |
201 | return this->cls().isOption(); | |
202 | } | |
203 | ||
204 | bool isVariant() const noexcept | |
205 | { | |
206 | return this->cls().isVariant(); | |
207 | } | |
208 | ||
45e0ded5 PP |
209 | template <typename FieldT> |
210 | FieldT as() const noexcept | |
211 | { | |
212 | return FieldT {this->libObjPtr()}; | |
213 | } | |
214 | ||
a1e31878 PP |
215 | CommonBoolField<LibObjT> asBool() const noexcept; |
216 | CommonBitArrayField<LibObjT> asBitArray() const noexcept; | |
217 | CommonUnsignedIntegerField<LibObjT> asUnsignedInteger() const noexcept; | |
218 | CommonSignedIntegerField<LibObjT> asSignedInteger() const noexcept; | |
219 | CommonUnsignedEnumerationField<LibObjT> asUnsignedEnumeration() const noexcept; | |
220 | CommonSignedEnumerationField<LibObjT> asSignedEnumeration() const noexcept; | |
221 | CommonSinglePrecisionRealField<LibObjT> asSinglePrecisionReal() const noexcept; | |
222 | CommonDoublePrecisionRealField<LibObjT> asDoublePrecisionReal() const noexcept; | |
223 | CommonStringField<LibObjT> asString() const noexcept; | |
224 | CommonStructureField<LibObjT> asStructure() const noexcept; | |
225 | CommonArrayField<LibObjT> asArray() const noexcept; | |
226 | CommonDynamicArrayField<LibObjT> asDynamicArray() const noexcept; | |
227 | CommonOptionField<LibObjT> asOption() const noexcept; | |
228 | CommonVariantField<LibObjT> asVariant() const noexcept; | |
229 | }; | |
230 | ||
231 | using Field = CommonField<bt_field>; | |
232 | using ConstField = CommonField<const bt_field>; | |
233 | ||
4927bae7 PP |
234 | namespace internal { |
235 | ||
236 | struct FieldTypeDescr | |
237 | { | |
238 | using Const = ConstField; | |
239 | using NonConst = Field; | |
240 | }; | |
241 | ||
242 | template <> | |
243 | struct TypeDescr<Field> : public FieldTypeDescr | |
244 | { | |
245 | }; | |
246 | ||
247 | template <> | |
248 | struct TypeDescr<ConstField> : public FieldTypeDescr | |
249 | { | |
250 | }; | |
251 | ||
252 | } /* namespace internal */ | |
253 | ||
a1e31878 PP |
254 | template <typename LibObjT> |
255 | class CommonBoolField final : public CommonField<LibObjT> | |
256 | { | |
257 | private: | |
258 | using typename CommonField<LibObjT>::_LibObjPtr; | |
259 | using typename CommonField<LibObjT>::_ThisCommonField; | |
260 | ||
261 | public: | |
262 | using Value = bool; | |
263 | ||
264 | explicit CommonBoolField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} | |
265 | { | |
266 | BT_ASSERT_DBG(this->isBool()); | |
267 | } | |
268 | ||
269 | template <typename OtherLibObjT> | |
100fa861 | 270 | CommonBoolField(const CommonBoolField<OtherLibObjT> val) noexcept : _ThisCommonField {val} |
a1e31878 PP |
271 | { |
272 | } | |
273 | ||
274 | template <typename OtherLibObjT> | |
ac30a470 | 275 | CommonBoolField<LibObjT> operator=(const CommonBoolField<OtherLibObjT> val) noexcept |
a1e31878 PP |
276 | { |
277 | _ThisCommonField::operator=(val); | |
278 | return *this; | |
279 | } | |
280 | ||
328a274a PP |
281 | CommonBoolField<const bt_field> asConst() const noexcept |
282 | { | |
283 | return CommonBoolField<const bt_field> {*this}; | |
284 | } | |
285 | ||
7f7fbdb3 PP |
286 | RawValueProxy<CommonBoolField> operator*() const noexcept |
287 | { | |
288 | return RawValueProxy<CommonBoolField> {*this}; | |
289 | } | |
290 | ||
291 | void value(const Value val) const noexcept | |
a1e31878 | 292 | { |
5c895f64 | 293 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolField`."); |
a1e31878 | 294 | |
341a67c4 | 295 | bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val)); |
a1e31878 PP |
296 | } |
297 | ||
298 | Value value() const noexcept | |
299 | { | |
341a67c4 | 300 | return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr())); |
a1e31878 | 301 | } |
a1e31878 PP |
302 | }; |
303 | ||
304 | using BoolField = CommonBoolField<bt_field>; | |
305 | using ConstBoolField = CommonBoolField<const bt_field>; | |
306 | ||
4927bae7 PP |
307 | namespace internal { |
308 | ||
309 | struct BoolFieldTypeDescr | |
310 | { | |
311 | using Const = ConstBoolField; | |
312 | using NonConst = BoolField; | |
313 | }; | |
314 | ||
315 | template <> | |
316 | struct TypeDescr<BoolField> : public BoolFieldTypeDescr | |
317 | { | |
318 | }; | |
319 | ||
320 | template <> | |
321 | struct TypeDescr<ConstBoolField> : public BoolFieldTypeDescr | |
322 | { | |
323 | }; | |
324 | ||
325 | } /* namespace internal */ | |
326 | ||
a1e31878 PP |
327 | template <typename LibObjT> |
328 | class CommonBitArrayField final : public CommonField<LibObjT> | |
329 | { | |
330 | private: | |
331 | using typename CommonField<LibObjT>::_LibObjPtr; | |
332 | using typename CommonField<LibObjT>::_ThisCommonField; | |
333 | ||
334 | public: | |
8047a175 | 335 | using Class = internal::DepType<LibObjT, BitArrayFieldClass, ConstBitArrayFieldClass>; |
a1e31878 PP |
336 | |
337 | explicit CommonBitArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} | |
338 | { | |
339 | BT_ASSERT_DBG(this->isBitArray()); | |
340 | } | |
341 | ||
342 | template <typename OtherLibObjT> | |
100fa861 | 343 | CommonBitArrayField(const CommonBitArrayField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
344 | _ThisCommonField {val} |
345 | { | |
346 | } | |
347 | ||
348 | template <typename OtherLibObjT> | |
ac30a470 | 349 | CommonBitArrayField<LibObjT> operator=(const CommonBitArrayField<OtherLibObjT> val) noexcept |
a1e31878 PP |
350 | { |
351 | _ThisCommonField::operator=(val); | |
352 | return *this; | |
353 | } | |
354 | ||
328a274a PP |
355 | CommonBitArrayField<const bt_field> asConst() const noexcept |
356 | { | |
357 | return CommonBitArrayField<const bt_field> {*this}; | |
358 | } | |
359 | ||
a1e31878 PP |
360 | ConstBitArrayFieldClass cls() const noexcept |
361 | { | |
362 | return ConstBitArrayFieldClass { | |
341a67c4 | 363 | internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())}; |
a1e31878 PP |
364 | } |
365 | ||
366 | Class cls() noexcept | |
367 | { | |
341a67c4 | 368 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
369 | } |
370 | ||
7f7fbdb3 | 371 | void valueAsInteger(const std::uint64_t bits) const noexcept |
a1e31878 | 372 | { |
5c895f64 PP |
373 | static_assert(!std::is_const<LibObjT>::value, |
374 | "Not available with `bt2::ConstBitArrayField`."); | |
a1e31878 | 375 | |
341a67c4 | 376 | bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits); |
a1e31878 PP |
377 | } |
378 | ||
379 | std::uint64_t valueAsInteger() const noexcept | |
380 | { | |
341a67c4 | 381 | return bt_field_bit_array_get_value_as_integer(this->libObjPtr()); |
a1e31878 PP |
382 | } |
383 | ||
384 | bool bitValue(const std::uint64_t index) const noexcept | |
385 | { | |
386 | BT_ASSERT_DBG(index < this->cls().length()); | |
387 | return static_cast<bool>(this->valueAsInteger() & (1ULL << index)); | |
388 | } | |
389 | }; | |
390 | ||
391 | using BitArrayField = CommonBitArrayField<bt_field>; | |
392 | using ConstBitArrayField = CommonBitArrayField<const bt_field>; | |
393 | ||
4927bae7 PP |
394 | namespace internal { |
395 | ||
396 | struct BitArrayFieldTypeDescr | |
397 | { | |
398 | using Const = ConstBitArrayField; | |
399 | using NonConst = BitArrayField; | |
400 | }; | |
401 | ||
402 | template <> | |
403 | struct TypeDescr<BitArrayField> : public BitArrayFieldTypeDescr | |
404 | { | |
405 | }; | |
406 | ||
407 | template <> | |
408 | struct TypeDescr<ConstBitArrayField> : public BitArrayFieldTypeDescr | |
409 | { | |
410 | }; | |
411 | ||
412 | } /* namespace internal */ | |
413 | ||
a1e31878 | 414 | template <typename LibObjT> |
edfe13aa | 415 | class CommonUnsignedIntegerField : public CommonField<LibObjT> |
a1e31878 PP |
416 | { |
417 | private: | |
418 | using typename CommonField<LibObjT>::_ThisCommonField; | |
419 | ||
420 | protected: | |
421 | using typename CommonField<LibObjT>::_LibObjPtr; | |
422 | using _ThisCommonUnsignedIntegerField = CommonUnsignedIntegerField<LibObjT>; | |
423 | ||
424 | public: | |
425 | using Value = std::uint64_t; | |
8047a175 | 426 | using Class = internal::DepType<LibObjT, IntegerFieldClass, ConstIntegerFieldClass>; |
a1e31878 PP |
427 | |
428 | explicit CommonUnsignedIntegerField(const _LibObjPtr libObjPtr) noexcept : | |
429 | _ThisCommonField {libObjPtr} | |
430 | { | |
431 | BT_ASSERT_DBG(this->isUnsignedInteger()); | |
432 | } | |
433 | ||
434 | template <typename OtherLibObjT> | |
100fa861 | 435 | CommonUnsignedIntegerField(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
436 | _ThisCommonField {val} |
437 | { | |
438 | } | |
439 | ||
440 | template <typename OtherLibObjT> | |
ac30a470 | 441 | _ThisCommonUnsignedIntegerField |
100fa861 | 442 | operator=(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept |
a1e31878 PP |
443 | { |
444 | _ThisCommonField::operator=(val); | |
445 | return *this; | |
446 | } | |
447 | ||
328a274a PP |
448 | CommonUnsignedIntegerField<const bt_field> asConst() const noexcept |
449 | { | |
450 | return CommonUnsignedIntegerField<const bt_field> {*this}; | |
451 | } | |
452 | ||
dcb8ae9b | 453 | Class cls() const noexcept |
a1e31878 | 454 | { |
341a67c4 | 455 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
456 | } |
457 | ||
7f7fbdb3 PP |
458 | RawValueProxy<CommonUnsignedIntegerField> operator*() const noexcept |
459 | { | |
460 | return RawValueProxy<CommonUnsignedIntegerField> {*this}; | |
461 | } | |
462 | ||
463 | void value(const Value val) const noexcept | |
a1e31878 | 464 | { |
5c895f64 PP |
465 | static_assert(!std::is_const<LibObjT>::value, |
466 | "Not available with `bt2::ConstUnsignedIntegerField`."); | |
a1e31878 | 467 | |
341a67c4 | 468 | bt_field_integer_unsigned_set_value(this->libObjPtr(), val); |
a1e31878 PP |
469 | } |
470 | ||
471 | Value value() const noexcept | |
472 | { | |
341a67c4 | 473 | return bt_field_integer_unsigned_get_value(this->libObjPtr()); |
a1e31878 | 474 | } |
a1e31878 PP |
475 | }; |
476 | ||
477 | using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>; | |
478 | using ConstUnsignedIntegerField = CommonUnsignedIntegerField<const bt_field>; | |
479 | ||
4927bae7 PP |
480 | namespace internal { |
481 | ||
482 | struct UnsignedIntegerFieldTypeDescr | |
483 | { | |
484 | using Const = ConstUnsignedIntegerField; | |
485 | using NonConst = UnsignedIntegerField; | |
486 | }; | |
487 | ||
488 | template <> | |
489 | struct TypeDescr<UnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr | |
490 | { | |
491 | }; | |
492 | ||
493 | template <> | |
494 | struct TypeDescr<ConstUnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr | |
495 | { | |
496 | }; | |
497 | ||
498 | } /* namespace internal */ | |
499 | ||
a1e31878 | 500 | template <typename LibObjT> |
edfe13aa | 501 | class CommonSignedIntegerField : public CommonField<LibObjT> |
a1e31878 PP |
502 | { |
503 | private: | |
504 | using typename CommonField<LibObjT>::_ThisCommonField; | |
505 | ||
506 | protected: | |
507 | using typename CommonField<LibObjT>::_LibObjPtr; | |
508 | using _ThisCommonSignedIntegerField = CommonSignedIntegerField<LibObjT>; | |
509 | ||
510 | public: | |
edfe13aa | 511 | using Value = std::int64_t; |
8047a175 | 512 | using Class = internal::DepType<LibObjT, IntegerFieldClass, ConstIntegerFieldClass>; |
a1e31878 PP |
513 | |
514 | explicit CommonSignedIntegerField(const _LibObjPtr libObjPtr) noexcept : | |
515 | _ThisCommonField {libObjPtr} | |
516 | { | |
517 | BT_ASSERT_DBG(this->isSignedInteger()); | |
518 | } | |
519 | ||
520 | template <typename OtherLibObjT> | |
100fa861 | 521 | CommonSignedIntegerField(const CommonSignedIntegerField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
522 | _ThisCommonField {val} |
523 | { | |
524 | } | |
525 | ||
526 | template <typename OtherLibObjT> | |
ac30a470 | 527 | _ThisCommonSignedIntegerField |
100fa861 | 528 | operator=(const CommonSignedIntegerField<OtherLibObjT> val) noexcept |
a1e31878 PP |
529 | { |
530 | _ThisCommonField::operator=(val); | |
531 | return *this; | |
532 | } | |
533 | ||
328a274a PP |
534 | CommonSignedIntegerField<const bt_field> asConst() const noexcept |
535 | { | |
536 | return CommonSignedIntegerField<const bt_field> {*this}; | |
537 | } | |
538 | ||
dcb8ae9b | 539 | Class cls() const noexcept |
a1e31878 | 540 | { |
341a67c4 | 541 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
542 | } |
543 | ||
7f7fbdb3 PP |
544 | RawValueProxy<CommonSignedIntegerField> operator*() const noexcept |
545 | { | |
546 | return RawValueProxy<CommonSignedIntegerField> {*this}; | |
547 | } | |
548 | ||
549 | void value(const Value val) const noexcept | |
a1e31878 | 550 | { |
5c895f64 PP |
551 | static_assert(!std::is_const<LibObjT>::value, |
552 | "Not available with `bt2::ConstSignedIntegerField`."); | |
a1e31878 | 553 | |
341a67c4 | 554 | bt_field_integer_signed_set_value(this->libObjPtr(), val); |
a1e31878 PP |
555 | } |
556 | ||
557 | Value value() const noexcept | |
558 | { | |
341a67c4 | 559 | return bt_field_integer_signed_get_value(this->libObjPtr()); |
a1e31878 | 560 | } |
a1e31878 PP |
561 | }; |
562 | ||
563 | using SignedIntegerField = CommonSignedIntegerField<bt_field>; | |
564 | using ConstSignedIntegerField = CommonSignedIntegerField<const bt_field>; | |
565 | ||
4927bae7 PP |
566 | namespace internal { |
567 | ||
568 | struct SignedIntegerFieldTypeDescr | |
569 | { | |
570 | using Const = ConstSignedIntegerField; | |
571 | using NonConst = SignedIntegerField; | |
572 | }; | |
573 | ||
574 | template <> | |
575 | struct TypeDescr<SignedIntegerField> : public SignedIntegerFieldTypeDescr | |
576 | { | |
577 | }; | |
578 | ||
579 | template <> | |
580 | struct TypeDescr<ConstSignedIntegerField> : public SignedIntegerFieldTypeDescr | |
581 | { | |
582 | }; | |
583 | ||
584 | } /* namespace internal */ | |
585 | ||
a1e31878 PP |
586 | class EnumerationFieldClassMappingLabels |
587 | { | |
588 | public: | |
589 | explicit EnumerationFieldClassMappingLabels( | |
590 | const bt_field_class_enumeration_mapping_label_array labels, const std::uint64_t size) : | |
591 | _mLabels {labels}, | |
c0b73c63 | 592 | _mLen {size} |
a1e31878 PP |
593 | { |
594 | } | |
595 | ||
c0b73c63 | 596 | std::uint64_t length() const noexcept |
a1e31878 | 597 | { |
c0b73c63 | 598 | return _mLen; |
a1e31878 PP |
599 | } |
600 | ||
601 | bpstd::string_view operator[](const std::uint64_t index) const noexcept | |
602 | { | |
603 | return _mLabels[index]; | |
604 | } | |
605 | ||
606 | private: | |
607 | bt_field_class_enumeration_mapping_label_array _mLabels; | |
c0b73c63 | 608 | std::uint64_t _mLen; |
a1e31878 PP |
609 | }; |
610 | ||
611 | template <typename LibObjT> | |
612 | class CommonUnsignedEnumerationField final : public CommonUnsignedIntegerField<LibObjT> | |
613 | { | |
614 | private: | |
615 | using typename CommonUnsignedIntegerField<LibObjT>::_ThisCommonUnsignedIntegerField; | |
616 | using typename CommonField<LibObjT>::_LibObjPtr; | |
617 | ||
618 | public: | |
8047a175 PP |
619 | using Class = internal::DepType<LibObjT, UnsignedEnumerationFieldClass, |
620 | ConstUnsignedEnumerationFieldClass>; | |
a1e31878 PP |
621 | |
622 | explicit CommonUnsignedEnumerationField(const _LibObjPtr libObjPtr) noexcept : | |
623 | _ThisCommonUnsignedIntegerField {libObjPtr} | |
624 | { | |
625 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); | |
626 | } | |
627 | ||
628 | template <typename OtherLibObjT> | |
100fa861 | 629 | CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept |
a1e31878 PP |
630 | : |
631 | _ThisCommonUnsignedIntegerField {val} | |
632 | { | |
633 | } | |
634 | ||
635 | template <typename OtherLibObjT> | |
ac30a470 | 636 | CommonUnsignedEnumerationField<LibObjT> |
100fa861 | 637 | operator=(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept |
a1e31878 PP |
638 | { |
639 | _ThisCommonUnsignedIntegerField::operator=(val); | |
640 | return *this; | |
641 | } | |
642 | ||
328a274a PP |
643 | CommonUnsignedEnumerationField<const bt_field> asConst() const noexcept |
644 | { | |
645 | return CommonUnsignedEnumerationField<const bt_field> {*this}; | |
646 | } | |
647 | ||
dcb8ae9b | 648 | Class cls() const noexcept |
a1e31878 | 649 | { |
341a67c4 | 650 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
651 | } |
652 | ||
653 | EnumerationFieldClassMappingLabels labels() const | |
654 | { | |
655 | bt_field_class_enumeration_mapping_label_array labelArray; | |
656 | std::uint64_t count; | |
341a67c4 | 657 | const auto status = bt_field_enumeration_unsigned_get_mapping_labels(this->libObjPtr(), |
a1e31878 PP |
658 | &labelArray, &count); |
659 | ||
660 | if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) { | |
39278ebc | 661 | throw MemoryError {}; |
a1e31878 PP |
662 | } |
663 | ||
664 | return EnumerationFieldClassMappingLabels {labelArray, count}; | |
665 | } | |
666 | }; | |
667 | ||
668 | using UnsignedEnumerationField = CommonUnsignedEnumerationField<bt_field>; | |
669 | using ConstUnsignedEnumerationField = CommonUnsignedEnumerationField<const bt_field>; | |
670 | ||
4927bae7 PP |
671 | namespace internal { |
672 | ||
673 | struct UnsignedEnumerationFieldTypeDescr | |
674 | { | |
675 | using Const = ConstUnsignedEnumerationField; | |
676 | using NonConst = UnsignedEnumerationField; | |
677 | }; | |
678 | ||
679 | template <> | |
680 | struct TypeDescr<UnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr | |
681 | { | |
682 | }; | |
683 | ||
684 | template <> | |
685 | struct TypeDescr<ConstUnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr | |
686 | { | |
687 | }; | |
688 | ||
689 | } /* namespace internal */ | |
690 | ||
a1e31878 PP |
691 | template <typename LibObjT> |
692 | class CommonSignedEnumerationField final : public CommonSignedIntegerField<LibObjT> | |
693 | { | |
694 | private: | |
695 | using typename CommonSignedIntegerField<LibObjT>::_ThisCommonSignedIntegerField; | |
696 | using typename CommonField<LibObjT>::_LibObjPtr; | |
697 | ||
698 | public: | |
699 | using Class = | |
8047a175 | 700 | internal::DepType<LibObjT, SignedEnumerationFieldClass, ConstSignedEnumerationFieldClass>; |
a1e31878 PP |
701 | |
702 | explicit CommonSignedEnumerationField(const _LibObjPtr libObjPtr) noexcept : | |
703 | _ThisCommonSignedIntegerField {libObjPtr} | |
704 | { | |
705 | BT_ASSERT_DBG(this->isSignedEnumeration()); | |
706 | } | |
707 | ||
708 | template <typename OtherLibObjT> | |
100fa861 | 709 | CommonSignedEnumerationField(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
710 | _ThisCommonSignedIntegerField {val} |
711 | { | |
712 | } | |
713 | ||
714 | template <typename OtherLibObjT> | |
ac30a470 | 715 | CommonSignedEnumerationField<LibObjT> |
100fa861 | 716 | operator=(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept |
a1e31878 PP |
717 | { |
718 | _ThisCommonSignedIntegerField::operator=(val); | |
719 | return *this; | |
720 | } | |
721 | ||
328a274a PP |
722 | CommonSignedEnumerationField<const bt_field> asConst() const noexcept |
723 | { | |
724 | return CommonSignedEnumerationField<const bt_field> {*this}; | |
725 | } | |
726 | ||
dcb8ae9b | 727 | Class cls() const noexcept |
a1e31878 | 728 | { |
341a67c4 | 729 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
730 | } |
731 | ||
732 | EnumerationFieldClassMappingLabels labels() const | |
733 | { | |
734 | bt_field_class_enumeration_mapping_label_array labelArray; | |
735 | std::uint64_t count; | |
736 | const auto status = | |
341a67c4 | 737 | bt_field_enumeration_signed_get_mapping_labels(this->libObjPtr(), &labelArray, &count); |
a1e31878 PP |
738 | |
739 | if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) { | |
39278ebc | 740 | throw MemoryError {}; |
a1e31878 PP |
741 | } |
742 | ||
743 | return EnumerationFieldClassMappingLabels {labelArray, count}; | |
744 | } | |
745 | }; | |
746 | ||
747 | using SignedEnumerationField = CommonSignedEnumerationField<bt_field>; | |
748 | using ConstSignedEnumerationField = CommonSignedEnumerationField<const bt_field>; | |
749 | ||
4927bae7 PP |
750 | namespace internal { |
751 | ||
752 | struct SignedEnumerationFieldTypeDescr | |
753 | { | |
754 | using Const = ConstSignedEnumerationField; | |
755 | using NonConst = SignedEnumerationField; | |
756 | }; | |
757 | ||
758 | template <> | |
759 | struct TypeDescr<SignedEnumerationField> : public SignedEnumerationFieldTypeDescr | |
760 | { | |
761 | }; | |
762 | ||
763 | template <> | |
764 | struct TypeDescr<ConstSignedEnumerationField> : public SignedEnumerationFieldTypeDescr | |
765 | { | |
766 | }; | |
767 | ||
768 | } /* namespace internal */ | |
769 | ||
a1e31878 PP |
770 | template <typename LibObjT> |
771 | class CommonSinglePrecisionRealField final : public CommonField<LibObjT> | |
772 | { | |
773 | private: | |
774 | using typename CommonField<LibObjT>::_LibObjPtr; | |
775 | using typename CommonField<LibObjT>::_ThisCommonField; | |
776 | ||
777 | public: | |
778 | using Value = float; | |
779 | ||
780 | explicit CommonSinglePrecisionRealField(const _LibObjPtr libObjPtr) noexcept : | |
781 | _ThisCommonField {libObjPtr} | |
782 | { | |
783 | BT_ASSERT_DBG(this->isSinglePrecisionReal()); | |
784 | } | |
785 | ||
786 | template <typename OtherLibObjT> | |
100fa861 | 787 | CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept |
a1e31878 PP |
788 | : |
789 | _ThisCommonField {val} | |
790 | { | |
791 | } | |
792 | ||
793 | template <typename OtherLibObjT> | |
ac30a470 | 794 | CommonSinglePrecisionRealField<LibObjT> |
100fa861 | 795 | operator=(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept |
a1e31878 PP |
796 | { |
797 | _ThisCommonField::operator=(val); | |
798 | return *this; | |
799 | } | |
800 | ||
328a274a PP |
801 | CommonSinglePrecisionRealField<const bt_field> asConst() const noexcept |
802 | { | |
803 | return CommonSinglePrecisionRealField<const bt_field> {*this}; | |
804 | } | |
805 | ||
7f7fbdb3 PP |
806 | RawValueProxy<CommonSinglePrecisionRealField> operator*() const noexcept |
807 | { | |
808 | return RawValueProxy<CommonSinglePrecisionRealField> {*this}; | |
809 | } | |
810 | ||
811 | void value(const Value val) const noexcept | |
a1e31878 | 812 | { |
5c895f64 PP |
813 | static_assert(!std::is_const<LibObjT>::value, |
814 | "Not available with `bt2::ConstSinglePrecisionRealField`."); | |
a1e31878 | 815 | |
341a67c4 | 816 | bt_field_real_single_precision_set_value(this->libObjPtr(), val); |
a1e31878 PP |
817 | } |
818 | ||
819 | Value value() const noexcept | |
820 | { | |
341a67c4 | 821 | return bt_field_real_single_precision_get_value(this->libObjPtr()); |
a1e31878 | 822 | } |
a1e31878 PP |
823 | }; |
824 | ||
825 | using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>; | |
826 | using ConstSinglePrecisionRealField = CommonSinglePrecisionRealField<const bt_field>; | |
827 | ||
4927bae7 PP |
828 | namespace internal { |
829 | ||
830 | struct SinglePrecisionRealFieldTypeDescr | |
831 | { | |
832 | using Const = ConstSinglePrecisionRealField; | |
833 | using NonConst = SinglePrecisionRealField; | |
834 | }; | |
835 | ||
836 | template <> | |
837 | struct TypeDescr<SinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr | |
838 | { | |
839 | }; | |
840 | ||
841 | template <> | |
842 | struct TypeDescr<ConstSinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr | |
843 | { | |
844 | }; | |
845 | ||
846 | } /* namespace internal */ | |
847 | ||
a1e31878 PP |
848 | template <typename LibObjT> |
849 | class CommonDoublePrecisionRealField final : public CommonField<LibObjT> | |
850 | { | |
851 | private: | |
852 | using typename CommonField<LibObjT>::_LibObjPtr; | |
853 | using typename CommonField<LibObjT>::_ThisCommonField; | |
854 | ||
855 | public: | |
856 | using Value = double; | |
857 | ||
858 | explicit CommonDoublePrecisionRealField(const _LibObjPtr libObjPtr) noexcept : | |
859 | _ThisCommonField {libObjPtr} | |
860 | { | |
861 | BT_ASSERT_DBG(this->isDoublePrecisionReal()); | |
862 | } | |
863 | ||
864 | template <typename OtherLibObjT> | |
100fa861 | 865 | CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept |
a1e31878 PP |
866 | : |
867 | _ThisCommonField {val} | |
868 | { | |
869 | } | |
870 | ||
871 | template <typename OtherLibObjT> | |
ac30a470 | 872 | CommonDoublePrecisionRealField<LibObjT> |
100fa861 | 873 | operator=(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept |
a1e31878 PP |
874 | { |
875 | _ThisCommonField::operator=(val); | |
876 | return *this; | |
877 | } | |
878 | ||
328a274a PP |
879 | CommonDoublePrecisionRealField<const bt_field> asConst() const noexcept |
880 | { | |
881 | return CommonDoublePrecisionRealField<const bt_field> {*this}; | |
882 | } | |
883 | ||
7f7fbdb3 PP |
884 | RawValueProxy<CommonDoublePrecisionRealField> operator*() const noexcept |
885 | { | |
886 | return RawValueProxy<CommonDoublePrecisionRealField> {*this}; | |
887 | } | |
888 | ||
889 | void value(const Value val) const noexcept | |
a1e31878 | 890 | { |
5c895f64 PP |
891 | static_assert(!std::is_const<LibObjT>::value, |
892 | "Not available with `bt2::ConstDoublePrecisionRealField`."); | |
a1e31878 | 893 | |
edfe13aa | 894 | bt_field_real_double_precision_set_value(this->libObjPtr(), val); |
a1e31878 PP |
895 | } |
896 | ||
897 | Value value() const noexcept | |
898 | { | |
edfe13aa | 899 | return bt_field_real_double_precision_get_value(this->libObjPtr()); |
a1e31878 | 900 | } |
a1e31878 PP |
901 | }; |
902 | ||
903 | using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>; | |
904 | using ConstDoublePrecisionRealField = CommonDoublePrecisionRealField<const bt_field>; | |
905 | ||
4927bae7 PP |
906 | namespace internal { |
907 | ||
908 | struct DoublePrecisionRealFieldTypeDescr | |
909 | { | |
910 | using Const = ConstDoublePrecisionRealField; | |
911 | using NonConst = DoublePrecisionRealField; | |
912 | }; | |
913 | ||
914 | template <> | |
915 | struct TypeDescr<DoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr | |
916 | { | |
917 | }; | |
918 | ||
919 | template <> | |
920 | struct TypeDescr<ConstDoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr | |
921 | { | |
922 | }; | |
923 | ||
924 | } /* namespace internal */ | |
925 | ||
a1e31878 PP |
926 | template <typename LibObjT> |
927 | class CommonStringField final : public CommonField<LibObjT> | |
928 | { | |
929 | private: | |
930 | using typename CommonField<LibObjT>::_LibObjPtr; | |
931 | using typename CommonField<LibObjT>::_ThisCommonField; | |
932 | ||
933 | public: | |
7f7fbdb3 PP |
934 | using Value = const char *; |
935 | ||
a1e31878 PP |
936 | explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} |
937 | { | |
938 | BT_ASSERT_DBG(this->isString()); | |
939 | } | |
940 | ||
941 | template <typename OtherLibObjT> | |
100fa861 | 942 | CommonStringField(const CommonStringField<OtherLibObjT> val) noexcept : _ThisCommonField {val} |
a1e31878 PP |
943 | { |
944 | } | |
945 | ||
946 | template <typename OtherLibObjT> | |
ac30a470 | 947 | CommonStringField<LibObjT> operator=(const CommonStringField<OtherLibObjT> val) noexcept |
a1e31878 PP |
948 | { |
949 | _ThisCommonField::operator=(val); | |
950 | return *this; | |
951 | } | |
952 | ||
328a274a PP |
953 | CommonStringField<const bt_field> asConst() const noexcept |
954 | { | |
955 | return CommonStringField<const bt_field> {*this}; | |
956 | } | |
957 | ||
7f7fbdb3 PP |
958 | RawStringValueProxy<CommonStringField> operator*() const noexcept |
959 | { | |
960 | return RawStringValueProxy<CommonStringField> {*this}; | |
961 | } | |
962 | ||
963 | void value(const char * const val) const | |
a1e31878 | 964 | { |
5c895f64 PP |
965 | static_assert(!std::is_const<LibObjT>::value, |
966 | "Not available with `bt2::ConstStringField`."); | |
a1e31878 | 967 | |
341a67c4 | 968 | const auto status = bt_field_string_set_value(this->libObjPtr(), val); |
a1e31878 PP |
969 | |
970 | if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) { | |
39278ebc | 971 | throw MemoryError {}; |
a1e31878 | 972 | } |
a1e31878 PP |
973 | } |
974 | ||
7f7fbdb3 | 975 | void value(const std::string& val) const |
a1e31878 | 976 | { |
7f7fbdb3 | 977 | this->value(val.data()); |
a1e31878 PP |
978 | } |
979 | ||
dcb8ae9b | 980 | void append(const char * const begin, const std::uint64_t len) const |
8a79c777 | 981 | { |
5c895f64 PP |
982 | static_assert(!std::is_const<LibObjT>::value, |
983 | "Not available with `bt2::ConstStringField`."); | |
8a79c777 FD |
984 | |
985 | const auto status = bt_field_string_append_with_length(this->libObjPtr(), begin, len); | |
986 | ||
987 | if (status == BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR) { | |
988 | throw MemoryError {}; | |
989 | } | |
990 | } | |
991 | ||
dcb8ae9b | 992 | void append(const std::string& val) const |
8a79c777 FD |
993 | { |
994 | this->append(val.data(), val.size()); | |
995 | } | |
996 | ||
dcb8ae9b | 997 | void clear() const noexcept |
a1e31878 | 998 | { |
5c895f64 PP |
999 | static_assert(!std::is_const<LibObjT>::value, |
1000 | "Not available with `bt2::ConstStringField`."); | |
a1e31878 | 1001 | |
341a67c4 | 1002 | bt_field_string_clear(this->libObjPtr()); |
a1e31878 PP |
1003 | } |
1004 | ||
7f7fbdb3 | 1005 | const char *value() const noexcept |
a1e31878 | 1006 | { |
341a67c4 | 1007 | return bt_field_string_get_value(this->libObjPtr()); |
a1e31878 PP |
1008 | } |
1009 | }; | |
1010 | ||
1011 | using StringField = CommonStringField<bt_field>; | |
1012 | using ConstStringField = CommonStringField<const bt_field>; | |
1013 | ||
1014 | namespace internal { | |
1015 | ||
4927bae7 PP |
1016 | struct StringFieldTypeDescr |
1017 | { | |
1018 | using Const = ConstStringField; | |
1019 | using NonConst = StringField; | |
1020 | }; | |
1021 | ||
1022 | template <> | |
1023 | struct TypeDescr<StringField> : public StringFieldTypeDescr | |
1024 | { | |
1025 | }; | |
1026 | ||
1027 | template <> | |
1028 | struct TypeDescr<ConstStringField> : public StringFieldTypeDescr | |
1029 | { | |
1030 | }; | |
1031 | ||
a1e31878 PP |
1032 | template <typename LibObjT> |
1033 | struct CommonStructureFieldSpec; | |
1034 | ||
b5f55e9f | 1035 | /* Functions specific to mutable structure fields */ |
a1e31878 PP |
1036 | template <> |
1037 | struct CommonStructureFieldSpec<bt_field> final | |
1038 | { | |
1039 | static bt_field *memberFieldByIndex(bt_field * const libObjPtr, | |
1040 | const std::uint64_t index) noexcept | |
1041 | { | |
1042 | return bt_field_structure_borrow_member_field_by_index(libObjPtr, index); | |
1043 | } | |
1044 | ||
1045 | static bt_field *memberFieldByName(bt_field * const libObjPtr, const char * const name) noexcept | |
1046 | { | |
1047 | return bt_field_structure_borrow_member_field_by_name(libObjPtr, name); | |
1048 | } | |
1049 | }; | |
1050 | ||
b5f55e9f | 1051 | /* Functions specific to constant structure fields */ |
a1e31878 PP |
1052 | template <> |
1053 | struct CommonStructureFieldSpec<const bt_field> final | |
1054 | { | |
1055 | static const bt_field *memberFieldByIndex(const bt_field * const libObjPtr, | |
1056 | const std::uint64_t index) noexcept | |
1057 | { | |
1058 | return bt_field_structure_borrow_member_field_by_index_const(libObjPtr, index); | |
1059 | } | |
1060 | ||
1061 | static const bt_field *memberFieldByName(const bt_field * const libObjPtr, | |
1062 | const char * const name) noexcept | |
1063 | { | |
1064 | return bt_field_structure_borrow_member_field_by_name_const(libObjPtr, name); | |
1065 | } | |
1066 | }; | |
1067 | ||
b5f55e9f | 1068 | } /* namespace internal */ |
a1e31878 PP |
1069 | |
1070 | template <typename LibObjT> | |
1071 | class CommonStructureField final : public CommonField<LibObjT> | |
1072 | { | |
1073 | private: | |
1074 | using typename CommonField<LibObjT>::_LibObjPtr; | |
1075 | using typename CommonField<LibObjT>::_ThisCommonField; | |
1076 | using _Spec = internal::CommonStructureFieldSpec<LibObjT>; | |
1077 | ||
1078 | public: | |
8047a175 | 1079 | using Class = internal::DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>; |
a1e31878 PP |
1080 | |
1081 | explicit CommonStructureField(const _LibObjPtr libObjPtr) noexcept : | |
1082 | _ThisCommonField {libObjPtr} | |
1083 | { | |
1084 | BT_ASSERT_DBG(this->isStructure()); | |
1085 | } | |
1086 | ||
1087 | template <typename OtherLibObjT> | |
100fa861 | 1088 | CommonStructureField(const CommonStructureField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
1089 | _ThisCommonField {val} |
1090 | { | |
1091 | } | |
1092 | ||
1093 | template <typename OtherLibObjT> | |
ac30a470 | 1094 | CommonStructureField<LibObjT> operator=(const CommonStructureField<OtherLibObjT> val) noexcept |
a1e31878 PP |
1095 | { |
1096 | _ThisCommonField::operator=(val); | |
1097 | return *this; | |
1098 | } | |
1099 | ||
328a274a PP |
1100 | CommonStructureField<const bt_field> asConst() const noexcept |
1101 | { | |
1102 | return CommonStructureField<const bt_field> {*this}; | |
1103 | } | |
1104 | ||
dcb8ae9b | 1105 | Class cls() const noexcept |
a1e31878 | 1106 | { |
341a67c4 | 1107 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
1108 | } |
1109 | ||
c0b73c63 | 1110 | std::uint64_t length() const noexcept |
a1e31878 | 1111 | { |
c0b73c63 | 1112 | return this->cls().length(); |
a1e31878 PP |
1113 | } |
1114 | ||
dcb8ae9b | 1115 | CommonField<LibObjT> operator[](const std::uint64_t index) const noexcept |
a1e31878 | 1116 | { |
341a67c4 | 1117 | return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)}; |
a1e31878 PP |
1118 | } |
1119 | ||
dcb8ae9b | 1120 | nonstd::optional<CommonField<LibObjT>> operator[](const char * const name) const noexcept |
a1e31878 | 1121 | { |
341a67c4 | 1122 | const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name); |
a1e31878 PP |
1123 | |
1124 | if (libObjPtr) { | |
1125 | return CommonField<LibObjT> {libObjPtr}; | |
1126 | } | |
1127 | ||
1128 | return nonstd::nullopt; | |
1129 | } | |
1130 | ||
dcb8ae9b | 1131 | nonstd::optional<CommonField<LibObjT>> operator[](const std::string& name) const noexcept |
a1e31878 PP |
1132 | { |
1133 | return (*this)[name.data()]; | |
1134 | } | |
1135 | }; | |
1136 | ||
1137 | using StructureField = CommonStructureField<bt_field>; | |
1138 | using ConstStructureField = CommonStructureField<const bt_field>; | |
1139 | ||
1140 | namespace internal { | |
1141 | ||
4927bae7 PP |
1142 | struct StructureFieldTypeDescr |
1143 | { | |
1144 | using Const = ConstStructureField; | |
1145 | using NonConst = StructureField; | |
1146 | }; | |
1147 | ||
1148 | template <> | |
1149 | struct TypeDescr<StructureField> : public StructureFieldTypeDescr | |
1150 | { | |
1151 | }; | |
1152 | ||
1153 | template <> | |
1154 | struct TypeDescr<ConstStructureField> : public StructureFieldTypeDescr | |
1155 | { | |
1156 | }; | |
1157 | ||
a1e31878 PP |
1158 | template <typename LibObjT> |
1159 | struct CommonArrayFieldSpec; | |
1160 | ||
b5f55e9f | 1161 | /* Functions specific to mutable array fields */ |
a1e31878 PP |
1162 | template <> |
1163 | struct CommonArrayFieldSpec<bt_field> final | |
1164 | { | |
1165 | static bt_field *elementFieldByIndex(bt_field * const libObjPtr, | |
1166 | const std::uint64_t index) noexcept | |
1167 | { | |
1168 | return bt_field_array_borrow_element_field_by_index(libObjPtr, index); | |
1169 | } | |
1170 | }; | |
1171 | ||
b5f55e9f | 1172 | /* Functions specific to constant array fields */ |
a1e31878 PP |
1173 | template <> |
1174 | struct CommonArrayFieldSpec<const bt_field> final | |
1175 | { | |
1176 | static const bt_field *elementFieldByIndex(const bt_field * const libObjPtr, | |
1177 | const std::uint64_t index) noexcept | |
1178 | { | |
1179 | return bt_field_array_borrow_element_field_by_index_const(libObjPtr, index); | |
1180 | } | |
1181 | }; | |
1182 | ||
b5f55e9f | 1183 | } /* namespace internal */ |
a1e31878 PP |
1184 | |
1185 | template <typename LibObjT> | |
1186 | class CommonArrayField : public CommonField<LibObjT> | |
1187 | { | |
1188 | private: | |
1189 | using typename CommonField<LibObjT>::_ThisCommonField; | |
1190 | using _Spec = internal::CommonArrayFieldSpec<LibObjT>; | |
1191 | ||
1192 | protected: | |
1193 | using typename CommonField<LibObjT>::_LibObjPtr; | |
1194 | using _ThisCommonArrayField = CommonArrayField<LibObjT>; | |
1195 | ||
1196 | public: | |
8047a175 | 1197 | using Class = internal::DepType<LibObjT, ArrayFieldClass, ConstArrayFieldClass>; |
a1e31878 PP |
1198 | |
1199 | explicit CommonArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} | |
1200 | { | |
1201 | BT_ASSERT_DBG(this->isArray()); | |
1202 | } | |
1203 | ||
1204 | template <typename OtherLibObjT> | |
100fa861 | 1205 | CommonArrayField(const CommonArrayField<OtherLibObjT> val) noexcept : _ThisCommonField {val} |
a1e31878 PP |
1206 | { |
1207 | } | |
1208 | ||
1209 | template <typename OtherLibObjT> | |
ac30a470 | 1210 | _ThisCommonArrayField operator=(const CommonArrayField<OtherLibObjT> val) noexcept |
a1e31878 PP |
1211 | { |
1212 | _ThisCommonField::operator=(val); | |
1213 | return *this; | |
1214 | } | |
1215 | ||
328a274a PP |
1216 | CommonArrayField<const bt_field> asConst() const noexcept |
1217 | { | |
1218 | return CommonArrayField<const bt_field> {*this}; | |
1219 | } | |
1220 | ||
dcb8ae9b | 1221 | Class cls() const noexcept |
a1e31878 | 1222 | { |
341a67c4 | 1223 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
1224 | } |
1225 | ||
1226 | std::uint64_t length() const noexcept | |
1227 | { | |
341a67c4 | 1228 | return bt_field_array_get_length(this->libObjPtr()); |
a1e31878 PP |
1229 | } |
1230 | ||
dcb8ae9b | 1231 | CommonField<LibObjT> operator[](const std::uint64_t index) const noexcept |
a1e31878 | 1232 | { |
341a67c4 | 1233 | return CommonField<LibObjT> {_Spec::elementFieldByIndex(this->libObjPtr(), index)}; |
a1e31878 PP |
1234 | } |
1235 | }; | |
1236 | ||
1237 | using ArrayField = CommonArrayField<bt_field>; | |
1238 | using ConstArrayField = CommonArrayField<const bt_field>; | |
1239 | ||
4927bae7 PP |
1240 | namespace internal { |
1241 | ||
1242 | struct ArrayFieldTypeDescr | |
1243 | { | |
1244 | using Const = ConstArrayField; | |
1245 | using NonConst = ArrayField; | |
1246 | }; | |
1247 | ||
1248 | template <> | |
1249 | struct TypeDescr<ArrayField> : public ArrayFieldTypeDescr | |
1250 | { | |
1251 | }; | |
1252 | ||
1253 | template <> | |
1254 | struct TypeDescr<ConstArrayField> : public ArrayFieldTypeDescr | |
1255 | { | |
1256 | }; | |
1257 | ||
1258 | } /* namespace internal */ | |
1259 | ||
a1e31878 PP |
1260 | template <typename LibObjT> |
1261 | class CommonDynamicArrayField : public CommonArrayField<LibObjT> | |
1262 | { | |
1263 | private: | |
1264 | using typename CommonField<LibObjT>::_LibObjPtr; | |
1265 | using typename CommonArrayField<LibObjT>::_ThisCommonArrayField; | |
1266 | ||
1267 | public: | |
1268 | explicit CommonDynamicArrayField(const _LibObjPtr libObjPtr) noexcept : | |
1269 | _ThisCommonArrayField {libObjPtr} | |
1270 | { | |
1271 | BT_ASSERT_DBG(this->isDynamicArray()); | |
1272 | } | |
1273 | ||
1274 | template <typename OtherLibObjT> | |
100fa861 | 1275 | CommonDynamicArrayField(const CommonDynamicArrayField<OtherLibObjT> val) noexcept : |
a1e31878 PP |
1276 | _ThisCommonArrayField {val} |
1277 | { | |
1278 | } | |
1279 | ||
1280 | template <typename OtherLibObjT> | |
ac30a470 | 1281 | CommonDynamicArrayField<LibObjT> |
100fa861 | 1282 | operator=(const CommonDynamicArrayField<OtherLibObjT> val) noexcept |
a1e31878 PP |
1283 | { |
1284 | _ThisCommonArrayField::operator=(val); | |
1285 | return *this; | |
1286 | } | |
1287 | ||
328a274a PP |
1288 | CommonDynamicArrayField<const bt_field> asConst() const noexcept |
1289 | { | |
1290 | return CommonDynamicArrayField<const bt_field> {*this}; | |
1291 | } | |
1292 | ||
a1e31878 PP |
1293 | std::uint64_t length() const noexcept |
1294 | { | |
1295 | return _ThisCommonArrayField::length(); | |
1296 | } | |
1297 | ||
dcb8ae9b | 1298 | void length(const std::uint64_t length) const |
a1e31878 | 1299 | { |
5c895f64 PP |
1300 | static_assert(!std::is_const<LibObjT>::value, |
1301 | "Not available with `bt2::ConstDynamicArrayField`."); | |
a1e31878 | 1302 | |
341a67c4 | 1303 | const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length); |
a1e31878 PP |
1304 | |
1305 | if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) { | |
39278ebc | 1306 | throw MemoryError {}; |
a1e31878 PP |
1307 | } |
1308 | } | |
1309 | }; | |
1310 | ||
1311 | using DynamicArrayField = CommonDynamicArrayField<bt_field>; | |
1312 | using ConstDynamicArrayField = CommonDynamicArrayField<const bt_field>; | |
1313 | ||
1314 | namespace internal { | |
1315 | ||
4927bae7 PP |
1316 | struct DynamicArrayFieldTypeDescr |
1317 | { | |
1318 | using Const = ConstDynamicArrayField; | |
1319 | using NonConst = DynamicArrayField; | |
1320 | }; | |
1321 | ||
1322 | template <> | |
1323 | struct TypeDescr<DynamicArrayField> : public DynamicArrayFieldTypeDescr | |
1324 | { | |
1325 | }; | |
1326 | ||
1327 | template <> | |
1328 | struct TypeDescr<ConstDynamicArrayField> : public DynamicArrayFieldTypeDescr | |
1329 | { | |
1330 | }; | |
1331 | ||
a1e31878 PP |
1332 | template <typename LibObjT> |
1333 | struct CommonOptionFieldSpec; | |
1334 | ||
b5f55e9f | 1335 | /* Functions specific to mutable option fields */ |
a1e31878 PP |
1336 | template <> |
1337 | struct CommonOptionFieldSpec<bt_field> final | |
1338 | { | |
1339 | static bt_field *field(bt_field * const libObjPtr) noexcept | |
1340 | { | |
1341 | return bt_field_option_borrow_field(libObjPtr); | |
1342 | } | |
1343 | }; | |
1344 | ||
b5f55e9f | 1345 | /* Functions specific to constant option fields */ |
a1e31878 PP |
1346 | template <> |
1347 | struct CommonOptionFieldSpec<const bt_field> final | |
1348 | { | |
1349 | static const bt_field *field(const bt_field * const libObjPtr) noexcept | |
1350 | { | |
1351 | return bt_field_option_borrow_field_const(libObjPtr); | |
1352 | } | |
1353 | }; | |
1354 | ||
b5f55e9f | 1355 | } /* namespace internal */ |
a1e31878 PP |
1356 | |
1357 | template <typename LibObjT> | |
1358 | class CommonOptionField : public CommonField<LibObjT> | |
1359 | { | |
1360 | private: | |
1361 | using typename CommonField<LibObjT>::_LibObjPtr; | |
1362 | using typename CommonField<LibObjT>::_ThisCommonField; | |
1363 | using _Spec = internal::CommonOptionFieldSpec<LibObjT>; | |
1364 | ||
1365 | public: | |
8047a175 | 1366 | using Class = internal::DepType<LibObjT, OptionFieldClass, ConstOptionFieldClass>; |
a1e31878 PP |
1367 | |
1368 | explicit CommonOptionField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} | |
1369 | { | |
1370 | BT_ASSERT_DBG(this->isOption()); | |
1371 | } | |
1372 | ||
1373 | template <typename OtherLibObjT> | |
100fa861 | 1374 | CommonOptionField(const CommonOptionField<OtherLibObjT> val) noexcept : _ThisCommonField {val} |
a1e31878 PP |
1375 | { |
1376 | } | |
1377 | ||
1378 | template <typename OtherLibObjT> | |
ac30a470 | 1379 | CommonOptionField<LibObjT> operator=(const CommonOptionField<OtherLibObjT> val) noexcept |
a1e31878 PP |
1380 | { |
1381 | _ThisCommonField::operator=(val); | |
1382 | return *this; | |
1383 | } | |
1384 | ||
328a274a PP |
1385 | CommonOptionField<const bt_field> asConst() const noexcept |
1386 | { | |
1387 | return CommonOptionField<const bt_field> {*this}; | |
1388 | } | |
1389 | ||
dcb8ae9b | 1390 | Class cls() const noexcept |
a1e31878 | 1391 | { |
341a67c4 | 1392 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
1393 | } |
1394 | ||
dcb8ae9b | 1395 | void hasField(const bool hasField) const noexcept |
a1e31878 | 1396 | { |
5c895f64 PP |
1397 | static_assert(!std::is_const<LibObjT>::value, |
1398 | "Not available with `bt2::ConstOptionField`."); | |
a1e31878 | 1399 | |
341a67c4 | 1400 | bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField)); |
a1e31878 PP |
1401 | } |
1402 | ||
1403 | bool hasField() const noexcept | |
1404 | { | |
a5edf52d | 1405 | return this->field().has_value(); |
a1e31878 PP |
1406 | } |
1407 | ||
dcb8ae9b | 1408 | nonstd::optional<CommonField<LibObjT>> field() const noexcept |
a1e31878 | 1409 | { |
341a67c4 | 1410 | const auto libObjPtr = _Spec::field(this->libObjPtr()); |
a1e31878 PP |
1411 | |
1412 | if (libObjPtr) { | |
1413 | return CommonField<LibObjT> {libObjPtr}; | |
1414 | } | |
1415 | ||
1416 | return nonstd::nullopt; | |
1417 | } | |
1418 | }; | |
1419 | ||
1420 | using OptionField = CommonOptionField<bt_field>; | |
1421 | using ConstOptionField = CommonOptionField<const bt_field>; | |
1422 | ||
1423 | namespace internal { | |
1424 | ||
4927bae7 PP |
1425 | struct OptionFieldTypeDescr |
1426 | { | |
1427 | using Const = ConstOptionField; | |
1428 | using NonConst = OptionField; | |
1429 | }; | |
1430 | ||
1431 | template <> | |
1432 | struct TypeDescr<OptionField> : public OptionFieldTypeDescr | |
1433 | { | |
1434 | }; | |
1435 | ||
1436 | template <> | |
1437 | struct TypeDescr<ConstOptionField> : public OptionFieldTypeDescr | |
1438 | { | |
1439 | }; | |
1440 | ||
a1e31878 PP |
1441 | template <typename LibObjT> |
1442 | struct CommonVariantFieldSpec; | |
1443 | ||
b5f55e9f | 1444 | /* Functions specific to mutable variant fields */ |
a1e31878 PP |
1445 | template <> |
1446 | struct CommonVariantFieldSpec<bt_field> final | |
1447 | { | |
1448 | static bt_field *selectedOptionField(bt_field * const libObjPtr) noexcept | |
1449 | { | |
1450 | return bt_field_variant_borrow_selected_option_field(libObjPtr); | |
1451 | } | |
1452 | }; | |
1453 | ||
b5f55e9f | 1454 | /* Functions specific to constant variant fields */ |
a1e31878 PP |
1455 | template <> |
1456 | struct CommonVariantFieldSpec<const bt_field> final | |
1457 | { | |
1458 | static const bt_field *selectedOptionField(const bt_field * const libObjPtr) noexcept | |
1459 | { | |
1460 | return bt_field_variant_borrow_selected_option_field_const(libObjPtr); | |
1461 | } | |
1462 | }; | |
1463 | ||
b5f55e9f | 1464 | } /* namespace internal */ |
a1e31878 PP |
1465 | |
1466 | template <typename LibObjT> | |
1467 | class CommonVariantField : public CommonField<LibObjT> | |
1468 | { | |
1469 | private: | |
1470 | using typename CommonField<LibObjT>::_LibObjPtr; | |
1471 | using typename CommonField<LibObjT>::_ThisCommonField; | |
1472 | using _Spec = internal::CommonVariantFieldSpec<LibObjT>; | |
1473 | ||
1474 | public: | |
8047a175 | 1475 | using Class = internal::DepType<LibObjT, VariantFieldClass, ConstVariantFieldClass>; |
a1e31878 PP |
1476 | |
1477 | explicit CommonVariantField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr} | |
1478 | { | |
1479 | BT_ASSERT_DBG(this->isVariant()); | |
1480 | } | |
1481 | ||
1482 | template <typename OtherLibObjT> | |
100fa861 | 1483 | CommonVariantField(const CommonVariantField<OtherLibObjT> val) noexcept : _ThisCommonField {val} |
a1e31878 PP |
1484 | { |
1485 | } | |
1486 | ||
1487 | template <typename OtherLibObjT> | |
ac30a470 | 1488 | CommonVariantField<LibObjT> operator=(const CommonVariantField<OtherLibObjT> val) noexcept |
a1e31878 PP |
1489 | { |
1490 | _ThisCommonField::operator=(val); | |
1491 | return *this; | |
1492 | } | |
1493 | ||
328a274a PP |
1494 | CommonVariantField<const bt_field> asConst() const noexcept |
1495 | { | |
1496 | return CommonVariantField<const bt_field> {*this}; | |
1497 | } | |
1498 | ||
dcb8ae9b | 1499 | Class cls() const noexcept |
a1e31878 | 1500 | { |
341a67c4 | 1501 | return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())}; |
a1e31878 PP |
1502 | } |
1503 | ||
dcb8ae9b | 1504 | void selectOption(const std::uint64_t index) const noexcept |
a1e31878 | 1505 | { |
5c895f64 PP |
1506 | static_assert(!std::is_const<LibObjT>::value, |
1507 | "Not available with `bt2::ConstVariantField`."); | |
a1e31878 | 1508 | |
341a67c4 | 1509 | static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index)); |
a1e31878 PP |
1510 | } |
1511 | ||
dcb8ae9b | 1512 | CommonField<LibObjT> selectedOptionField() const noexcept |
a1e31878 | 1513 | { |
341a67c4 | 1514 | return CommonField<LibObjT> {_Spec::selectedOptionField(this->libObjPtr())}; |
a1e31878 PP |
1515 | } |
1516 | ||
1517 | std::uint64_t selectedOptionIndex() const noexcept | |
1518 | { | |
341a67c4 | 1519 | return bt_field_variant_get_selected_option_index(this->libObjPtr()); |
a1e31878 PP |
1520 | } |
1521 | }; | |
1522 | ||
1523 | using VariantField = CommonVariantField<bt_field>; | |
1524 | using ConstVariantField = CommonVariantField<const bt_field>; | |
1525 | ||
4927bae7 PP |
1526 | namespace internal { |
1527 | ||
1528 | struct VariantFieldTypeDescr | |
1529 | { | |
1530 | using Const = ConstVariantField; | |
1531 | using NonConst = VariantField; | |
1532 | }; | |
1533 | ||
1534 | template <> | |
1535 | struct TypeDescr<VariantField> : public VariantFieldTypeDescr | |
1536 | { | |
1537 | }; | |
1538 | ||
1539 | template <> | |
1540 | struct TypeDescr<ConstVariantField> : public VariantFieldTypeDescr | |
1541 | { | |
1542 | }; | |
1543 | ||
1544 | } /* namespace internal */ | |
1545 | ||
a1e31878 PP |
1546 | template <typename LibObjT> |
1547 | CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept | |
1548 | { | |
1549 | BT_ASSERT_DBG(this->isBool()); | |
341a67c4 | 1550 | return CommonBoolField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1551 | } |
1552 | ||
1553 | template <typename LibObjT> | |
1554 | CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept | |
1555 | { | |
1556 | BT_ASSERT_DBG(this->isBitArray()); | |
341a67c4 | 1557 | return CommonBitArrayField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1558 | } |
1559 | ||
1560 | template <typename LibObjT> | |
1561 | CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept | |
1562 | { | |
1563 | BT_ASSERT_DBG(this->isUnsignedInteger()); | |
341a67c4 | 1564 | return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1565 | } |
1566 | ||
1567 | template <typename LibObjT> | |
1568 | CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept | |
1569 | { | |
1570 | BT_ASSERT_DBG(this->isSignedInteger()); | |
341a67c4 | 1571 | return CommonSignedIntegerField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1572 | } |
1573 | ||
1574 | template <typename LibObjT> | |
1575 | CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept | |
1576 | { | |
1577 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); | |
341a67c4 | 1578 | return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1579 | } |
1580 | ||
1581 | template <typename LibObjT> | |
1582 | CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept | |
1583 | { | |
1584 | BT_ASSERT_DBG(this->isSignedEnumeration()); | |
341a67c4 | 1585 | return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1586 | } |
1587 | ||
1588 | template <typename LibObjT> | |
1589 | CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept | |
1590 | { | |
1591 | BT_ASSERT_DBG(this->isSinglePrecisionReal()); | |
341a67c4 | 1592 | return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1593 | } |
1594 | ||
1595 | template <typename LibObjT> | |
1596 | CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept | |
1597 | { | |
1598 | BT_ASSERT_DBG(this->isDoublePrecisionReal()); | |
341a67c4 | 1599 | return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1600 | } |
1601 | ||
1602 | template <typename LibObjT> | |
1603 | CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept | |
1604 | { | |
1605 | BT_ASSERT_DBG(this->isString()); | |
341a67c4 | 1606 | return CommonStringField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1607 | } |
1608 | ||
1609 | template <typename LibObjT> | |
1610 | CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept | |
1611 | { | |
1612 | BT_ASSERT_DBG(this->isStructure()); | |
341a67c4 | 1613 | return CommonStructureField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1614 | } |
1615 | ||
1616 | template <typename LibObjT> | |
1617 | CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept | |
1618 | { | |
1619 | BT_ASSERT_DBG(this->isArray()); | |
341a67c4 | 1620 | return CommonArrayField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1621 | } |
1622 | ||
1623 | template <typename LibObjT> | |
1624 | CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept | |
1625 | { | |
1626 | BT_ASSERT_DBG(this->isDynamicArray()); | |
341a67c4 | 1627 | return CommonDynamicArrayField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1628 | } |
1629 | ||
1630 | template <typename LibObjT> | |
1631 | CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept | |
1632 | { | |
1633 | BT_ASSERT_DBG(this->isOption()); | |
341a67c4 | 1634 | return CommonOptionField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1635 | } |
1636 | ||
1637 | template <typename LibObjT> | |
1638 | CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept | |
1639 | { | |
1640 | BT_ASSERT_DBG(this->isVariant()); | |
341a67c4 | 1641 | return CommonVariantField<LibObjT> {this->libObjPtr()}; |
a1e31878 PP |
1642 | } |
1643 | ||
b5f55e9f | 1644 | } /* namespace bt2 */ |
a1e31878 | 1645 | |
b5f55e9f | 1646 | #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_HPP */ |