cpp-common/bt2: use bt2c::CStringView in parameters and return values throughout
[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
15030982 448 void name(const bt2c::CStringView 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
e7f0f07b 459 bt2c::CStringView name() const noexcept
74fc764d 460 {
5cc5088c 461 return bt_stream_get_name(this->libObjPtr());
74fc764d
PP
462 }
463
464 template <typename LibValT>
b7ffa6f0 465 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 466 {
5c895f64 467 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
74fc764d 468
341a67c4 469 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
74fc764d
PP
470 }
471
dcb8ae9b 472 UserAttributes userAttributes() const noexcept
74fc764d 473 {
341a67c4 474 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
475 }
476
477 Shared shared() const noexcept
478 {
c9c0b6e2 479 return Shared::createWithRef(*this);
74fc764d
PP
480 }
481};
482
483using Stream = CommonStream<bt_stream>;
484using ConstStream = CommonStream<const bt_stream>;
485
4927bae7
PP
486namespace internal {
487
488struct StreamTypeDescr
489{
490 using Const = ConstStream;
491 using NonConst = Stream;
492};
493
494template <>
495struct TypeDescr<Stream> : public StreamTypeDescr
496{
497};
498
499template <>
500struct TypeDescr<ConstStream> : public StreamTypeDescr
501{
502};
503
504} /* namespace internal */
505
74fc764d 506template <typename LibObjT>
dcb8ae9b 507typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
74fc764d 508{
341a67c4 509 return _Stream {_Spec::stream(this->libObjPtr())};
74fc764d
PP
510}
511
512template <typename LibObjT>
dcb8ae9b 513typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
74fc764d 514{
341a67c4 515 return _Stream {_Spec::stream(this->libObjPtr())};
74fc764d
PP
516}
517
518namespace internal {
519
520struct TraceRefFuncs final
521{
c677c492 522 static void get(const bt_trace * const libObjPtr) noexcept
74fc764d
PP
523 {
524 bt_trace_get_ref(libObjPtr);
525 }
526
c677c492 527 static void put(const bt_trace * const libObjPtr) noexcept
74fc764d
PP
528 {
529 bt_trace_put_ref(libObjPtr);
530 }
531};
532
533template <typename LibObjT>
534struct CommonTraceSpec;
535
b5f55e9f 536/* Functions specific to mutable traces */
74fc764d
PP
537template <>
538struct CommonTraceSpec<bt_trace> final
539{
540 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
541 {
542 return bt_trace_borrow_class(libObjPtr);
543 }
544
545 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
546 {
547 return bt_trace_borrow_stream_by_index(libObjPtr, index);
548 }
549
550 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
551 {
552 return bt_trace_borrow_stream_by_id(libObjPtr, id);
553 }
554
555 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
556 {
557 return bt_trace_borrow_user_attributes(libObjPtr);
558 }
559};
560
b5f55e9f 561/* Functions specific to constant traces */
74fc764d
PP
562template <>
563struct CommonTraceSpec<const bt_trace> final
564{
565 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
566 {
567 return bt_trace_borrow_class_const(libObjPtr);
568 }
569
570 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
571 const std::uint64_t index) noexcept
572 {
573 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
574 }
575
576 static const bt_stream *streamById(const bt_trace * const libObjPtr,
577 const std::uint64_t id) noexcept
578 {
579 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
580 }
581
582 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
583 {
584 return bt_trace_borrow_user_attributes_const(libObjPtr);
585 }
586};
587
b5f55e9f 588} /* namespace internal */
74fc764d
PP
589
590template <typename LibObjT>
0d218157 591class CommonTrace final : public BorrowedObject<LibObjT>
74fc764d 592{
74fc764d 593private:
0d218157 594 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 595 using _Spec = internal::CommonTraceSpec<LibObjT>;
8047a175 596 using _Stream = internal::DepStream<LibObjT>;
74fc764d
PP
597
598public:
d246c457 599 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 600 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
8047a175 601 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 602
8047a175
PP
603 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
604 CommonTraceClass<const bt_trace_class>>;
74fc764d
PP
605
606 struct ConstEnvironmentEntry
607 {
e7f0f07b 608 bt2c::CStringView name;
74fc764d
PP
609 ConstValue value;
610 };
611
d246c457 612 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
613 {
614 }
615
616 template <typename OtherLibObjT>
0d218157 617 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
74fc764d
PP
618 {
619 }
620
621 template <typename OtherLibObjT>
ac30a470 622 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
74fc764d 623 {
0d218157 624 _ThisBorrowedObject::operator=(trace);
74fc764d
PP
625 return *this;
626 }
627
328a274a
PP
628 CommonTrace<const bt_trace> asConst() const noexcept
629 {
630 return CommonTrace<const bt_trace> {*this};
631 }
632
dcb8ae9b 633 Class cls() const noexcept;
74fc764d 634
15030982 635 void name(const bt2c::CStringView name) const
74fc764d 636 {
5c895f64 637 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 638
341a67c4 639 const auto status = bt_trace_set_name(this->libObjPtr(), name);
74fc764d
PP
640
641 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 642 throw MemoryError {};
74fc764d
PP
643 }
644 }
645
e7f0f07b 646 bt2c::CStringView name() const noexcept
74fc764d 647 {
5cc5088c 648 return bt_trace_get_name(this->libObjPtr());
74fc764d
PP
649 }
650
094bf3f2 651 void uuid(const bt2c::UuidView& uuid) const noexcept
74fc764d 652 {
81d250db 653 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
74fc764d
PP
654 }
655
c022776a 656 bt2s::optional<bt2c::UuidView> uuid() const noexcept
74fc764d 657 {
341a67c4 658 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
74fc764d
PP
659
660 if (uuid) {
094bf3f2 661 return bt2c::UuidView {uuid};
74fc764d
PP
662 }
663
c022776a 664 return bt2s::nullopt;
74fc764d
PP
665 }
666
c0b73c63 667 std::uint64_t length() const noexcept
74fc764d 668 {
341a67c4 669 return bt_trace_get_stream_count(this->libObjPtr());
74fc764d
PP
670 }
671
dcb8ae9b 672 _Stream operator[](const std::uint64_t index) const noexcept
74fc764d 673 {
341a67c4 674 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
74fc764d
PP
675 }
676
ca61ecbc 677 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
74fc764d 678 {
ca61ecbc 679 return _Spec::streamById(this->libObjPtr(), id);
74fc764d
PP
680 }
681
15030982 682 void environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
74fc764d 683 {
5c895f64 684 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 685
341a67c4 686 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
74fc764d
PP
687
688 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
39278ebc 689 throw MemoryError {};
74fc764d
PP
690 }
691 }
692
15030982 693 void environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
74fc764d 694 {
5c895f64 695 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 696
341a67c4 697 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
74fc764d
PP
698
699 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
39278ebc 700 throw MemoryError {};
74fc764d
PP
701 }
702 }
703
74fc764d
PP
704 std::uint64_t environmentSize() const noexcept
705 {
341a67c4 706 return bt_trace_get_environment_entry_count(this->libObjPtr());
74fc764d
PP
707 }
708
709 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
710 {
711 const char *name;
712 const bt_value *libObjPtr;
713
341a67c4 714 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
74fc764d
PP
715 &libObjPtr);
716 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
717 }
718
15030982 719 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
74fc764d 720 {
ca61ecbc 721 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
74fc764d
PP
722 }
723
74fc764d 724 template <typename LibValT>
b7ffa6f0 725 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 726 {
5c895f64 727 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
74fc764d 728
341a67c4 729 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
74fc764d
PP
730 }
731
dcb8ae9b 732 UserAttributes userAttributes() const noexcept
74fc764d 733 {
341a67c4 734 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
735 }
736
737 Shared shared() const noexcept
738 {
c9c0b6e2 739 return Shared::createWithRef(*this);
74fc764d
PP
740 }
741};
742
743using Trace = CommonTrace<bt_trace>;
744using ConstTrace = CommonTrace<const bt_trace>;
745
4927bae7
PP
746namespace internal {
747
748struct TraceTypeDescr
749{
750 using Const = ConstTrace;
751 using NonConst = Trace;
752};
753
754template <>
755struct TypeDescr<Trace> : public TraceTypeDescr
756{
757};
758
759template <>
760struct TypeDescr<ConstTrace> : public TraceTypeDescr
761{
762};
763
764} /* namespace internal */
765
74fc764d 766template <typename LibObjT>
dcb8ae9b 767typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
74fc764d 768{
341a67c4 769 return _Trace {_Spec::trace(this->libObjPtr())};
74fc764d
PP
770}
771
772namespace internal {
773
774struct EventClassRefFuncs final
775{
c677c492 776 static void get(const bt_event_class * const libObjPtr) noexcept
74fc764d
PP
777 {
778 bt_event_class_get_ref(libObjPtr);
779 }
780
c677c492 781 static void put(const bt_event_class * const libObjPtr) noexcept
74fc764d
PP
782 {
783 bt_event_class_put_ref(libObjPtr);
784 }
785};
786
787template <typename LibObjT>
788struct CommonEventClassSpec;
789
b5f55e9f 790/* Functions specific to mutable event classes */
74fc764d
PP
791template <>
792struct CommonEventClassSpec<bt_event_class> final
793{
794 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
795 {
796 return bt_event_class_borrow_stream_class(libObjPtr);
797 }
798
799 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
800 {
801 return bt_event_class_borrow_payload_field_class(libObjPtr);
802 }
803
804 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
805 {
806 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
807 }
808
809 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
810 {
811 return bt_event_class_borrow_user_attributes(libObjPtr);
812 }
813};
814
b5f55e9f 815/* Functions specific to constant event classes */
74fc764d
PP
816template <>
817struct CommonEventClassSpec<const bt_event_class> final
818{
819 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
820 {
821 return bt_event_class_borrow_stream_class_const(libObjPtr);
822 }
823
824 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
825 {
826 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
827 }
828
829 static const bt_field_class *
830 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
831 {
832 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
833 }
834
835 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
836 {
837 return bt_event_class_borrow_user_attributes_const(libObjPtr);
838 }
839};
840
8047a175
PP
841template <typename LibObjT>
842using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
843
b5f55e9f 844} /* namespace internal */
74fc764d
PP
845
846template <typename LibObjT>
0d218157 847class CommonEventClass final : public BorrowedObject<LibObjT>
74fc764d
PP
848{
849private:
0d218157 850 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 851 using _Spec = internal::CommonEventClassSpec<LibObjT>;
8047a175 852 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
74fc764d 853
8047a175
PP
854 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
855 CommonStreamClass<const bt_stream_class>>;
74fc764d
PP
856
857public:
d246c457 858 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 859 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
8047a175 860 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d
PP
861
862 enum class LogLevel
863 {
864 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
865 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
866 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
0c0001b4 867 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
74fc764d
PP
868 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
869 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
870 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
871 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
872 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
0c0001b4 873 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
74fc764d
PP
874 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
875 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
876 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
877 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
878 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
879 };
880
d246c457 881 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
882 {
883 }
884
885 template <typename OtherLibObjT>
100fa861 886 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
0d218157 887 _ThisBorrowedObject {eventClass}
74fc764d
PP
888 {
889 }
890
891 template <typename OtherLibObjT>
ac30a470 892 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
74fc764d 893 {
0d218157 894 _ThisBorrowedObject::operator=(eventClass);
74fc764d
PP
895 return *this;
896 }
897
328a274a
PP
898 CommonEventClass<const bt_event_class> asConst() const noexcept
899 {
900 return CommonEventClass<const bt_event_class> {*this};
901 }
902
dcb8ae9b 903 _StreamClass streamClass() const noexcept;
74fc764d
PP
904
905 std::uint64_t id() const noexcept
906 {
341a67c4 907 return bt_event_class_get_id(this->libObjPtr());
74fc764d
PP
908 }
909
15030982 910 void name(const bt2c::CStringView name) const
74fc764d 911 {
5c895f64 912 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 913
341a67c4 914 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
74fc764d
PP
915
916 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 917 throw MemoryError {};
74fc764d
PP
918 }
919 }
920
e7f0f07b 921 bt2c::CStringView name() const noexcept
74fc764d 922 {
5cc5088c 923 return bt_event_class_get_name(this->libObjPtr());
74fc764d
PP
924 }
925
dcb8ae9b 926 void logLevel(const LogLevel logLevel) const noexcept
74fc764d 927 {
5c895f64 928 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 929
341a67c4 930 bt_event_class_set_log_level(this->libObjPtr(),
74fc764d
PP
931 static_cast<bt_event_class_log_level>(logLevel));
932 }
933
c022776a 934 bt2s::optional<LogLevel> logLevel() const noexcept
74fc764d
PP
935 {
936 bt_event_class_log_level libLogLevel;
74fc764d 937
b3a12e59 938 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
74fc764d
PP
939 return static_cast<LogLevel>(libLogLevel);
940 }
941
c022776a 942 return bt2s::nullopt;
74fc764d
PP
943 }
944
15030982 945 void emfUri(const bt2c::CStringView emfUri) 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_emf_uri(this->libObjPtr(), emfUri);
74fc764d
PP
950
951 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
39278ebc 952 throw MemoryError {};
74fc764d
PP
953 }
954 }
955
e7f0f07b 956 bt2c::CStringView emfUri() const noexcept
74fc764d 957 {
5cc5088c 958 return bt_event_class_get_emf_uri(this->libObjPtr());
74fc764d
PP
959 }
960
dcb8ae9b 961 void payloadFieldClass(const StructureFieldClass fc) const
74fc764d 962 {
5c895f64 963 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d
PP
964
965 const auto status =
341a67c4 966 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d
PP
967
968 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 969 throw MemoryError {};
74fc764d
PP
970 }
971 }
972
ca61ecbc 973 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
74fc764d 974 {
ca61ecbc 975 return _Spec::payloadFieldClass(this->libObjPtr());
74fc764d
PP
976 }
977
dcb8ae9b 978 void specificContextFieldClass(const StructureFieldClass fc) const
74fc764d 979 {
5c895f64 980 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d
PP
981
982 const auto status =
341a67c4 983 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d
PP
984
985 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 986 throw MemoryError {};
74fc764d
PP
987 }
988 }
989
ca61ecbc 990 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
74fc764d 991 {
ca61ecbc 992 return _Spec::specificContextFieldClass(this->libObjPtr());
74fc764d
PP
993 }
994
995 template <typename LibValT>
b7ffa6f0 996 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 997 {
5c895f64 998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
74fc764d 999
341a67c4 1000 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
74fc764d
PP
1001 }
1002
dcb8ae9b 1003 UserAttributes userAttributes() const noexcept
74fc764d 1004 {
341a67c4 1005 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1006 }
1007
1008 Shared shared() const noexcept
1009 {
c9c0b6e2 1010 return Shared::createWithRef(*this);
74fc764d
PP
1011 }
1012};
1013
1014using EventClass = CommonEventClass<bt_event_class>;
1015using ConstEventClass = CommonEventClass<const bt_event_class>;
1016
4927bae7
PP
1017namespace internal {
1018
1019struct EventClassTypeDescr
1020{
1021 using Const = ConstEventClass;
1022 using NonConst = EventClass;
1023};
1024
1025template <>
1026struct TypeDescr<EventClass> : public EventClassTypeDescr
1027{
1028};
1029
1030template <>
1031struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1032{
1033};
1034
1035} /* namespace internal */
1036
74fc764d 1037template <typename LibObjT>
dcb8ae9b 1038typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
74fc764d 1039{
341a67c4 1040 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1041}
1042
1043namespace internal {
1044
1045struct StreamClassRefFuncs final
1046{
c677c492 1047 static void get(const bt_stream_class * const libObjPtr) noexcept
74fc764d
PP
1048 {
1049 bt_stream_class_get_ref(libObjPtr);
1050 }
1051
c677c492 1052 static void put(const bt_stream_class * const libObjPtr) noexcept
74fc764d
PP
1053 {
1054 bt_stream_class_put_ref(libObjPtr);
1055 }
1056};
1057
1058template <typename LibObjT>
1059struct CommonStreamClassSpec;
1060
b5f55e9f 1061/* Functions specific to mutable stream classes */
74fc764d
PP
1062template <>
1063struct CommonStreamClassSpec<bt_stream_class> final
1064{
1065 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1066 {
1067 return bt_stream_class_borrow_trace_class(libObjPtr);
1068 }
1069
1070 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1071 const std::uint64_t index) noexcept
1072 {
1073 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1074 }
1075
1076 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1077 const std::uint64_t id) noexcept
1078 {
1079 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1080 }
1081
1082 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1083 {
1084 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1085 }
1086
1087 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1088 {
1089 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1090 }
1091
1092 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1093 {
1094 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1095 }
1096
1097 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1098 {
1099 return bt_stream_class_borrow_user_attributes(libObjPtr);
1100 }
1101};
1102
b5f55e9f 1103/* Functions specific to constant stream classes */
74fc764d
PP
1104template <>
1105struct CommonStreamClassSpec<const bt_stream_class> final
1106{
1107 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1108 {
1109 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1110 }
1111
1112 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1113 const std::uint64_t index) noexcept
1114 {
1115 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1116 }
1117
1118 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1119 const std::uint64_t id) noexcept
1120 {
1121 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1122 }
1123
1124 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1125 {
1126 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1127 }
1128
1129 static const bt_field_class *
1130 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1131 {
1132 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1133 }
1134
1135 static const bt_field_class *
1136 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1137 {
1138 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1139 }
1140
1141 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1142 {
1143 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1144 }
1145};
1146
b5f55e9f 1147} /* namespace internal */
74fc764d
PP
1148
1149template <typename LibObjT>
0d218157 1150class CommonStreamClass final : public BorrowedObject<LibObjT>
74fc764d
PP
1151{
1152private:
0d218157 1153 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
74fc764d 1154 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
8047a175 1155 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
74fc764d 1156
8047a175
PP
1157 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1158 CommonTraceClass<const bt_trace_class>>;
74fc764d 1159
8047a175
PP
1160 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1161 CommonEventClass<const bt_event_class>>;
74fc764d 1162
8047a175 1163 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
74fc764d
PP
1164
1165public:
d246c457 1166 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 1167 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
8047a175 1168 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 1169
d246c457 1170 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
1171 {
1172 }
1173
1174 template <typename OtherLibObjT>
100fa861 1175 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
0d218157 1176 _ThisBorrowedObject {streamClass}
74fc764d
PP
1177 {
1178 }
1179
1180 template <typename OtherLibObjT>
ac30a470 1181 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
74fc764d 1182 {
0d218157 1183 _ThisBorrowedObject::operator=(streamClass);
74fc764d
PP
1184 return *this;
1185 }
1186
328a274a
PP
1187 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1188 {
1189 return CommonStreamClass<const bt_stream_class> {*this};
1190 }
1191
dcb8ae9b 1192 Stream::Shared instantiate(const Trace trace) const
74fc764d 1193 {
5c895f64
PP
1194 static_assert(!std::is_const<LibObjT>::value,
1195 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1196
341a67c4 1197 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
74fc764d
PP
1198
1199 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1200 return Stream::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1201 }
1202
dcb8ae9b 1203 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
74fc764d 1204 {
5c895f64
PP
1205 static_assert(!std::is_const<LibObjT>::value,
1206 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1207
341a67c4 1208 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
74fc764d
PP
1209
1210 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1211 return Stream::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1212 }
1213
dcb8ae9b 1214 EventClass::Shared createEventClass() const
74fc764d 1215 {
5c895f64
PP
1216 static_assert(!std::is_const<LibObjT>::value,
1217 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1218
341a67c4 1219 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
74fc764d
PP
1220
1221 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1222 return EventClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1223 }
1224
dcb8ae9b 1225 EventClass::Shared createEventClass(const std::uint64_t id) const
74fc764d 1226 {
5c895f64
PP
1227 static_assert(!std::is_const<LibObjT>::value,
1228 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1229
341a67c4 1230 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
74fc764d
PP
1231
1232 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1233 return EventClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1234 }
1235
dcb8ae9b 1236 _TraceClass traceClass() const noexcept;
74fc764d
PP
1237
1238 std::uint64_t id() const noexcept
1239 {
341a67c4 1240 return bt_stream_class_get_id(this->libObjPtr());
74fc764d
PP
1241 }
1242
15030982 1243 void name(const bt2c::CStringView name) const
74fc764d 1244 {
5c895f64
PP
1245 static_assert(!std::is_const<LibObjT>::value,
1246 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1247
341a67c4 1248 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
74fc764d
PP
1249
1250 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
39278ebc 1251 throw MemoryError {};
74fc764d
PP
1252 }
1253 }
1254
e7f0f07b 1255 bt2c::CStringView name() const noexcept
74fc764d 1256 {
5cc5088c 1257 return bt_stream_class_get_name(this->libObjPtr());
74fc764d
PP
1258 }
1259
dcb8ae9b 1260 void assignsAutomaticEventClassId(const bool val) const noexcept
74fc764d 1261 {
5c895f64
PP
1262 static_assert(!std::is_const<LibObjT>::value,
1263 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1264
341a67c4 1265 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
74fc764d
PP
1266 static_cast<bt_bool>(val));
1267 }
1268
1269 bool assignsAutomaticEventClassId() const noexcept
1270 {
1271 return static_cast<bool>(
341a67c4 1272 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
74fc764d
PP
1273 }
1274
dcb8ae9b 1275 void assignsAutomaticStreamId(const bool val) const noexcept
74fc764d 1276 {
5c895f64
PP
1277 static_assert(!std::is_const<LibObjT>::value,
1278 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1279
341a67c4 1280 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
74fc764d
PP
1281 static_cast<bt_bool>(val));
1282 }
1283
1284 bool assignsAutomaticStreamId() const noexcept
1285 {
341a67c4 1286 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
74fc764d
PP
1287 }
1288
1289 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
dcb8ae9b 1290 const bool withEndDefaultClkSnapshot) const noexcept
74fc764d 1291 {
5c895f64
PP
1292 static_assert(!std::is_const<LibObjT>::value,
1293 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1294
341a67c4 1295 bt_stream_class_set_supports_packets(this->libObjPtr(),
74fc764d
PP
1296 static_cast<bt_bool>(supportsPackets),
1297 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1298 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1299 }
1300
1301 bool supportsPackets() const noexcept
1302 {
341a67c4 1303 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
74fc764d
PP
1304 }
1305
1306 bool packetsHaveBeginningClockSnapshot() const noexcept
1307 {
1308 return static_cast<bool>(
341a67c4 1309 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
74fc764d
PP
1310 }
1311
1312 bool packetsHaveEndClockSnapshot() const noexcept
1313 {
1314 return static_cast<bool>(
341a67c4 1315 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
74fc764d
PP
1316 }
1317
1318 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
dcb8ae9b 1319 const bool withDefaultClkSnapshots) const noexcept
74fc764d 1320 {
5c895f64
PP
1321 static_assert(!std::is_const<LibObjT>::value,
1322 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1323
1324 bt_stream_class_set_supports_discarded_events(
7593e646 1325 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
74fc764d
PP
1326 static_cast<bt_bool>(withDefaultClkSnapshots));
1327 }
1328
1329 bool supportsDiscardedEvents() const noexcept
1330 {
341a67c4 1331 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
74fc764d
PP
1332 }
1333
1334 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1335 {
1336 return static_cast<bool>(
341a67c4 1337 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
74fc764d
PP
1338 }
1339
1340 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
dcb8ae9b 1341 const bool withDefaultClkSnapshots) const noexcept
74fc764d 1342 {
5c895f64
PP
1343 static_assert(!std::is_const<LibObjT>::value,
1344 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1345
1346 bt_stream_class_set_supports_discarded_packets(
7593e646 1347 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
74fc764d
PP
1348 static_cast<bt_bool>(withDefaultClkSnapshots));
1349 }
1350
1351 bool supportsDiscardedPackets() const noexcept
1352 {
341a67c4 1353 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
74fc764d
PP
1354 }
1355
1356 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1357 {
1358 return static_cast<bool>(
341a67c4 1359 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
74fc764d
PP
1360 }
1361
dcb8ae9b 1362 void defaultClockClass(const ClockClass clkCls) const
74fc764d 1363 {
5c895f64
PP
1364 static_assert(!std::is_const<LibObjT>::value,
1365 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1366
1367 const auto status =
341a67c4 1368 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
74fc764d
PP
1369
1370 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1371 }
1372
ca61ecbc 1373 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
74fc764d 1374 {
ca61ecbc 1375 return _Spec::defaultClockClass(this->libObjPtr());
74fc764d
PP
1376 }
1377
c0b73c63 1378 std::uint64_t length() const noexcept
74fc764d 1379 {
341a67c4 1380 return bt_stream_class_get_event_class_count(this->libObjPtr());
74fc764d
PP
1381 }
1382
dcb8ae9b 1383 _EventClass operator[](const std::uint64_t index) const noexcept
74fc764d 1384 {
341a67c4 1385 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
74fc764d
PP
1386 }
1387
ca61ecbc 1388 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
74fc764d 1389 {
ca61ecbc 1390 return _Spec::eventClassById(this->libObjPtr(), id);
74fc764d
PP
1391 }
1392
dcb8ae9b 1393 void packetContextFieldClass(const StructureFieldClass fc) const
74fc764d 1394 {
5c895f64
PP
1395 static_assert(!std::is_const<LibObjT>::value,
1396 "Not available with `bt2::ConstStreamClass`.");
74fc764d
PP
1397
1398 const auto status =
341a67c4 1399 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d 1400
9ce695a6 1401 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 1402 throw MemoryError {};
74fc764d
PP
1403 }
1404 }
1405
ca61ecbc 1406 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
74fc764d 1407 {
ca61ecbc 1408 return _Spec::packetContextFieldClass(this->libObjPtr());
74fc764d
PP
1409 }
1410
dcb8ae9b 1411 void eventCommonContextFieldClass(const StructureFieldClass fc) const
74fc764d 1412 {
5c895f64
PP
1413 static_assert(!std::is_const<LibObjT>::value,
1414 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1415
341a67c4
FD
1416 const auto status =
1417 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
74fc764d 1418
9ce695a6 1419 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
39278ebc 1420 throw MemoryError {};
74fc764d
PP
1421 }
1422 }
1423
ca61ecbc 1424 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
74fc764d 1425 {
ca61ecbc 1426 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
74fc764d
PP
1427 }
1428
1429 template <typename LibValT>
b7ffa6f0 1430 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 1431 {
5c895f64
PP
1432 static_assert(!std::is_const<LibObjT>::value,
1433 "Not available with `bt2::ConstStreamClass`.");
74fc764d 1434
341a67c4 1435 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
74fc764d
PP
1436 }
1437
dcb8ae9b 1438 UserAttributes userAttributes() const noexcept
74fc764d 1439 {
341a67c4 1440 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1441 }
1442
1443 Shared shared() const noexcept
1444 {
c9c0b6e2 1445 return Shared::createWithRef(*this);
74fc764d
PP
1446 }
1447};
1448
1449using StreamClass = CommonStreamClass<bt_stream_class>;
1450using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1451
4927bae7
PP
1452namespace internal {
1453
1454struct StreamClassTypeDescr
1455{
1456 using Const = ConstStreamClass;
1457 using NonConst = StreamClass;
1458};
1459
1460template <>
1461struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1462{
1463};
1464
1465template <>
1466struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1467{
1468};
1469
1470} /* namespace internal */
1471
74fc764d 1472template <typename LibObjT>
dcb8ae9b
PP
1473typename CommonEventClass<LibObjT>::_StreamClass
1474CommonEventClass<LibObjT>::streamClass() const noexcept
74fc764d 1475{
341a67c4 1476 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
74fc764d
PP
1477}
1478
1479template <typename LibObjT>
dcb8ae9b 1480typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
74fc764d 1481{
341a67c4 1482 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1483}
1484
1485namespace internal {
1486
1487struct TraceClassRefFuncs final
1488{
c677c492 1489 static void get(const bt_trace_class * const libObjPtr) noexcept
74fc764d
PP
1490 {
1491 bt_trace_class_get_ref(libObjPtr);
1492 }
1493
c677c492 1494 static void put(const bt_trace_class * const libObjPtr) noexcept
74fc764d
PP
1495 {
1496 bt_trace_class_put_ref(libObjPtr);
1497 }
1498};
1499
1500template <typename LibObjT>
1501struct CommonTraceClassSpec;
1502
b5f55e9f 1503/* Functions specific to mutable stream classes */
74fc764d
PP
1504template <>
1505struct CommonTraceClassSpec<bt_trace_class> final
1506{
1507 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1508 const std::uint64_t index) noexcept
1509 {
1510 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1511 }
1512
1513 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1514 const std::uint64_t id) noexcept
1515 {
1516 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1517 }
1518
1519 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1520 {
1521 return bt_trace_class_borrow_user_attributes(libObjPtr);
1522 }
1523};
1524
b5f55e9f 1525/* Functions specific to constant stream classes */
74fc764d
PP
1526template <>
1527struct CommonTraceClassSpec<const bt_trace_class> final
1528{
1529 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1530 const std::uint64_t index) noexcept
1531 {
1532 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1533 }
1534
1535 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1536 const std::uint64_t id) noexcept
1537 {
1538 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1539 }
1540
1541 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1542 {
1543 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1544 }
1545};
1546
b5f55e9f 1547} /* namespace internal */
74fc764d
PP
1548
1549template <typename LibObjT>
0d218157 1550class CommonTraceClass final : public BorrowedObject<LibObjT>
74fc764d
PP
1551{
1552private:
0d218157 1553 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
d246c457 1554
74fc764d 1555 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
74fc764d 1556
8047a175
PP
1557 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1558 CommonStreamClass<const bt_stream_class>>;
74fc764d
PP
1559
1560public:
d246c457 1561 using typename BorrowedObject<LibObjT>::LibObjPtr;
ac19444e 1562 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
8047a175 1563 using UserAttributes = internal::DepUserAttrs<LibObjT>;
74fc764d 1564
d246c457 1565 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
74fc764d
PP
1566 {
1567 }
1568
1569 template <typename OtherLibObjT>
100fa861 1570 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
0d218157 1571 _ThisBorrowedObject {traceClass}
74fc764d
PP
1572 {
1573 }
1574
1575 template <typename OtherLibObjT>
ac30a470 1576 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
74fc764d 1577 {
0d218157 1578 _ThisBorrowedObject::operator=(traceClass);
74fc764d
PP
1579 return *this;
1580 }
1581
328a274a
PP
1582 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1583 {
1584 return CommonTraceClass<const bt_trace_class> {*this};
1585 }
1586
dcb8ae9b 1587 Trace::Shared instantiate() const
74fc764d 1588 {
5c895f64 1589 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1590
341a67c4 1591 const auto libObjPtr = bt_trace_create(this->libObjPtr());
74fc764d
PP
1592
1593 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1594 return Trace::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1595 }
1596
dcb8ae9b 1597 StreamClass::Shared createStreamClass() const
74fc764d 1598 {
5c895f64 1599 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1600
341a67c4 1601 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
74fc764d
PP
1602
1603 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1604 return StreamClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1605 }
1606
dcb8ae9b 1607 StreamClass::Shared createStreamClass(const std::uint64_t id) const
74fc764d 1608 {
5c895f64 1609 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1610
341a67c4 1611 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
74fc764d
PP
1612
1613 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1614 return StreamClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1615 }
1616
dcb8ae9b 1617 FieldClass::Shared createBoolFieldClass() const
74fc764d 1618 {
5c895f64 1619 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1620
341a67c4 1621 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
74fc764d
PP
1622
1623 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1624 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1625 }
1626
dcb8ae9b 1627 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
74fc764d 1628 {
5c895f64 1629 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1630
341a67c4 1631 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
74fc764d
PP
1632
1633 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1634 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1635 }
1636
dcb8ae9b 1637 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() 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_field_class_integer_unsigned_create(this->libObjPtr());
74fc764d
PP
1642
1643 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1644 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1645 }
1646
dcb8ae9b 1647 IntegerFieldClass::Shared createSignedIntegerFieldClass() 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_field_class_integer_signed_create(this->libObjPtr());
74fc764d
PP
1652
1653 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1654 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1655 }
1656
dcb8ae9b 1657 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() 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_field_class_enumeration_unsigned_create(this->libObjPtr());
74fc764d
PP
1662
1663 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1664 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1665 }
1666
dcb8ae9b 1667 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() 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_enumeration_signed_create(this->libObjPtr());
74fc764d
PP
1672
1673 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1674 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1675 }
1676
dcb8ae9b 1677 FieldClass::Shared createSinglePrecisionRealFieldClass() 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_real_single_precision_create(this->libObjPtr());
74fc764d
PP
1682
1683 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1684 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1685 }
1686
dcb8ae9b 1687 FieldClass::Shared createDoublePrecisionRealFieldClass() 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_real_double_precision_create(this->libObjPtr());
74fc764d
PP
1692
1693 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1694 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1695 }
1696
dcb8ae9b 1697 FieldClass::Shared createStringFieldClass() 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_string_create(this->libObjPtr());
74fc764d
PP
1702
1703 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1704 return FieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1705 }
1706
100fa861 1707 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
dcb8ae9b 1708 const std::uint64_t length) const
74fc764d 1709 {
5c895f64 1710 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1711
1712 const auto libObjPtr = bt_field_class_array_static_create(
341a67c4 1713 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
74fc764d
PP
1714
1715 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1716 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1717 }
1718
dcb8ae9b 1719 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
74fc764d 1720 {
5c895f64 1721 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1722
1723 const auto libObjPtr = bt_field_class_array_dynamic_create(
341a67c4 1724 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
74fc764d
PP
1725
1726 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1727 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1728 }
1729
1730 DynamicArrayWithLengthFieldClass::Shared
100fa861 1731 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
dcb8ae9b 1732 const IntegerFieldClass lengthFieldClass) const
74fc764d 1733 {
5c895f64 1734 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1735
1736 const auto libObjPtr = bt_field_class_array_dynamic_create(
341a67c4 1737 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
74fc764d
PP
1738
1739 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1740 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1741 }
1742
dcb8ae9b 1743 StructureFieldClass::Shared createStructureFieldClass() const
74fc764d 1744 {
5c895f64 1745 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1746
341a67c4 1747 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
74fc764d
PP
1748
1749 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1750 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1751 }
1752
dcb8ae9b 1753 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
74fc764d 1754 {
5c895f64 1755 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1756
1757 const auto libObjPtr = bt_field_class_option_without_selector_create(
341a67c4 1758 this->libObjPtr(), optionalFieldClass.libObjPtr());
74fc764d
PP
1759
1760 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1761 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1762 }
1763
1764 OptionWithBoolSelectorFieldClass::Shared
100fa861 1765 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
dcb8ae9b 1766 const FieldClass selectorFieldClass) const
74fc764d 1767 {
5c895f64 1768 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1769
1770 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
341a67c4 1771 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
74fc764d
PP
1772
1773 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1774 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1775 }
1776
1777 OptionWithUnsignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1778 createOptionWithUnsignedIntegerSelectorFieldClass(
1779 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1780 const ConstUnsignedIntegerRangeSet ranges) const
74fc764d 1781 {
5c895f64 1782 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1783
1784 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
341a67c4
FD
1785 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1786 ranges.libObjPtr());
74fc764d
PP
1787
1788 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1789 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1790 }
1791
1792 OptionWithSignedIntegerSelectorFieldClass::Shared
100fa861
PP
1793 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1794 const IntegerFieldClass selectorFieldClass,
dcb8ae9b 1795 const ConstSignedIntegerRangeSet ranges) const
74fc764d 1796 {
5c895f64 1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1798
1799 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
341a67c4
FD
1800 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1801 ranges.libObjPtr());
74fc764d
PP
1802
1803 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1804 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1805 }
1806
dcb8ae9b 1807 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
74fc764d 1808 {
5c895f64 1809 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1810
341a67c4 1811 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
74fc764d
PP
1812
1813 internal::validateCreatedObjPtr(libObjPtr);
c9c0b6e2 1814 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1815 }
1816
1817 VariantWithUnsignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1818 createVariantWithUnsignedIntegerSelectorFieldClass(
1819 const IntegerFieldClass selectorFieldClass) const
74fc764d 1820 {
69d96f80
FD
1821 return this->_createVariantWithIntegerSelectorFieldClass<
1822 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
74fc764d
PP
1823 }
1824
1825 VariantWithSignedIntegerSelectorFieldClass::Shared
dcb8ae9b
PP
1826 createVariantWithSignedIntegerSelectorFieldClass(
1827 const IntegerFieldClass selectorFieldClass) const
74fc764d 1828 {
69d96f80
FD
1829 return this->_createVariantWithIntegerSelectorFieldClass<
1830 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
74fc764d
PP
1831 }
1832
dcb8ae9b 1833 void assignsAutomaticStreamClassId(const bool val) const noexcept
74fc764d 1834 {
5c895f64 1835 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1836
341a67c4 1837 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
74fc764d
PP
1838 static_cast<bt_bool>(val));
1839 }
1840
1841 bool assignsAutomaticStreamClassId() const noexcept
1842 {
1843 return static_cast<bool>(
341a67c4 1844 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
74fc764d
PP
1845 }
1846
c0b73c63 1847 std::uint64_t length() const noexcept
74fc764d 1848 {
341a67c4 1849 return bt_trace_class_get_stream_class_count(this->libObjPtr());
74fc764d
PP
1850 }
1851
dcb8ae9b 1852 _StreamClass operator[](const std::uint64_t index) const noexcept
74fc764d 1853 {
341a67c4 1854 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
74fc764d
PP
1855 }
1856
ca61ecbc 1857 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
74fc764d 1858 {
ca61ecbc 1859 return _Spec::streamClassById(this->libObjPtr(), id);
74fc764d
PP
1860 }
1861
1862 template <typename LibValT>
b7ffa6f0 1863 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
74fc764d 1864 {
5c895f64 1865 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d 1866
341a67c4 1867 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
74fc764d
PP
1868 }
1869
dcb8ae9b 1870 UserAttributes userAttributes() const noexcept
74fc764d 1871 {
341a67c4 1872 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
74fc764d
PP
1873 }
1874
1875 Shared shared() const noexcept
1876 {
c9c0b6e2 1877 return Shared::createWithRef(*this);
74fc764d
PP
1878 }
1879
1880private:
69d96f80
FD
1881 template <typename ObjT>
1882 typename ObjT::Shared
dcb8ae9b 1883 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
74fc764d 1884 {
5c895f64 1885 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
74fc764d
PP
1886
1887 const auto libObjPtr =
341a67c4 1888 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
74fc764d
PP
1889
1890 internal::validateCreatedObjPtr(libObjPtr);
69d96f80 1891 return ObjT::Shared::createWithoutRef(libObjPtr);
74fc764d
PP
1892 }
1893};
1894
1895using TraceClass = CommonTraceClass<bt_trace_class>;
1896using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1897
4927bae7
PP
1898namespace internal {
1899
1900struct TraceClassTypeDescr
1901{
1902 using Const = ConstTraceClass;
1903 using NonConst = TraceClass;
1904};
1905
1906template <>
1907struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1908{
1909};
1910
1911template <>
1912struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1913{
1914};
1915
1916} /* namespace internal */
1917
74fc764d 1918template <typename LibObjT>
dcb8ae9b
PP
1919typename CommonStreamClass<LibObjT>::_TraceClass
1920CommonStreamClass<LibObjT>::traceClass() const noexcept
74fc764d 1921{
341a67c4 1922 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
74fc764d
PP
1923}
1924
1925template <typename LibObjT>
dcb8ae9b 1926typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
74fc764d 1927{
341a67c4 1928 return Class {_Spec::cls(this->libObjPtr())};
74fc764d
PP
1929}
1930
b5f55e9f 1931} /* namespace bt2 */
74fc764d 1932
b5f55e9f 1933#endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */
This page took 0.138845 seconds and 4 git commands to generate.