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