Change naming convention for enum class enumerators
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
CommitLineData
74fc764d
PP
1/*
2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8#define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
9
74fc764d 10#include <cstdint>
c802cacb
SM
11#include <type_traits>
12
74fc764d
PP
13#include <babeltrace2/babeltrace.h>
14
1c5ea5eb 15#include "common/macros.h"
e7f0f07b 16#include "cpp-common/bt2c/c-string-view.hpp"
c022776a 17#include "cpp-common/bt2s/optional.hpp"
c802cacb 18
0d218157 19#include "borrowed-object.hpp"
74fc764d 20#include "clock-class.hpp"
74fc764d
PP
21#include "field-class.hpp"
22#include "field.hpp"
74fc764d 23#include "internal/utils.hpp"
ca61ecbc 24#include "optional-borrowed-object.hpp"
7f5cdaf0 25#include "shared-object.hpp"
c802cacb 26#include "value.hpp"
74fc764d
PP
27
28namespace bt2 {
29
30template <typename LibObjT>
31class CommonEvent;
32
33template <typename LibObjT>
34class CommonPacket;
35
36template <typename LibObjT>
37class CommonStream;
38
39template <typename LibObjT>
40class CommonTrace;
41
42template <typename LibObjT>
43class CommonEventClass;
44
45template <typename LibObjT>
46class CommonStreamClass;
47
48template <typename LibObjT>
49class CommonTraceClass;
50
51namespace internal {
52
53template <typename LibObjT>
54struct CommonEventSpec;
55
b5f55e9f 56/* Functions specific to mutable events */
74fc764d
PP
57template <>
58struct CommonEventSpec<bt_event> final
59{
60 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
61 {
62 return bt_event_borrow_class(libObjPtr);
63 }
64
65 static bt_stream *stream(bt_event * const libObjPtr) noexcept
66 {
67 return bt_event_borrow_stream(libObjPtr);
68 }
69
70 static bt_packet *packet(bt_event * const libObjPtr) noexcept
71 {
72 return bt_event_borrow_packet(libObjPtr);
73 }
74
75 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
76 {
77 return bt_event_borrow_payload_field(libObjPtr);
78 }
79
80 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
81 {
82 return bt_event_borrow_specific_context_field(libObjPtr);
83 }
84
85 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
86 {
87 return bt_event_borrow_common_context_field(libObjPtr);
88 }
89};
90
b5f55e9f 91/* Functions specific to constant events */
74fc764d
PP
92template <>
93struct CommonEventSpec<const bt_event> final
94{
95 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
96 {
97 return bt_event_borrow_class_const(libObjPtr);
98 }
99
100 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
101 {
102 return bt_event_borrow_stream_const(libObjPtr);
103 }
104
105 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
106 {
107 return bt_event_borrow_packet_const(libObjPtr);
108 }
109
110 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
111 {
112 return bt_event_borrow_payload_field_const(libObjPtr);
113 }
114
115 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
116 {
117 return bt_event_borrow_specific_context_field_const(libObjPtr);
118 }
119
120 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
121 {
122 return bt_event_borrow_common_context_field_const(libObjPtr);
123 }
124};
125
8047a175
PP
126template <typename LibObjT>
127using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
128
b5f55e9f 129} /* namespace internal */
74fc764d
PP
130
131template <typename LibObjT>
0d218157 132class CommonEvent final : public BorrowedObject<LibObjT>
74fc764d
PP
133{
134private:
0d218157 135 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 136 using _Spec = internal::CommonEventSpec<LibObjT>;
8047a175
PP
137 using _Packet = internal::DepPacket<LibObjT>;
138 using _Stream = internal::DepStream<LibObjT>;
139 using _StructureField = internal::DepStructField<LibObjT>;
74fc764d
PP
140
141public:
d246c457
PP
142 using typename BorrowedObject<LibObjT>::LibObjPtr;
143
8047a175
PP
144 using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
145 CommonEventClass<const bt_event_class>>;
74fc764d 146
d246c457 147 explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
148 {
149 }
150
151 template <typename OtherLibObjT>
0d218157 152 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
74fc764d
PP
153 {
154 }
155
156 template <typename OtherLibObjT>
ac30a470 157 CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
74fc764d 158 {
0d218157 159 _ThisBorrowedObject::operator=(event);
74fc764d
PP
160 return *this;
161 }
162
328a274a
PP
163 CommonEvent<const bt_event> asConst() const noexcept
164 {
165 return CommonEvent<const bt_event> {*this};
166 }
167
dcb8ae9b
PP
168 Class cls() const noexcept;
169 _Stream stream() const noexcept;
ca61ecbc 170 OptionalBorrowedObject<_Packet> packet() const noexcept;
74fc764d 171
ca61ecbc 172 OptionalBorrowedObject<_StructureField> payloadField() const noexcept
74fc764d 173 {
ca61ecbc 174 return _Spec::payloadField(this->libObjPtr());
74fc764d
PP
175 }
176
ca61ecbc 177 OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
74fc764d 178 {
ca61ecbc 179 return _Spec::specificContextField(this->libObjPtr());
74fc764d
PP
180 }
181
ca61ecbc 182 OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
74fc764d 183 {
ca61ecbc 184 return _Spec::commonContextField(this->libObjPtr());
74fc764d
PP
185 }
186};
187
188using Event = CommonEvent<bt_event>;
189using ConstEvent = CommonEvent<const bt_event>;
190
191namespace internal {
192
4927bae7
PP
193struct EventTypeDescr
194{
195 using Const = ConstEvent;
196 using NonConst = Event;
197};
198
199template <>
200struct TypeDescr<Event> : public EventTypeDescr
201{
202};
203
204template <>
205struct TypeDescr<ConstEvent> : public EventTypeDescr
206{
207};
208
74fc764d
PP
209struct PacketRefFuncs final
210{
c677c492 211 static void get(const bt_packet * const libObjPtr) noexcept
74fc764d
PP
212 {
213 bt_packet_get_ref(libObjPtr);
214 }
215
c677c492 216 static void put(const bt_packet * const libObjPtr) noexcept
74fc764d
PP
217 {
218 bt_packet_put_ref(libObjPtr);
219 }
220};
221
222template <typename LibObjT>
223struct CommonPacketSpec;
224
b5f55e9f 225/* Functions specific to mutable packets */
74fc764d
PP
226template <>
227struct CommonPacketSpec<bt_packet> final
228{
229 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
230 {
231 return bt_packet_borrow_stream(libObjPtr);
232 }
233
234 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
235 {
236 return bt_packet_borrow_context_field(libObjPtr);
237 }
238};
239
b5f55e9f 240/* Functions specific to constant packets */
74fc764d
PP
241template <>
242struct CommonPacketSpec<const bt_packet> final
243{
244 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
245 {
246 return bt_packet_borrow_stream_const(libObjPtr);
247 }
248
249 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
250 {
251 return bt_packet_borrow_context_field_const(libObjPtr);
252 }
253};
254
b5f55e9f 255} /* namespace internal */
74fc764d
PP
256
257template <typename LibObjT>
0d218157 258class CommonPacket final : public BorrowedObject<LibObjT>
74fc764d
PP
259{
260private:
0d218157 261 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 262 using _Spec = internal::CommonPacketSpec<LibObjT>;
8047a175
PP
263 using _Stream = internal::DepStream<LibObjT>;
264 using _StructureField = internal::DepStructField<LibObjT>;
74fc764d
PP
265
266public:
d246c457 267 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 268 using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
74fc764d 269
d246c457 270 explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
271 {
272 }
273
274 template <typename OtherLibObjT>
0d218157 275 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
74fc764d
PP
276 {
277 }
278
279 template <typename OtherLibObjT>
ac30a470 280 CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
74fc764d 281 {
0d218157 282 _ThisBorrowedObject::operator=(packet);
74fc764d
PP
283 return *this;
284 }
285
328a274a
PP
286 CommonPacket<const bt_packet> asConst() const noexcept
287 {
288 return CommonPacket<const bt_packet> {*this};
289 }
290
dcb8ae9b 291 _Stream stream() const noexcept;
74fc764d 292
ca61ecbc 293 OptionalBorrowedObject<_StructureField> contextField() const noexcept
74fc764d 294 {
ca61ecbc 295 return _Spec::contextField(this->libObjPtr());
74fc764d
PP
296 }
297
298 Shared shared() const noexcept
299 {
c9c0b6e2 300 return Shared::createWithRef(*this);
74fc764d
PP
301 }
302};
303
304using Packet = CommonPacket<bt_packet>;
305using ConstPacket = CommonPacket<const bt_packet>;
306
4927bae7
PP
307namespace internal {
308
309struct PacketTypeDescr
310{
311 using Const = ConstPacket;
312 using NonConst = Packet;
313};
314
315template <>
316struct TypeDescr<Packet> : public PacketTypeDescr
317{
318};
319
320template <>
321struct TypeDescr<ConstPacket> : public PacketTypeDescr
322{
323};
324
325} /* namespace internal */
326
74fc764d 327template <typename LibObjT>
ca61ecbc
PP
328OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
329CommonEvent<LibObjT>::packet() const noexcept
74fc764d 330{
ca61ecbc 331 return _Spec::packet(this->libObjPtr());
74fc764d
PP
332}
333
334namespace internal {
335
336struct StreamRefFuncs final
337{
c677c492 338 static void get(const bt_stream * const libObjPtr) noexcept
74fc764d
PP
339 {
340 bt_stream_get_ref(libObjPtr);
341 }
342
c677c492 343 static void put(const bt_stream * const libObjPtr) noexcept
74fc764d
PP
344 {
345 bt_stream_put_ref(libObjPtr);
346 }
347};
348
349template <typename LibObjT>
350struct CommonStreamSpec;
351
b5f55e9f 352/* Functions specific to mutable streams */
74fc764d
PP
353template <>
354struct CommonStreamSpec<bt_stream> final
355{
356 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
357 {
358 return bt_stream_borrow_class(libObjPtr);
359 }
360
361 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
362 {
363 return bt_stream_borrow_trace(libObjPtr);
364 }
365
366 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
367 {
368 return bt_stream_borrow_user_attributes(libObjPtr);
369 }
370};
371
b5f55e9f 372/* Functions specific to constant streams */
74fc764d
PP
373template <>
374struct CommonStreamSpec<const bt_stream> final
375{
376 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
377 {
378 return bt_stream_borrow_class_const(libObjPtr);
379 }
380
381 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
382 {
383 return bt_stream_borrow_trace_const(libObjPtr);
384 }
385
386 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
387 {
388 return bt_stream_borrow_user_attributes_const(libObjPtr);
389 }
390};
391
b5f55e9f 392} /* namespace internal */
74fc764d
PP
393
394template <typename LibObjT>
0d218157 395class CommonStream final : public BorrowedObject<LibObjT>
74fc764d
PP
396{
397private:
0d218157 398 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 399 using _Spec = internal::CommonStreamSpec<LibObjT>;
8047a175 400 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
74fc764d
PP
401
402public:
d246c457 403 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 404 using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
8047a175 405 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 406
8047a175
PP
407 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
408 CommonStreamClass<const bt_stream_class>>;
74fc764d 409
d246c457 410 explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
411 {
412 }
413
414 template <typename OtherLibObjT>
0d218157 415 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
74fc764d
PP
416 {
417 }
418
419 template <typename OtherLibObjT>
ac30a470 420 CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
74fc764d 421 {
0d218157 422 _ThisBorrowedObject::operator=(stream);
74fc764d
PP
423 return *this;
424 }
425
328a274a
PP
426 CommonStream<const bt_stream> asConst() const noexcept
427 {
428 return CommonStream<const bt_stream> {*this};
429 }
430
dcb8ae9b 431 Packet::Shared createPacket() const
74fc764d 432 {
5c895f64 433 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
74fc764d 434
341a67c4 435 const auto libObjPtr = bt_packet_create(this->libObjPtr());
74fc764d
PP
436
437 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 438 return Packet::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
439 }
440
dcb8ae9b
PP
441 Class cls() const noexcept;
442 _Trace trace() const noexcept;
74fc764d
PP
443
444 std::uint64_t id() const noexcept
445 {
341a67c4 446 return bt_stream_get_id(this->libObjPtr());
74fc764d
PP
447 }
448
2a24eba8 449 CommonStream name(const bt2c::CStringView name) const
74fc764d 450 {
5c895f64 451 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
74fc764d 452
341a67c4 453 const auto status = bt_stream_set_name(this->libObjPtr(), name);
74fc764d
PP
454
455 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 456 throw MemoryError {};
74fc764d 457 }
2a24eba8
SM
458
459 return *this;
74fc764d
PP
460 }
461
e7f0f07b 462 bt2c::CStringView name() const noexcept
74fc764d 463 {
5cc5088c 464 return bt_stream_get_name(this->libObjPtr());
74fc764d
PP
465 }
466
467 template <typename LibValT>
2a24eba8 468 CommonStream userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 469 {
5c895f64 470 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
74fc764d 471
341a67c4 472 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2a24eba8 473 return *this;
74fc764d
PP
474 }
475
dcb8ae9b 476 UserAttributes userAttributes() const noexcept
74fc764d 477 {
341a67c4 478 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
479 }
480
481 Shared shared() const noexcept
482 {
c9c0b6e2 483 return Shared::createWithRef(*this);
74fc764d
PP
484 }
485};
486
487using Stream = CommonStream<bt_stream>;
488using ConstStream = CommonStream<const bt_stream>;
489
4927bae7
PP
490namespace internal {
491
492struct StreamTypeDescr
493{
494 using Const = ConstStream;
495 using NonConst = Stream;
496};
497
498template <>
499struct TypeDescr<Stream> : public StreamTypeDescr
500{
501};
502
503template <>
504struct TypeDescr<ConstStream> : public StreamTypeDescr
505{
506};
507
508} /* namespace internal */
509
74fc764d 510template <typename LibObjT>
dcb8ae9b 511typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
74fc764d 512{
341a67c4 513 return _Stream {_Spec::stream(this->libObjPtr())};
74fc764d
PP
514}
515
516template <typename LibObjT>
dcb8ae9b 517typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
74fc764d 518{
341a67c4 519 return _Stream {_Spec::stream(this->libObjPtr())};
74fc764d
PP
520}
521
522namespace internal {
523
524struct TraceRefFuncs final
525{
c677c492 526 static void get(const bt_trace * const libObjPtr) noexcept
74fc764d
PP
527 {
528 bt_trace_get_ref(libObjPtr);
529 }
530
c677c492 531 static void put(const bt_trace * const libObjPtr) noexcept
74fc764d
PP
532 {
533 bt_trace_put_ref(libObjPtr);
534 }
535};
536
537template <typename LibObjT>
538struct CommonTraceSpec;
539
b5f55e9f 540/* Functions specific to mutable traces */
74fc764d
PP
541template <>
542struct CommonTraceSpec<bt_trace> final
543{
544 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
545 {
546 return bt_trace_borrow_class(libObjPtr);
547 }
548
549 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
550 {
551 return bt_trace_borrow_stream_by_index(libObjPtr, index);
552 }
553
554 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
555 {
556 return bt_trace_borrow_stream_by_id(libObjPtr, id);
557 }
558
559 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
560 {
561 return bt_trace_borrow_user_attributes(libObjPtr);
562 }
563};
564
b5f55e9f 565/* Functions specific to constant traces */
74fc764d
PP
566template <>
567struct CommonTraceSpec<const bt_trace> final
568{
569 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
570 {
571 return bt_trace_borrow_class_const(libObjPtr);
572 }
573
574 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
575 const std::uint64_t index) noexcept
576 {
577 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
578 }
579
580 static const bt_stream *streamById(const bt_trace * const libObjPtr,
581 const std::uint64_t id) noexcept
582 {
583 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
584 }
585
586 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
587 {
588 return bt_trace_borrow_user_attributes_const(libObjPtr);
589 }
590};
591
b5f55e9f 592} /* namespace internal */
74fc764d
PP
593
594template <typename LibObjT>
0d218157 595class CommonTrace final : public BorrowedObject<LibObjT>
74fc764d 596{
74fc764d 597private:
0d218157 598 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 599 using _Spec = internal::CommonTraceSpec<LibObjT>;
8047a175 600 using _Stream = internal::DepStream<LibObjT>;
74fc764d
PP
601
602public:
d246c457 603 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 604 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
8047a175 605 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 606
8047a175
PP
607 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
608 CommonTraceClass<const bt_trace_class>>;
74fc764d
PP
609
610 struct ConstEnvironmentEntry
611 {
e7f0f07b 612 bt2c::CStringView name;
74fc764d
PP
613 ConstValue value;
614 };
615
d246c457 616 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
617 {
618 }
619
620 template <typename OtherLibObjT>
0d218157 621 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
74fc764d
PP
622 {
623 }
624
625 template <typename OtherLibObjT>
ac30a470 626 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
74fc764d 627 {
0d218157 628 _ThisBorrowedObject::operator=(trace);
74fc764d
PP
629 return *this;
630 }
631
328a274a
PP
632 CommonTrace<const bt_trace> asConst() const noexcept
633 {
634 return CommonTrace<const bt_trace> {*this};
635 }
636
dcb8ae9b 637 Class cls() const noexcept;
74fc764d 638
2a24eba8 639 CommonTrace name(const bt2c::CStringView name) const
74fc764d 640 {
5c895f64 641 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 642
341a67c4 643 const auto status = bt_trace_set_name(this->libObjPtr(), name);
74fc764d
PP
644
645 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 646 throw MemoryError {};
74fc764d 647 }
2a24eba8
SM
648
649 return *this;
74fc764d
PP
650 }
651
e7f0f07b 652 bt2c::CStringView name() const noexcept
74fc764d 653 {
5cc5088c 654 return bt_trace_get_name(this->libObjPtr());
74fc764d
PP
655 }
656
2a24eba8 657 CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept
74fc764d 658 {
81d250db 659 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
2a24eba8 660 return *this;
74fc764d
PP
661 }
662
c022776a 663 bt2s::optional<bt2c::UuidView> uuid() const noexcept
74fc764d 664 {
341a67c4 665 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
74fc764d
PP
666
667 if (uuid) {
094bf3f2 668 return bt2c::UuidView {uuid};
74fc764d
PP
669 }
670
c022776a 671 return bt2s::nullopt;
74fc764d
PP
672 }
673
c0b73c63 674 std::uint64_t length() const noexcept
74fc764d 675 {
341a67c4 676 return bt_trace_get_stream_count(this->libObjPtr());
74fc764d
PP
677 }
678
dcb8ae9b 679 _Stream operator[](const std::uint64_t index) const noexcept
74fc764d 680 {
341a67c4 681 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
74fc764d
PP
682 }
683
ca61ecbc 684 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
74fc764d 685 {
ca61ecbc 686 return _Spec::streamById(this->libObjPtr(), id);
74fc764d
PP
687 }
688
2a24eba8 689 CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
74fc764d 690 {
5c895f64 691 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 692
341a67c4 693 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
74fc764d
PP
694
695 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
39278ebc 696 throw MemoryError {};
74fc764d 697 }
2a24eba8
SM
698
699 return *this;
74fc764d
PP
700 }
701
2a24eba8 702 CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
74fc764d 703 {
5c895f64 704 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 705
341a67c4 706 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
74fc764d
PP
707
708 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
39278ebc 709 throw MemoryError {};
74fc764d 710 }
2a24eba8
SM
711
712 return *this;
74fc764d
PP
713 }
714
74fc764d
PP
715 std::uint64_t environmentSize() const noexcept
716 {
341a67c4 717 return bt_trace_get_environment_entry_count(this->libObjPtr());
74fc764d
PP
718 }
719
720 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
721 {
722 const char *name;
723 const bt_value *libObjPtr;
724
341a67c4 725 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
74fc764d
PP
726 &libObjPtr);
727 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
728 }
729
15030982 730 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
74fc764d 731 {
ca61ecbc 732 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
74fc764d
PP
733 }
734
74fc764d 735 template <typename LibValT>
2a24eba8 736 CommonTrace userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 737 {
5c895f64 738 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 739
341a67c4 740 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2a24eba8 741 return *this;
74fc764d
PP
742 }
743
dcb8ae9b 744 UserAttributes userAttributes() const noexcept
74fc764d 745 {
341a67c4 746 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
747 }
748
749 Shared shared() const noexcept
750 {
c9c0b6e2 751 return Shared::createWithRef(*this);
74fc764d
PP
752 }
753};
754
755using Trace = CommonTrace<bt_trace>;
756using ConstTrace = CommonTrace<const bt_trace>;
757
4927bae7
PP
758namespace internal {
759
760struct TraceTypeDescr
761{
762 using Const = ConstTrace;
763 using NonConst = Trace;
764};
765
766template <>
767struct TypeDescr<Trace> : public TraceTypeDescr
768{
769};
770
771template <>
772struct TypeDescr<ConstTrace> : public TraceTypeDescr
773{
774};
775
776} /* namespace internal */
777
74fc764d 778template <typename LibObjT>
dcb8ae9b 779typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
74fc764d 780{
341a67c4 781 return _Trace {_Spec::trace(this->libObjPtr())};
74fc764d
PP
782}
783
784namespace internal {
785
786struct EventClassRefFuncs final
787{
c677c492 788 static void get(const bt_event_class * const libObjPtr) noexcept
74fc764d
PP
789 {
790 bt_event_class_get_ref(libObjPtr);
791 }
792
c677c492 793 static void put(const bt_event_class * const libObjPtr) noexcept
74fc764d
PP
794 {
795 bt_event_class_put_ref(libObjPtr);
796 }
797};
798
799template <typename LibObjT>
800struct CommonEventClassSpec;
801
b5f55e9f 802/* Functions specific to mutable event classes */
74fc764d
PP
803template <>
804struct CommonEventClassSpec<bt_event_class> final
805{
806 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
807 {
808 return bt_event_class_borrow_stream_class(libObjPtr);
809 }
810
811 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
812 {
813 return bt_event_class_borrow_payload_field_class(libObjPtr);
814 }
815
816 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
817 {
818 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
819 }
820
821 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
822 {
823 return bt_event_class_borrow_user_attributes(libObjPtr);
824 }
825};
826
b5f55e9f 827/* Functions specific to constant event classes */
74fc764d
PP
828template <>
829struct CommonEventClassSpec<const bt_event_class> final
830{
831 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
832 {
833 return bt_event_class_borrow_stream_class_const(libObjPtr);
834 }
835
836 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
837 {
838 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
839 }
840
841 static const bt_field_class *
842 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
843 {
844 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
845 }
846
847 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
848 {
849 return bt_event_class_borrow_user_attributes_const(libObjPtr);
850 }
851};
852
8047a175
PP
853template <typename LibObjT>
854using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
855
b5f55e9f 856} /* namespace internal */
74fc764d
PP
857
858template <typename LibObjT>
0d218157 859class CommonEventClass final : public BorrowedObject<LibObjT>
74fc764d
PP
860{
861private:
0d218157 862 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 863 using _Spec = internal::CommonEventClassSpec<LibObjT>;
8047a175 864 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
74fc764d 865
8047a175
PP
866 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
867 CommonStreamClass<const bt_stream_class>>;
74fc764d
PP
868
869public:
d246c457 870 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 871 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
8047a175 872 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 873
1c5ea5eb
SM
874 /* Avoid `-Wshadow` error on GCC, conflicting with `bt2::Error` */
875 BT_DIAG_PUSH
876 BT_DIAG_IGNORE_SHADOW
877
74fc764d
PP
878 enum class LogLevel
879 {
1c5ea5eb
SM
880 Emergency = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
881 Alert = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
882 Critical = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
883 Error = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
884 Warning = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
885 Notice = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
886 Info = BT_EVENT_CLASS_LOG_LEVEL_INFO,
887 DebugSystem = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
888 DebugProgram = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
889 DebugProcess = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
890 DebugModule = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
891 DebugUnit = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
892 DebugFunction = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
893 DebugLine = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
894 Debug = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
74fc764d
PP
895 };
896
1c5ea5eb
SM
897 BT_DIAG_POP
898
d246c457 899 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
900 {
901 }
902
903 template <typename OtherLibObjT>
100fa861 904 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
0d218157 905 _ThisBorrowedObject {eventClass}
74fc764d
PP
906 {
907 }
908
909 template <typename OtherLibObjT>
ac30a470 910 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
74fc764d 911 {
0d218157 912 _ThisBorrowedObject::operator=(eventClass);
74fc764d
PP
913 return *this;
914 }
915
328a274a
PP
916 CommonEventClass<const bt_event_class> asConst() const noexcept
917 {
918 return CommonEventClass<const bt_event_class> {*this};
919 }
920
dcb8ae9b 921 _StreamClass streamClass() const noexcept;
74fc764d
PP
922
923 std::uint64_t id() const noexcept
924 {
341a67c4 925 return bt_event_class_get_id(this->libObjPtr());
74fc764d
PP
926 }
927
2a24eba8 928 CommonEventClass name(const bt2c::CStringView name) const
74fc764d 929 {
5c895f64 930 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 931
341a67c4 932 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
74fc764d
PP
933
934 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 935 throw MemoryError {};
74fc764d 936 }
2a24eba8
SM
937
938 return *this;
74fc764d
PP
939 }
940
e7f0f07b 941 bt2c::CStringView name() const noexcept
74fc764d 942 {
5cc5088c 943 return bt_event_class_get_name(this->libObjPtr());
74fc764d
PP
944 }
945
2a24eba8 946 CommonEventClass logLevel(const LogLevel logLevel) const noexcept
74fc764d 947 {
5c895f64 948 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 949
341a67c4 950 bt_event_class_set_log_level(this->libObjPtr(),
74fc764d 951 static_cast<bt_event_class_log_level>(logLevel));
2a24eba8 952 return *this;
74fc764d
PP
953 }
954
c022776a 955 bt2s::optional<LogLevel> logLevel() const noexcept
74fc764d
PP
956 {
957 bt_event_class_log_level libLogLevel;
74fc764d 958
b3a12e59 959 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
74fc764d
PP
960 return static_cast<LogLevel>(libLogLevel);
961 }
962
c022776a 963 return bt2s::nullopt;
74fc764d
PP
964 }
965
2a24eba8 966 CommonEventClass emfUri(const bt2c::CStringView emfUri) const
74fc764d 967 {
5c895f64 968 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 969
341a67c4 970 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
74fc764d
PP
971
972 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
39278ebc 973 throw MemoryError {};
74fc764d 974 }
2a24eba8
SM
975
976 return *this;
74fc764d
PP
977 }
978
e7f0f07b 979 bt2c::CStringView emfUri() const noexcept
74fc764d 980 {
5cc5088c 981 return bt_event_class_get_emf_uri(this->libObjPtr());
74fc764d
PP
982 }
983
2a24eba8 984 CommonEventClass payloadFieldClass(const StructureFieldClass fc) const
74fc764d 985 {
5c895f64 986 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d
PP
987
988 const auto status =
341a67c4 989 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d
PP
990
991 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 992 throw MemoryError {};
74fc764d 993 }
2a24eba8
SM
994
995 return *this;
74fc764d
PP
996 }
997
ca61ecbc 998 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
74fc764d 999 {
ca61ecbc 1000 return _Spec::payloadFieldClass(this->libObjPtr());
74fc764d
PP
1001 }
1002
2a24eba8 1003 CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const
74fc764d 1004 {
5c895f64 1005 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d
PP
1006
1007 const auto status =
341a67c4 1008 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d
PP
1009
1010 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 1011 throw MemoryError {};
74fc764d 1012 }
2a24eba8
SM
1013
1014 return *this;
74fc764d
PP
1015 }
1016
ca61ecbc 1017 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
74fc764d 1018 {
ca61ecbc 1019 return _Spec::specificContextFieldClass(this->libObjPtr());
74fc764d
PP
1020 }
1021
1022 template <typename LibValT>
2a24eba8 1023 CommonEventClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 1024 {
5c895f64 1025 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 1026
341a67c4 1027 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2a24eba8 1028 return *this;
74fc764d
PP
1029 }
1030
dcb8ae9b 1031 UserAttributes userAttributes() const noexcept
74fc764d 1032 {
341a67c4 1033 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1034 }
1035
1036 Shared shared() const noexcept
1037 {
c9c0b6e2 1038 return Shared::createWithRef(*this);
74fc764d
PP
1039 }
1040};
1041
1042using EventClass = CommonEventClass<bt_event_class>;
1043using ConstEventClass = CommonEventClass<const bt_event_class>;
1044
4927bae7
PP
1045namespace internal {
1046
1047struct EventClassTypeDescr
1048{
1049 using Const = ConstEventClass;
1050 using NonConst = EventClass;
1051};
1052
1053template <>
1054struct TypeDescr<EventClass> : public EventClassTypeDescr
1055{
1056};
1057
1058template <>
1059struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1060{
1061};
1062
1063} /* namespace internal */
1064
74fc764d 1065template <typename LibObjT>
dcb8ae9b 1066typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
74fc764d 1067{
341a67c4 1068 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1069}
1070
1071namespace internal {
1072
1073struct StreamClassRefFuncs final
1074{
c677c492 1075 static void get(const bt_stream_class * const libObjPtr) noexcept
74fc764d
PP
1076 {
1077 bt_stream_class_get_ref(libObjPtr);
1078 }
1079
c677c492 1080 static void put(const bt_stream_class * const libObjPtr) noexcept
74fc764d
PP
1081 {
1082 bt_stream_class_put_ref(libObjPtr);
1083 }
1084};
1085
1086template <typename LibObjT>
1087struct CommonStreamClassSpec;
1088
b5f55e9f 1089/* Functions specific to mutable stream classes */
74fc764d
PP
1090template <>
1091struct CommonStreamClassSpec<bt_stream_class> final
1092{
1093 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1094 {
1095 return bt_stream_class_borrow_trace_class(libObjPtr);
1096 }
1097
1098 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1099 const std::uint64_t index) noexcept
1100 {
1101 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1102 }
1103
1104 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1105 const std::uint64_t id) noexcept
1106 {
1107 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1108 }
1109
1110 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1111 {
1112 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1113 }
1114
1115 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1116 {
1117 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1118 }
1119
1120 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1121 {
1122 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1123 }
1124
1125 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1126 {
1127 return bt_stream_class_borrow_user_attributes(libObjPtr);
1128 }
1129};
1130
b5f55e9f 1131/* Functions specific to constant stream classes */
74fc764d
PP
1132template <>
1133struct CommonStreamClassSpec<const bt_stream_class> final
1134{
1135 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1136 {
1137 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1138 }
1139
1140 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1141 const std::uint64_t index) noexcept
1142 {
1143 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1144 }
1145
1146 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1147 const std::uint64_t id) noexcept
1148 {
1149 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1150 }
1151
1152 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1153 {
1154 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1155 }
1156
1157 static const bt_field_class *
1158 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1159 {
1160 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1161 }
1162
1163 static const bt_field_class *
1164 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1165 {
1166 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1167 }
1168
1169 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1170 {
1171 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1172 }
1173};
1174
b5f55e9f 1175} /* namespace internal */
74fc764d
PP
1176
1177template <typename LibObjT>
0d218157 1178class CommonStreamClass final : public BorrowedObject<LibObjT>
74fc764d
PP
1179{
1180private:
0d218157 1181 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 1182 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
8047a175 1183 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
74fc764d 1184
8047a175
PP
1185 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1186 CommonTraceClass<const bt_trace_class>>;
74fc764d 1187
8047a175
PP
1188 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1189 CommonEventClass<const bt_event_class>>;
74fc764d 1190
8047a175 1191 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
74fc764d
PP
1192
1193public:
d246c457 1194 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 1195 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
8047a175 1196 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 1197
d246c457 1198 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
1199 {
1200 }
1201
1202 template <typename OtherLibObjT>
100fa861 1203 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
0d218157 1204 _ThisBorrowedObject {streamClass}
74fc764d
PP
1205 {
1206 }
1207
1208 template <typename OtherLibObjT>
ac30a470 1209 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
74fc764d 1210 {
0d218157 1211 _ThisBorrowedObject::operator=(streamClass);
74fc764d
PP
1212 return *this;
1213 }
1214
328a274a
PP
1215 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1216 {
1217 return CommonStreamClass<const bt_stream_class> {*this};
1218 }
1219
dcb8ae9b 1220 Stream::Shared instantiate(const Trace trace) const
74fc764d 1221 {
5c895f64
PP
1222 static_assert(!std::is_const<LibObjT>::value,
1223 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1224
341a67c4 1225 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
74fc764d
PP
1226
1227 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1228 return Stream::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1229 }
1230
dcb8ae9b 1231 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
74fc764d 1232 {
5c895f64
PP
1233 static_assert(!std::is_const<LibObjT>::value,
1234 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1235
341a67c4 1236 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
74fc764d
PP
1237
1238 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1239 return Stream::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1240 }
1241
dcb8ae9b 1242 EventClass::Shared createEventClass() const
74fc764d 1243 {
5c895f64
PP
1244 static_assert(!std::is_const<LibObjT>::value,
1245 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1246
341a67c4 1247 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
74fc764d
PP
1248
1249 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1250 return EventClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1251 }
1252
dcb8ae9b 1253 EventClass::Shared createEventClass(const std::uint64_t id) const
74fc764d 1254 {
5c895f64
PP
1255 static_assert(!std::is_const<LibObjT>::value,
1256 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1257
341a67c4 1258 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
74fc764d
PP
1259
1260 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1261 return EventClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1262 }
1263
dcb8ae9b 1264 _TraceClass traceClass() const noexcept;
74fc764d
PP
1265
1266 std::uint64_t id() const noexcept
1267 {
341a67c4 1268 return bt_stream_class_get_id(this->libObjPtr());
74fc764d
PP
1269 }
1270
2a24eba8 1271 CommonStreamClass name(const bt2c::CStringView name) const
74fc764d 1272 {
5c895f64
PP
1273 static_assert(!std::is_const<LibObjT>::value,
1274 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1275
341a67c4 1276 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
74fc764d
PP
1277
1278 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 1279 throw MemoryError {};
74fc764d 1280 }
2a24eba8
SM
1281
1282 return *this;
74fc764d
PP
1283 }
1284
e7f0f07b 1285 bt2c::CStringView name() const noexcept
74fc764d 1286 {
5cc5088c 1287 return bt_stream_class_get_name(this->libObjPtr());
74fc764d
PP
1288 }
1289
2a24eba8 1290 CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept
74fc764d 1291 {
5c895f64
PP
1292 static_assert(!std::is_const<LibObjT>::value,
1293 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1294
341a67c4 1295 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
74fc764d 1296 static_cast<bt_bool>(val));
2a24eba8 1297 return *this;
74fc764d
PP
1298 }
1299
1300 bool assignsAutomaticEventClassId() const noexcept
1301 {
1302 return static_cast<bool>(
341a67c4 1303 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
74fc764d
PP
1304 }
1305
2a24eba8 1306 CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept
74fc764d 1307 {
5c895f64
PP
1308 static_assert(!std::is_const<LibObjT>::value,
1309 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1310
341a67c4 1311 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
74fc764d 1312 static_cast<bt_bool>(val));
2a24eba8 1313 return *this;
74fc764d
PP
1314 }
1315
1316 bool assignsAutomaticStreamId() const noexcept
1317 {
341a67c4 1318 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
74fc764d
PP
1319 }
1320
2a24eba8
SM
1321 CommonStreamClass supportsPackets(const bool supportsPackets,
1322 const bool withBeginningDefaultClkSnapshot,
1323 const bool withEndDefaultClkSnapshot) const noexcept
74fc764d 1324 {
5c895f64
PP
1325 static_assert(!std::is_const<LibObjT>::value,
1326 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1327
341a67c4 1328 bt_stream_class_set_supports_packets(this->libObjPtr(),
74fc764d
PP
1329 static_cast<bt_bool>(supportsPackets),
1330 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1331 static_cast<bt_bool>(withEndDefaultClkSnapshot));
2a24eba8 1332 return *this;
74fc764d
PP
1333 }
1334
1335 bool supportsPackets() const noexcept
1336 {
341a67c4 1337 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
74fc764d
PP
1338 }
1339
1340 bool packetsHaveBeginningClockSnapshot() const noexcept
1341 {
1342 return static_cast<bool>(
341a67c4 1343 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
74fc764d
PP
1344 }
1345
1346 bool packetsHaveEndClockSnapshot() const noexcept
1347 {
1348 return static_cast<bool>(
341a67c4 1349 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
74fc764d
PP
1350 }
1351
2a24eba8
SM
1352 CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents,
1353 const bool withDefaultClkSnapshots) const noexcept
74fc764d 1354 {
5c895f64
PP
1355 static_assert(!std::is_const<LibObjT>::value,
1356 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1357
1358 bt_stream_class_set_supports_discarded_events(
7593e646 1359 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
74fc764d 1360 static_cast<bt_bool>(withDefaultClkSnapshots));
2a24eba8 1361 return *this;
74fc764d
PP
1362 }
1363
1364 bool supportsDiscardedEvents() const noexcept
1365 {
341a67c4 1366 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
74fc764d
PP
1367 }
1368
1369 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1370 {
1371 return static_cast<bool>(
341a67c4 1372 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
74fc764d
PP
1373 }
1374
2a24eba8
SM
1375 CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets,
1376 const bool withDefaultClkSnapshots) const noexcept
74fc764d 1377 {
5c895f64
PP
1378 static_assert(!std::is_const<LibObjT>::value,
1379 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1380
1381 bt_stream_class_set_supports_discarded_packets(
7593e646 1382 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
74fc764d 1383 static_cast<bt_bool>(withDefaultClkSnapshots));
2a24eba8 1384 return *this;
74fc764d
PP
1385 }
1386
1387 bool supportsDiscardedPackets() const noexcept
1388 {
341a67c4 1389 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
74fc764d
PP
1390 }
1391
1392 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1393 {
1394 return static_cast<bool>(
341a67c4 1395 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
74fc764d
PP
1396 }
1397
2a24eba8 1398 CommonStreamClass defaultClockClass(const ClockClass clkCls) const
74fc764d 1399 {
5c895f64
PP
1400 static_assert(!std::is_const<LibObjT>::value,
1401 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1402
1403 const auto status =
341a67c4 1404 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
74fc764d
PP
1405
1406 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
2a24eba8 1407 return *this;
74fc764d
PP
1408 }
1409
ca61ecbc 1410 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
74fc764d 1411 {
ca61ecbc 1412 return _Spec::defaultClockClass(this->libObjPtr());
74fc764d
PP
1413 }
1414
c0b73c63 1415 std::uint64_t length() const noexcept
74fc764d 1416 {
341a67c4 1417 return bt_stream_class_get_event_class_count(this->libObjPtr());
74fc764d
PP
1418 }
1419
dcb8ae9b 1420 _EventClass operator[](const std::uint64_t index) const noexcept
74fc764d 1421 {
341a67c4 1422 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
74fc764d
PP
1423 }
1424
ca61ecbc 1425 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
74fc764d 1426 {
ca61ecbc 1427 return _Spec::eventClassById(this->libObjPtr(), id);
74fc764d
PP
1428 }
1429
2a24eba8 1430 CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const
74fc764d 1431 {
5c895f64
PP
1432 static_assert(!std::is_const<LibObjT>::value,
1433 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1434
1435 const auto status =
341a67c4 1436 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d 1437
9ce695a6 1438 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 1439 throw MemoryError {};
74fc764d 1440 }
2a24eba8
SM
1441
1442 return *this;
74fc764d
PP
1443 }
1444
ca61ecbc 1445 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
74fc764d 1446 {
ca61ecbc 1447 return _Spec::packetContextFieldClass(this->libObjPtr());
74fc764d
PP
1448 }
1449
2a24eba8 1450 CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const
74fc764d 1451 {
5c895f64
PP
1452 static_assert(!std::is_const<LibObjT>::value,
1453 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1454
341a67c4
FD
1455 const auto status =
1456 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d 1457
9ce695a6 1458 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 1459 throw MemoryError {};
74fc764d 1460 }
2a24eba8
SM
1461
1462 return *this;
74fc764d
PP
1463 }
1464
ca61ecbc 1465 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
74fc764d 1466 {
ca61ecbc 1467 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
74fc764d
PP
1468 }
1469
1470 template <typename LibValT>
2a24eba8 1471 CommonStreamClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 1472 {
5c895f64
PP
1473 static_assert(!std::is_const<LibObjT>::value,
1474 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1475
341a67c4 1476 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2a24eba8 1477 return *this;
74fc764d
PP
1478 }
1479
dcb8ae9b 1480 UserAttributes userAttributes() const noexcept
74fc764d 1481 {
341a67c4 1482 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1483 }
1484
1485 Shared shared() const noexcept
1486 {
c9c0b6e2 1487 return Shared::createWithRef(*this);
74fc764d
PP
1488 }
1489};
1490
1491using StreamClass = CommonStreamClass<bt_stream_class>;
1492using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1493
4927bae7
PP
1494namespace internal {
1495
1496struct StreamClassTypeDescr
1497{
1498 using Const = ConstStreamClass;
1499 using NonConst = StreamClass;
1500};
1501
1502template <>
1503struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1504{
1505};
1506
1507template <>
1508struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1509{
1510};
1511
1512} /* namespace internal */
1513
74fc764d 1514template <typename LibObjT>
dcb8ae9b
PP
1515typename CommonEventClass<LibObjT>::_StreamClass
1516CommonEventClass<LibObjT>::streamClass() const noexcept
74fc764d 1517{
341a67c4 1518 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
74fc764d
PP
1519}
1520
1521template <typename LibObjT>
dcb8ae9b 1522typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
74fc764d 1523{
341a67c4 1524 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1525}
1526
1527namespace internal {
1528
1529struct TraceClassRefFuncs final
1530{
c677c492 1531 static void get(const bt_trace_class * const libObjPtr) noexcept
74fc764d
PP
1532 {
1533 bt_trace_class_get_ref(libObjPtr);
1534 }
1535
c677c492 1536 static void put(const bt_trace_class * const libObjPtr) noexcept
74fc764d
PP
1537 {
1538 bt_trace_class_put_ref(libObjPtr);
1539 }
1540};
1541
1542template <typename LibObjT>
1543struct CommonTraceClassSpec;
1544
b5f55e9f 1545/* Functions specific to mutable stream classes */
74fc764d
PP
1546template <>
1547struct CommonTraceClassSpec<bt_trace_class> final
1548{
1549 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1550 const std::uint64_t index) noexcept
1551 {
1552 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1553 }
1554
1555 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1556 const std::uint64_t id) noexcept
1557 {
1558 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1559 }
1560
1561 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1562 {
1563 return bt_trace_class_borrow_user_attributes(libObjPtr);
1564 }
1565};
1566
b5f55e9f 1567/* Functions specific to constant stream classes */
74fc764d
PP
1568template <>
1569struct CommonTraceClassSpec<const bt_trace_class> final
1570{
1571 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1572 const std::uint64_t index) noexcept
1573 {
1574 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1575 }
1576
1577 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1578 const std::uint64_t id) noexcept
1579 {
1580 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1581 }
1582
1583 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1584 {
1585 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1586 }
1587};
1588
b5f55e9f 1589} /* namespace internal */
74fc764d
PP
1590
1591template <typename LibObjT>
0d218157 1592class CommonTraceClass final : public BorrowedObject<LibObjT>
74fc764d
PP
1593{
1594private:
0d218157 1595 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
d246c457 1596
74fc764d 1597 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
74fc764d 1598
8047a175
PP
1599 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1600 CommonStreamClass<const bt_stream_class>>;
74fc764d
PP
1601
1602public:
d246c457 1603 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 1604 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
8047a175 1605 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 1606
d246c457 1607 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
1608 {
1609 }
1610
1611 template <typename OtherLibObjT>
100fa861 1612 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
0d218157 1613 _ThisBorrowedObject {traceClass}
74fc764d
PP
1614 {
1615 }
1616
1617 template <typename OtherLibObjT>
ac30a470 1618 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
74fc764d 1619 {
0d218157 1620 _ThisBorrowedObject::operator=(traceClass);
74fc764d
PP
1621 return *this;
1622 }
1623
328a274a
PP
1624 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1625 {
1626 return CommonTraceClass<const bt_trace_class> {*this};
1627 }
1628
dcb8ae9b 1629 Trace::Shared instantiate() const
74fc764d 1630 {
5c895f64 1631 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1632
341a67c4 1633 const auto libObjPtr = bt_trace_create(this->libObjPtr());
74fc764d
PP
1634
1635 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1636 return Trace::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1637 }
1638
dcb8ae9b 1639 StreamClass::Shared createStreamClass() const
74fc764d 1640 {
5c895f64 1641 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1642
341a67c4 1643 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
74fc764d
PP
1644
1645 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1646 return StreamClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1647 }
1648
dcb8ae9b 1649 StreamClass::Shared createStreamClass(const std::uint64_t id) const
74fc764d 1650 {
5c895f64 1651 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1652
341a67c4 1653 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
74fc764d
PP
1654
1655 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1656 return StreamClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1657 }
1658
dcb8ae9b 1659 FieldClass::Shared createBoolFieldClass() const
74fc764d 1660 {
5c895f64 1661 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1662
341a67c4 1663 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
74fc764d
PP
1664
1665 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1666 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1667 }
1668
dcb8ae9b 1669 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
74fc764d 1670 {
5c895f64 1671 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1672
341a67c4 1673 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
74fc764d
PP
1674
1675 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1676 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1677 }
1678
dcb8ae9b 1679 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
74fc764d 1680 {
5c895f64 1681 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1682
341a67c4 1683 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
74fc764d
PP
1684
1685 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1686 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1687 }
1688
dcb8ae9b 1689 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
74fc764d 1690 {
5c895f64 1691 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1692
341a67c4 1693 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
74fc764d
PP
1694
1695 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1696 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1697 }
1698
dcb8ae9b 1699 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
74fc764d 1700 {
5c895f64 1701 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1702
341a67c4 1703 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
74fc764d
PP
1704
1705 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1706 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1707 }
1708
dcb8ae9b 1709 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
74fc764d 1710 {
5c895f64 1711 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1712
341a67c4 1713 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
74fc764d
PP
1714
1715 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1716 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1717 }
1718
dcb8ae9b 1719 FieldClass::Shared createSinglePrecisionRealFieldClass() const
74fc764d 1720 {
5c895f64 1721 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1722
341a67c4 1723 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
74fc764d
PP
1724
1725 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1726 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1727 }
1728
dcb8ae9b 1729 FieldClass::Shared createDoublePrecisionRealFieldClass() const
74fc764d 1730 {
5c895f64 1731 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1732
341a67c4 1733 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
74fc764d
PP
1734
1735 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1736 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1737 }
1738
dcb8ae9b 1739 FieldClass::Shared createStringFieldClass() const
74fc764d 1740 {
5c895f64 1741 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1742
341a67c4 1743 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
74fc764d
PP
1744
1745 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1746 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1747 }
1748
100fa861 1749 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
dcb8ae9b 1750 const std::uint64_t length) const
74fc764d 1751 {
5c895f64 1752 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1753
1754 const auto libObjPtr = bt_field_class_array_static_create(
341a67c4 1755 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
74fc764d
PP
1756
1757 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1758 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1759 }
1760
dcb8ae9b 1761 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
74fc764d 1762 {
5c895f64 1763 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1764
1765 const auto libObjPtr = bt_field_class_array_dynamic_create(
341a67c4 1766 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
74fc764d
PP
1767
1768 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1769 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1770 }
1771
1772 DynamicArrayWithLengthFieldClass::Shared
100fa861 1773 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
dcb8ae9b 1774 const IntegerFieldClass lengthFieldClass) const
74fc764d 1775 {
5c895f64 1776 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1777
1778 const auto libObjPtr = bt_field_class_array_dynamic_create(
341a67c4 1779 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
74fc764d
PP
1780
1781 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1782 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1783 }
1784
dcb8ae9b 1785 StructureFieldClass::Shared createStructureFieldClass() const
74fc764d 1786 {
5c895f64 1787 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1788
341a67c4 1789 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
74fc764d
PP
1790
1791 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1792 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1793 }
1794
dcb8ae9b 1795 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
74fc764d 1796 {
5c895f64 1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1798
1799 const auto libObjPtr = bt_field_class_option_without_selector_create(
341a67c4 1800 this->libObjPtr(), optionalFieldClass.libObjPtr());
74fc764d
PP
1801
1802 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1803 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1804 }
1805
1806 OptionWithBoolSelectorFieldClass::Shared
100fa861 1807 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
dcb8ae9b 1808 const FieldClass selectorFieldClass) const
74fc764d 1809 {
5c895f64 1810 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1811
1812 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
341a67c4 1813 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
74fc764d
PP
1814
1815 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1816 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1817 }
1818
1819 OptionWithUnsignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1820 createOptionWithUnsignedIntegerSelectorFieldClass(
1821 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1822 const ConstUnsignedIntegerRangeSet ranges) const
74fc764d 1823 {
5c895f64 1824 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1825
1826 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
341a67c4
FD
1827 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1828 ranges.libObjPtr());
74fc764d
PP
1829
1830 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1831 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1832 }
1833
1834 OptionWithSignedIntegerSelectorFieldClass::Shared
100fa861
PP
1835 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1836 const IntegerFieldClass selectorFieldClass,
dcb8ae9b 1837 const ConstSignedIntegerRangeSet ranges) const
74fc764d 1838 {
5c895f64 1839 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1840
1841 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
341a67c4
FD
1842 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1843 ranges.libObjPtr());
74fc764d
PP
1844
1845 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1846 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1847 }
1848
dcb8ae9b 1849 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
74fc764d 1850 {
5c895f64 1851 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1852
341a67c4 1853 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
74fc764d
PP
1854
1855 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1856 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1857 }
1858
1859 VariantWithUnsignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1860 createVariantWithUnsignedIntegerSelectorFieldClass(
1861 const IntegerFieldClass selectorFieldClass) const
74fc764d 1862 {
69d96f80
FD
1863 return this->_createVariantWithIntegerSelectorFieldClass<
1864 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
74fc764d
PP
1865 }
1866
1867 VariantWithSignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1868 createVariantWithSignedIntegerSelectorFieldClass(
1869 const IntegerFieldClass selectorFieldClass) const
74fc764d 1870 {
69d96f80
FD
1871 return this->_createVariantWithIntegerSelectorFieldClass<
1872 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
74fc764d
PP
1873 }
1874
2a24eba8 1875 CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept
74fc764d 1876 {
5c895f64 1877 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1878
341a67c4 1879 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
74fc764d 1880 static_cast<bt_bool>(val));
2a24eba8 1881 return *this;
74fc764d
PP
1882 }
1883
1884 bool assignsAutomaticStreamClassId() const noexcept
1885 {
1886 return static_cast<bool>(
341a67c4 1887 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
74fc764d
PP
1888 }
1889
c0b73c63 1890 std::uint64_t length() const noexcept
74fc764d 1891 {
341a67c4 1892 return bt_trace_class_get_stream_class_count(this->libObjPtr());
74fc764d
PP
1893 }
1894
dcb8ae9b 1895 _StreamClass operator[](const std::uint64_t index) const noexcept
74fc764d 1896 {
341a67c4 1897 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
74fc764d
PP
1898 }
1899
ca61ecbc 1900 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
74fc764d 1901 {
ca61ecbc 1902 return _Spec::streamClassById(this->libObjPtr(), id);
74fc764d
PP
1903 }
1904
1905 template <typename LibValT>
2a24eba8 1906 CommonTraceClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 1907 {
5c895f64 1908 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1909
341a67c4 1910 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2a24eba8 1911 return *this;
74fc764d
PP
1912 }
1913
dcb8ae9b 1914 UserAttributes userAttributes() const noexcept
74fc764d 1915 {
341a67c4 1916 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1917 }
1918
1919 Shared shared() const noexcept
1920 {
c9c0b6e2 1921 return Shared::createWithRef(*this);
74fc764d
PP
1922 }
1923
1924private:
69d96f80
FD
1925 template <typename ObjT>
1926 typename ObjT::Shared
dcb8ae9b 1927 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
74fc764d 1928 {
5c895f64 1929 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1930
1931 const auto libObjPtr =
341a67c4 1932 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
74fc764d
PP
1933
1934 internal::validateCreatedObjPtr(libObjPtr);
69d96f80 1935 return ObjT::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1936 }
1937};
1938
1939using TraceClass = CommonTraceClass<bt_trace_class>;
1940using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1941
4927bae7
PP
1942namespace internal {
1943
1944struct TraceClassTypeDescr
1945{
1946 using Const = ConstTraceClass;
1947 using NonConst = TraceClass;
1948};
1949
1950template <>
1951struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1952{
1953};
1954
1955template <>
1956struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1957{
1958};
1959
1960} /* namespace internal */
1961
74fc764d 1962template <typename LibObjT>
dcb8ae9b
PP
1963typename CommonStreamClass<LibObjT>::_TraceClass
1964CommonStreamClass<LibObjT>::traceClass() const noexcept
74fc764d 1965{
341a67c4 1966 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
74fc764d
PP
1967}
1968
1969template <typename LibObjT>
dcb8ae9b 1970typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
74fc764d 1971{
341a67c4 1972 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1973}
1974
b5f55e9f 1975} /* namespace bt2 */
74fc764d 1976
b5f55e9f 1977#endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */
This page took 0.148216 seconds and 4 git commands to generate.