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