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