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