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