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