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