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