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