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