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