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 | 132 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
74fc764d | 133 | using _Spec = internal::CommonEventSpec<LibObjT>; |
8047a175 PP |
134 | using _Packet = internal::DepPacket<LibObjT>; |
135 | using _Stream = internal::DepStream<LibObjT>; | |
136 | using _StructureField = internal::DepStructField<LibObjT>; | |
74fc764d PP |
137 | |
138 | public: | |
d246c457 PP |
139 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
140 | ||
8047a175 PP |
141 | using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>, |
142 | CommonEventClass<const bt_event_class>>; | |
74fc764d | 143 | |
d246c457 | 144 | explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
145 | { |
146 | } | |
147 | ||
148 | template <typename OtherLibObjT> | |
0d218157 | 149 | CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event} |
74fc764d PP |
150 | { |
151 | } | |
152 | ||
153 | template <typename OtherLibObjT> | |
ac30a470 | 154 | CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept |
74fc764d | 155 | { |
0d218157 | 156 | _ThisBorrowedObject::operator=(event); |
74fc764d PP |
157 | return *this; |
158 | } | |
159 | ||
328a274a PP |
160 | CommonEvent<const bt_event> asConst() const noexcept |
161 | { | |
162 | return CommonEvent<const bt_event> {*this}; | |
163 | } | |
164 | ||
dcb8ae9b PP |
165 | Class cls() const noexcept; |
166 | _Stream stream() const noexcept; | |
c022776a | 167 | bt2s::optional<_Packet> packet() const noexcept; |
74fc764d | 168 | |
c022776a | 169 | bt2s::optional<_StructureField> payloadField() const noexcept |
74fc764d | 170 | { |
341a67c4 | 171 | const auto libObjPtr = _Spec::payloadField(this->libObjPtr()); |
74fc764d PP |
172 | |
173 | if (libObjPtr) { | |
174 | return _StructureField {libObjPtr}; | |
175 | } | |
176 | ||
c022776a | 177 | return bt2s::nullopt; |
74fc764d PP |
178 | } |
179 | ||
c022776a | 180 | bt2s::optional<_StructureField> specificContextField() const noexcept |
74fc764d | 181 | { |
341a67c4 | 182 | const auto libObjPtr = _Spec::specificContextField(this->libObjPtr()); |
74fc764d PP |
183 | |
184 | if (libObjPtr) { | |
185 | return _StructureField {libObjPtr}; | |
186 | } | |
187 | ||
c022776a | 188 | return bt2s::nullopt; |
74fc764d PP |
189 | } |
190 | ||
c022776a | 191 | bt2s::optional<_StructureField> commonContextField() const noexcept |
74fc764d | 192 | { |
341a67c4 | 193 | const auto libObjPtr = _Spec::commonContextField(this->libObjPtr()); |
74fc764d PP |
194 | |
195 | if (libObjPtr) { | |
196 | return _StructureField {libObjPtr}; | |
197 | } | |
198 | ||
c022776a | 199 | return bt2s::nullopt; |
74fc764d PP |
200 | } |
201 | }; | |
202 | ||
203 | using Event = CommonEvent<bt_event>; | |
204 | using ConstEvent = CommonEvent<const bt_event>; | |
205 | ||
206 | namespace internal { | |
207 | ||
4927bae7 PP |
208 | struct EventTypeDescr |
209 | { | |
210 | using Const = ConstEvent; | |
211 | using NonConst = Event; | |
212 | }; | |
213 | ||
214 | template <> | |
215 | struct TypeDescr<Event> : public EventTypeDescr | |
216 | { | |
217 | }; | |
218 | ||
219 | template <> | |
220 | struct TypeDescr<ConstEvent> : public EventTypeDescr | |
221 | { | |
222 | }; | |
223 | ||
74fc764d PP |
224 | struct PacketRefFuncs final |
225 | { | |
c677c492 | 226 | static void get(const bt_packet * const libObjPtr) noexcept |
74fc764d PP |
227 | { |
228 | bt_packet_get_ref(libObjPtr); | |
229 | } | |
230 | ||
c677c492 | 231 | static void put(const bt_packet * const libObjPtr) noexcept |
74fc764d PP |
232 | { |
233 | bt_packet_put_ref(libObjPtr); | |
234 | } | |
235 | }; | |
236 | ||
237 | template <typename LibObjT> | |
238 | struct CommonPacketSpec; | |
239 | ||
b5f55e9f | 240 | /* Functions specific to mutable packets */ |
74fc764d PP |
241 | template <> |
242 | struct CommonPacketSpec<bt_packet> final | |
243 | { | |
244 | static bt_stream *stream(bt_packet * const libObjPtr) noexcept | |
245 | { | |
246 | return bt_packet_borrow_stream(libObjPtr); | |
247 | } | |
248 | ||
249 | static bt_field *contextField(bt_packet * const libObjPtr) noexcept | |
250 | { | |
251 | return bt_packet_borrow_context_field(libObjPtr); | |
252 | } | |
253 | }; | |
254 | ||
b5f55e9f | 255 | /* Functions specific to constant packets */ |
74fc764d PP |
256 | template <> |
257 | struct CommonPacketSpec<const bt_packet> final | |
258 | { | |
259 | static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept | |
260 | { | |
261 | return bt_packet_borrow_stream_const(libObjPtr); | |
262 | } | |
263 | ||
264 | static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept | |
265 | { | |
266 | return bt_packet_borrow_context_field_const(libObjPtr); | |
267 | } | |
268 | }; | |
269 | ||
b5f55e9f | 270 | } /* namespace internal */ |
74fc764d PP |
271 | |
272 | template <typename LibObjT> | |
0d218157 | 273 | class CommonPacket final : public BorrowedObject<LibObjT> |
74fc764d PP |
274 | { |
275 | private: | |
0d218157 | 276 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
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: | |
d246c457 | 282 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 283 | using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>; |
74fc764d | 284 | |
d246c457 | 285 | explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
286 | { |
287 | } | |
288 | ||
289 | template <typename OtherLibObjT> | |
0d218157 | 290 | CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet} |
74fc764d PP |
291 | { |
292 | } | |
293 | ||
294 | template <typename OtherLibObjT> | |
ac30a470 | 295 | CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept |
74fc764d | 296 | { |
0d218157 | 297 | _ThisBorrowedObject::operator=(packet); |
74fc764d PP |
298 | return *this; |
299 | } | |
300 | ||
328a274a PP |
301 | CommonPacket<const bt_packet> asConst() const noexcept |
302 | { | |
303 | return CommonPacket<const bt_packet> {*this}; | |
304 | } | |
305 | ||
dcb8ae9b | 306 | _Stream stream() const noexcept; |
74fc764d | 307 | |
c022776a | 308 | bt2s::optional<_StructureField> contextField() const noexcept |
74fc764d | 309 | { |
341a67c4 | 310 | const auto libObjPtr = _Spec::contextField(this->libObjPtr()); |
74fc764d PP |
311 | |
312 | if (libObjPtr) { | |
313 | return _StructureField {libObjPtr}; | |
314 | } | |
315 | ||
c022776a | 316 | return bt2s::nullopt; |
74fc764d PP |
317 | } |
318 | ||
319 | Shared shared() const noexcept | |
320 | { | |
c9c0b6e2 | 321 | return Shared::createWithRef(*this); |
74fc764d PP |
322 | } |
323 | }; | |
324 | ||
325 | using Packet = CommonPacket<bt_packet>; | |
326 | using ConstPacket = CommonPacket<const bt_packet>; | |
327 | ||
4927bae7 PP |
328 | namespace internal { |
329 | ||
330 | struct PacketTypeDescr | |
331 | { | |
332 | using Const = ConstPacket; | |
333 | using NonConst = Packet; | |
334 | }; | |
335 | ||
336 | template <> | |
337 | struct TypeDescr<Packet> : public PacketTypeDescr | |
338 | { | |
339 | }; | |
340 | ||
341 | template <> | |
342 | struct TypeDescr<ConstPacket> : public PacketTypeDescr | |
343 | { | |
344 | }; | |
345 | ||
346 | } /* namespace internal */ | |
347 | ||
74fc764d | 348 | template <typename LibObjT> |
c022776a | 349 | bt2s::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() const noexcept |
74fc764d | 350 | { |
341a67c4 | 351 | const auto libObjPtr = _Spec::packet(this->libObjPtr()); |
74fc764d PP |
352 | |
353 | if (libObjPtr) { | |
354 | return _Packet {libObjPtr}; | |
355 | } | |
356 | ||
c022776a | 357 | return bt2s::nullopt; |
74fc764d PP |
358 | } |
359 | ||
360 | namespace internal { | |
361 | ||
362 | struct StreamRefFuncs final | |
363 | { | |
c677c492 | 364 | static void get(const bt_stream * const libObjPtr) noexcept |
74fc764d PP |
365 | { |
366 | bt_stream_get_ref(libObjPtr); | |
367 | } | |
368 | ||
c677c492 | 369 | static void put(const bt_stream * const libObjPtr) noexcept |
74fc764d PP |
370 | { |
371 | bt_stream_put_ref(libObjPtr); | |
372 | } | |
373 | }; | |
374 | ||
375 | template <typename LibObjT> | |
376 | struct CommonStreamSpec; | |
377 | ||
b5f55e9f | 378 | /* Functions specific to mutable streams */ |
74fc764d PP |
379 | template <> |
380 | struct CommonStreamSpec<bt_stream> final | |
381 | { | |
382 | static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept | |
383 | { | |
384 | return bt_stream_borrow_class(libObjPtr); | |
385 | } | |
386 | ||
387 | static bt_trace *trace(bt_stream * const libObjPtr) noexcept | |
388 | { | |
389 | return bt_stream_borrow_trace(libObjPtr); | |
390 | } | |
391 | ||
392 | static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept | |
393 | { | |
394 | return bt_stream_borrow_user_attributes(libObjPtr); | |
395 | } | |
396 | }; | |
397 | ||
b5f55e9f | 398 | /* Functions specific to constant streams */ |
74fc764d PP |
399 | template <> |
400 | struct CommonStreamSpec<const bt_stream> final | |
401 | { | |
402 | static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept | |
403 | { | |
404 | return bt_stream_borrow_class_const(libObjPtr); | |
405 | } | |
406 | ||
407 | static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept | |
408 | { | |
409 | return bt_stream_borrow_trace_const(libObjPtr); | |
410 | } | |
411 | ||
412 | static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept | |
413 | { | |
414 | return bt_stream_borrow_user_attributes_const(libObjPtr); | |
415 | } | |
416 | }; | |
417 | ||
b5f55e9f | 418 | } /* namespace internal */ |
74fc764d PP |
419 | |
420 | template <typename LibObjT> | |
0d218157 | 421 | class CommonStream final : public BorrowedObject<LibObjT> |
74fc764d PP |
422 | { |
423 | private: | |
0d218157 | 424 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
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: | |
d246c457 | 429 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 430 | using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>; |
8047a175 | 431 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
74fc764d | 432 | |
8047a175 PP |
433 | using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>, |
434 | CommonStreamClass<const bt_stream_class>>; | |
74fc764d | 435 | |
d246c457 | 436 | explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
437 | { |
438 | } | |
439 | ||
440 | template <typename OtherLibObjT> | |
0d218157 | 441 | CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream} |
74fc764d PP |
442 | { |
443 | } | |
444 | ||
445 | template <typename OtherLibObjT> | |
ac30a470 | 446 | CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept |
74fc764d | 447 | { |
0d218157 | 448 | _ThisBorrowedObject::operator=(stream); |
74fc764d PP |
449 | return *this; |
450 | } | |
451 | ||
328a274a PP |
452 | CommonStream<const bt_stream> asConst() const noexcept |
453 | { | |
454 | return CommonStream<const bt_stream> {*this}; | |
455 | } | |
456 | ||
dcb8ae9b | 457 | Packet::Shared createPacket() const |
74fc764d | 458 | { |
5c895f64 | 459 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
74fc764d | 460 | |
341a67c4 | 461 | const auto libObjPtr = bt_packet_create(this->libObjPtr()); |
74fc764d PP |
462 | |
463 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 464 | return Packet::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
465 | } |
466 | ||
dcb8ae9b PP |
467 | Class cls() const noexcept; |
468 | _Trace trace() const noexcept; | |
74fc764d PP |
469 | |
470 | std::uint64_t id() const noexcept | |
471 | { | |
341a67c4 | 472 | return bt_stream_get_id(this->libObjPtr()); |
74fc764d PP |
473 | } |
474 | ||
dcb8ae9b | 475 | void name(const char * const name) const |
74fc764d | 476 | { |
5c895f64 | 477 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
74fc764d | 478 | |
341a67c4 | 479 | const auto status = bt_stream_set_name(this->libObjPtr(), name); |
74fc764d PP |
480 | |
481 | if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 482 | throw MemoryError {}; |
74fc764d PP |
483 | } |
484 | } | |
485 | ||
dcb8ae9b | 486 | void name(const std::string& name) const |
74fc764d PP |
487 | { |
488 | this->name(name.data()); | |
489 | } | |
490 | ||
5cc5088c | 491 | const char *name() const noexcept |
74fc764d | 492 | { |
5cc5088c | 493 | return bt_stream_get_name(this->libObjPtr()); |
74fc764d PP |
494 | } |
495 | ||
496 | template <typename LibValT> | |
b7ffa6f0 | 497 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
74fc764d | 498 | { |
5c895f64 | 499 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
74fc764d | 500 | |
341a67c4 | 501 | bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
502 | } |
503 | ||
dcb8ae9b | 504 | UserAttributes userAttributes() const noexcept |
74fc764d | 505 | { |
341a67c4 | 506 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
507 | } |
508 | ||
509 | Shared shared() const noexcept | |
510 | { | |
c9c0b6e2 | 511 | return Shared::createWithRef(*this); |
74fc764d PP |
512 | } |
513 | }; | |
514 | ||
515 | using Stream = CommonStream<bt_stream>; | |
516 | using ConstStream = CommonStream<const bt_stream>; | |
517 | ||
4927bae7 PP |
518 | namespace internal { |
519 | ||
520 | struct StreamTypeDescr | |
521 | { | |
522 | using Const = ConstStream; | |
523 | using NonConst = Stream; | |
524 | }; | |
525 | ||
526 | template <> | |
527 | struct TypeDescr<Stream> : public StreamTypeDescr | |
528 | { | |
529 | }; | |
530 | ||
531 | template <> | |
532 | struct TypeDescr<ConstStream> : public StreamTypeDescr | |
533 | { | |
534 | }; | |
535 | ||
536 | } /* namespace internal */ | |
537 | ||
74fc764d | 538 | template <typename LibObjT> |
dcb8ae9b | 539 | typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept |
74fc764d | 540 | { |
341a67c4 | 541 | return _Stream {_Spec::stream(this->libObjPtr())}; |
74fc764d PP |
542 | } |
543 | ||
544 | template <typename LibObjT> | |
dcb8ae9b | 545 | typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept |
74fc764d | 546 | { |
341a67c4 | 547 | return _Stream {_Spec::stream(this->libObjPtr())}; |
74fc764d PP |
548 | } |
549 | ||
550 | namespace internal { | |
551 | ||
552 | struct TraceRefFuncs final | |
553 | { | |
c677c492 | 554 | static void get(const bt_trace * const libObjPtr) noexcept |
74fc764d PP |
555 | { |
556 | bt_trace_get_ref(libObjPtr); | |
557 | } | |
558 | ||
c677c492 | 559 | static void put(const bt_trace * const libObjPtr) noexcept |
74fc764d PP |
560 | { |
561 | bt_trace_put_ref(libObjPtr); | |
562 | } | |
563 | }; | |
564 | ||
565 | template <typename LibObjT> | |
566 | struct CommonTraceSpec; | |
567 | ||
b5f55e9f | 568 | /* Functions specific to mutable traces */ |
74fc764d PP |
569 | template <> |
570 | struct CommonTraceSpec<bt_trace> final | |
571 | { | |
572 | static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept | |
573 | { | |
574 | return bt_trace_borrow_class(libObjPtr); | |
575 | } | |
576 | ||
577 | static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept | |
578 | { | |
579 | return bt_trace_borrow_stream_by_index(libObjPtr, index); | |
580 | } | |
581 | ||
582 | static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept | |
583 | { | |
584 | return bt_trace_borrow_stream_by_id(libObjPtr, id); | |
585 | } | |
586 | ||
587 | static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept | |
588 | { | |
589 | return bt_trace_borrow_user_attributes(libObjPtr); | |
590 | } | |
591 | }; | |
592 | ||
b5f55e9f | 593 | /* Functions specific to constant traces */ |
74fc764d PP |
594 | template <> |
595 | struct CommonTraceSpec<const bt_trace> final | |
596 | { | |
597 | static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept | |
598 | { | |
599 | return bt_trace_borrow_class_const(libObjPtr); | |
600 | } | |
601 | ||
602 | static const bt_stream *streamByIndex(const bt_trace * const libObjPtr, | |
603 | const std::uint64_t index) noexcept | |
604 | { | |
605 | return bt_trace_borrow_stream_by_index_const(libObjPtr, index); | |
606 | } | |
607 | ||
608 | static const bt_stream *streamById(const bt_trace * const libObjPtr, | |
609 | const std::uint64_t id) noexcept | |
610 | { | |
611 | return bt_trace_borrow_stream_by_id_const(libObjPtr, id); | |
612 | } | |
613 | ||
614 | static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept | |
615 | { | |
616 | return bt_trace_borrow_user_attributes_const(libObjPtr); | |
617 | } | |
618 | }; | |
619 | ||
b5f55e9f | 620 | } /* namespace internal */ |
74fc764d PP |
621 | |
622 | template <typename LibObjT> | |
0d218157 | 623 | class CommonTrace final : public BorrowedObject<LibObjT> |
74fc764d | 624 | { |
74fc764d | 625 | private: |
0d218157 | 626 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
74fc764d | 627 | using _Spec = internal::CommonTraceSpec<LibObjT>; |
8047a175 | 628 | using _Stream = internal::DepStream<LibObjT>; |
74fc764d PP |
629 | |
630 | public: | |
d246c457 | 631 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 632 | using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>; |
8047a175 | 633 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
74fc764d | 634 | |
8047a175 PP |
635 | using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>, |
636 | CommonTraceClass<const bt_trace_class>>; | |
74fc764d PP |
637 | |
638 | struct ConstEnvironmentEntry | |
639 | { | |
5cc5088c | 640 | const char *name; |
74fc764d PP |
641 | ConstValue value; |
642 | }; | |
643 | ||
d246c457 | 644 | explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
645 | { |
646 | } | |
647 | ||
648 | template <typename OtherLibObjT> | |
0d218157 | 649 | CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace} |
74fc764d PP |
650 | { |
651 | } | |
652 | ||
653 | template <typename OtherLibObjT> | |
ac30a470 | 654 | CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept |
74fc764d | 655 | { |
0d218157 | 656 | _ThisBorrowedObject::operator=(trace); |
74fc764d PP |
657 | return *this; |
658 | } | |
659 | ||
328a274a PP |
660 | CommonTrace<const bt_trace> asConst() const noexcept |
661 | { | |
662 | return CommonTrace<const bt_trace> {*this}; | |
663 | } | |
664 | ||
dcb8ae9b | 665 | Class cls() const noexcept; |
74fc764d | 666 | |
dcb8ae9b | 667 | void name(const char * const name) const |
74fc764d | 668 | { |
5c895f64 | 669 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
74fc764d | 670 | |
341a67c4 | 671 | const auto status = bt_trace_set_name(this->libObjPtr(), name); |
74fc764d PP |
672 | |
673 | if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 674 | throw MemoryError {}; |
74fc764d PP |
675 | } |
676 | } | |
677 | ||
dcb8ae9b | 678 | void name(const std::string& name) const |
74fc764d PP |
679 | { |
680 | this->name(name.data()); | |
681 | } | |
682 | ||
5cc5088c | 683 | const char *name() const noexcept |
74fc764d | 684 | { |
5cc5088c | 685 | return bt_trace_get_name(this->libObjPtr()); |
74fc764d PP |
686 | } |
687 | ||
094bf3f2 | 688 | void uuid(const bt2c::UuidView& uuid) const noexcept |
74fc764d | 689 | { |
81d250db | 690 | bt_trace_set_uuid(this->libObjPtr(), uuid.begin()); |
74fc764d PP |
691 | } |
692 | ||
c022776a | 693 | bt2s::optional<bt2c::UuidView> uuid() const noexcept |
74fc764d | 694 | { |
341a67c4 | 695 | const auto uuid = bt_trace_get_uuid(this->libObjPtr()); |
74fc764d PP |
696 | |
697 | if (uuid) { | |
094bf3f2 | 698 | return bt2c::UuidView {uuid}; |
74fc764d PP |
699 | } |
700 | ||
c022776a | 701 | return bt2s::nullopt; |
74fc764d PP |
702 | } |
703 | ||
c0b73c63 | 704 | std::uint64_t length() const noexcept |
74fc764d | 705 | { |
341a67c4 | 706 | return bt_trace_get_stream_count(this->libObjPtr()); |
74fc764d PP |
707 | } |
708 | ||
dcb8ae9b | 709 | _Stream operator[](const std::uint64_t index) const noexcept |
74fc764d | 710 | { |
341a67c4 | 711 | return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
712 | } |
713 | ||
c022776a | 714 | bt2s::optional<_Stream> streamById(const std::uint64_t id) const noexcept |
74fc764d | 715 | { |
341a67c4 | 716 | const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id); |
74fc764d PP |
717 | |
718 | if (libObjPtr) { | |
719 | return _Stream {libObjPtr}; | |
720 | } | |
721 | ||
c022776a | 722 | return bt2s::nullopt; |
74fc764d PP |
723 | } |
724 | ||
dcb8ae9b | 725 | void environmentEntry(const char * const name, const std::int64_t val) const |
74fc764d | 726 | { |
5c895f64 | 727 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
74fc764d | 728 | |
341a67c4 | 729 | const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val); |
74fc764d PP |
730 | |
731 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { | |
39278ebc | 732 | throw MemoryError {}; |
74fc764d PP |
733 | } |
734 | } | |
735 | ||
dcb8ae9b | 736 | void environmentEntry(const std::string& name, const std::int64_t val) const |
74fc764d PP |
737 | { |
738 | this->environmentEntry(name.data(), val); | |
739 | } | |
740 | ||
dcb8ae9b | 741 | void environmentEntry(const char * const name, const char * const val) const |
74fc764d | 742 | { |
5c895f64 | 743 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
74fc764d | 744 | |
341a67c4 | 745 | const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val); |
74fc764d PP |
746 | |
747 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { | |
39278ebc | 748 | throw MemoryError {}; |
74fc764d PP |
749 | } |
750 | } | |
751 | ||
dcb8ae9b | 752 | void environmentEntry(const std::string& name, const char * const val) const |
74fc764d PP |
753 | { |
754 | this->environmentEntry(name.data(), val); | |
755 | } | |
756 | ||
dcb8ae9b | 757 | void environmentEntry(const char * const name, const std::string& val) const |
74fc764d PP |
758 | { |
759 | this->environmentEntry(name, val.data()); | |
760 | } | |
761 | ||
dcb8ae9b | 762 | void environmentEntry(const std::string& name, const std::string& val) const |
74fc764d PP |
763 | { |
764 | this->environmentEntry(name.data(), val.data()); | |
765 | } | |
766 | ||
767 | std::uint64_t environmentSize() const noexcept | |
768 | { | |
341a67c4 | 769 | return bt_trace_get_environment_entry_count(this->libObjPtr()); |
74fc764d PP |
770 | } |
771 | ||
772 | ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept | |
773 | { | |
774 | const char *name; | |
775 | const bt_value *libObjPtr; | |
776 | ||
341a67c4 | 777 | bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name, |
74fc764d PP |
778 | &libObjPtr); |
779 | return ConstEnvironmentEntry {name, ConstValue {libObjPtr}}; | |
780 | } | |
781 | ||
c022776a | 782 | bt2s::optional<ConstValue> environmentEntry(const char * const name) const noexcept |
74fc764d PP |
783 | { |
784 | const auto libObjPtr = | |
341a67c4 | 785 | bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name); |
74fc764d PP |
786 | |
787 | if (libObjPtr) { | |
788 | return ConstValue {libObjPtr}; | |
789 | } | |
790 | ||
c022776a | 791 | return bt2s::nullopt; |
74fc764d PP |
792 | } |
793 | ||
c022776a | 794 | bt2s::optional<ConstValue> environmentEntry(const std::string& name) const noexcept |
74fc764d PP |
795 | { |
796 | return this->environmentEntry(name.data()); | |
797 | } | |
798 | ||
799 | template <typename LibValT> | |
b7ffa6f0 | 800 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
74fc764d | 801 | { |
5c895f64 | 802 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
74fc764d | 803 | |
341a67c4 | 804 | bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
805 | } |
806 | ||
dcb8ae9b | 807 | UserAttributes userAttributes() const noexcept |
74fc764d | 808 | { |
341a67c4 | 809 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
810 | } |
811 | ||
812 | Shared shared() const noexcept | |
813 | { | |
c9c0b6e2 | 814 | return Shared::createWithRef(*this); |
74fc764d PP |
815 | } |
816 | }; | |
817 | ||
818 | using Trace = CommonTrace<bt_trace>; | |
819 | using ConstTrace = CommonTrace<const bt_trace>; | |
820 | ||
4927bae7 PP |
821 | namespace internal { |
822 | ||
823 | struct TraceTypeDescr | |
824 | { | |
825 | using Const = ConstTrace; | |
826 | using NonConst = Trace; | |
827 | }; | |
828 | ||
829 | template <> | |
830 | struct TypeDescr<Trace> : public TraceTypeDescr | |
831 | { | |
832 | }; | |
833 | ||
834 | template <> | |
835 | struct TypeDescr<ConstTrace> : public TraceTypeDescr | |
836 | { | |
837 | }; | |
838 | ||
839 | } /* namespace internal */ | |
840 | ||
74fc764d | 841 | template <typename LibObjT> |
dcb8ae9b | 842 | typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept |
74fc764d | 843 | { |
341a67c4 | 844 | return _Trace {_Spec::trace(this->libObjPtr())}; |
74fc764d PP |
845 | } |
846 | ||
847 | namespace internal { | |
848 | ||
849 | struct EventClassRefFuncs final | |
850 | { | |
c677c492 | 851 | static void get(const bt_event_class * const libObjPtr) noexcept |
74fc764d PP |
852 | { |
853 | bt_event_class_get_ref(libObjPtr); | |
854 | } | |
855 | ||
c677c492 | 856 | static void put(const bt_event_class * const libObjPtr) noexcept |
74fc764d PP |
857 | { |
858 | bt_event_class_put_ref(libObjPtr); | |
859 | } | |
860 | }; | |
861 | ||
862 | template <typename LibObjT> | |
863 | struct CommonEventClassSpec; | |
864 | ||
b5f55e9f | 865 | /* Functions specific to mutable event classes */ |
74fc764d PP |
866 | template <> |
867 | struct CommonEventClassSpec<bt_event_class> final | |
868 | { | |
869 | static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept | |
870 | { | |
871 | return bt_event_class_borrow_stream_class(libObjPtr); | |
872 | } | |
873 | ||
874 | static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept | |
875 | { | |
876 | return bt_event_class_borrow_payload_field_class(libObjPtr); | |
877 | } | |
878 | ||
879 | static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept | |
880 | { | |
881 | return bt_event_class_borrow_specific_context_field_class(libObjPtr); | |
882 | } | |
883 | ||
884 | static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept | |
885 | { | |
886 | return bt_event_class_borrow_user_attributes(libObjPtr); | |
887 | } | |
888 | }; | |
889 | ||
b5f55e9f | 890 | /* Functions specific to constant event classes */ |
74fc764d PP |
891 | template <> |
892 | struct CommonEventClassSpec<const bt_event_class> final | |
893 | { | |
894 | static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept | |
895 | { | |
896 | return bt_event_class_borrow_stream_class_const(libObjPtr); | |
897 | } | |
898 | ||
899 | static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept | |
900 | { | |
901 | return bt_event_class_borrow_payload_field_class_const(libObjPtr); | |
902 | } | |
903 | ||
904 | static const bt_field_class * | |
905 | specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept | |
906 | { | |
907 | return bt_event_class_borrow_specific_context_field_class_const(libObjPtr); | |
908 | } | |
909 | ||
910 | static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept | |
911 | { | |
912 | return bt_event_class_borrow_user_attributes_const(libObjPtr); | |
913 | } | |
914 | }; | |
915 | ||
8047a175 PP |
916 | template <typename LibObjT> |
917 | using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>; | |
918 | ||
b5f55e9f | 919 | } /* namespace internal */ |
74fc764d PP |
920 | |
921 | template <typename LibObjT> | |
0d218157 | 922 | class CommonEventClass final : public BorrowedObject<LibObjT> |
74fc764d PP |
923 | { |
924 | private: | |
0d218157 | 925 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
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: | |
d246c457 | 933 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 934 | using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>; |
8047a175 | 935 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
74fc764d PP |
936 | |
937 | enum class LogLevel | |
938 | { | |
939 | EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY, | |
940 | ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT, | |
941 | CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL, | |
0c0001b4 | 942 | ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR, |
74fc764d PP |
943 | WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING, |
944 | NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE, | |
945 | INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO, | |
946 | DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM, | |
947 | DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM, | |
0c0001b4 | 948 | DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS, |
74fc764d PP |
949 | DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE, |
950 | DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT, | |
951 | DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION, | |
952 | DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE, | |
953 | DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG, | |
954 | }; | |
955 | ||
d246c457 | 956 | explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
957 | { |
958 | } | |
959 | ||
960 | template <typename OtherLibObjT> | |
100fa861 | 961 | CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept : |
0d218157 | 962 | _ThisBorrowedObject {eventClass} |
74fc764d PP |
963 | { |
964 | } | |
965 | ||
966 | template <typename OtherLibObjT> | |
ac30a470 | 967 | CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept |
74fc764d | 968 | { |
0d218157 | 969 | _ThisBorrowedObject::operator=(eventClass); |
74fc764d PP |
970 | return *this; |
971 | } | |
972 | ||
328a274a PP |
973 | CommonEventClass<const bt_event_class> asConst() const noexcept |
974 | { | |
975 | return CommonEventClass<const bt_event_class> {*this}; | |
976 | } | |
977 | ||
dcb8ae9b | 978 | _StreamClass streamClass() const noexcept; |
74fc764d PP |
979 | |
980 | std::uint64_t id() const noexcept | |
981 | { | |
341a67c4 | 982 | return bt_event_class_get_id(this->libObjPtr()); |
74fc764d PP |
983 | } |
984 | ||
dcb8ae9b | 985 | void name(const char * const name) const |
74fc764d | 986 | { |
5c895f64 | 987 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d | 988 | |
341a67c4 | 989 | const auto status = bt_event_class_set_name(this->libObjPtr(), name); |
74fc764d PP |
990 | |
991 | if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 992 | throw MemoryError {}; |
74fc764d PP |
993 | } |
994 | } | |
995 | ||
dcb8ae9b | 996 | void name(const std::string& name) const |
74fc764d PP |
997 | { |
998 | this->name(name.data()); | |
999 | } | |
1000 | ||
5cc5088c | 1001 | const char *name() const noexcept |
74fc764d | 1002 | { |
5cc5088c | 1003 | return bt_event_class_get_name(this->libObjPtr()); |
74fc764d PP |
1004 | } |
1005 | ||
dcb8ae9b | 1006 | void logLevel(const LogLevel logLevel) const noexcept |
74fc764d | 1007 | { |
5c895f64 | 1008 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d | 1009 | |
341a67c4 | 1010 | bt_event_class_set_log_level(this->libObjPtr(), |
74fc764d PP |
1011 | static_cast<bt_event_class_log_level>(logLevel)); |
1012 | } | |
1013 | ||
c022776a | 1014 | bt2s::optional<LogLevel> logLevel() const noexcept |
74fc764d PP |
1015 | { |
1016 | bt_event_class_log_level libLogLevel; | |
341a67c4 | 1017 | const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel); |
74fc764d PP |
1018 | |
1019 | if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { | |
1020 | return static_cast<LogLevel>(libLogLevel); | |
1021 | } | |
1022 | ||
c022776a | 1023 | return bt2s::nullopt; |
74fc764d PP |
1024 | } |
1025 | ||
dcb8ae9b | 1026 | void emfUri(const char * const emfUri) const |
74fc764d | 1027 | { |
5c895f64 | 1028 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d | 1029 | |
341a67c4 | 1030 | const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri); |
74fc764d PP |
1031 | |
1032 | if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) { | |
39278ebc | 1033 | throw MemoryError {}; |
74fc764d PP |
1034 | } |
1035 | } | |
1036 | ||
dcb8ae9b | 1037 | void emfUri(const std::string& emfUri) const |
74fc764d PP |
1038 | { |
1039 | this->emfUri(emfUri.data()); | |
1040 | } | |
1041 | ||
5cc5088c | 1042 | const char *emfUri() const noexcept |
74fc764d | 1043 | { |
5cc5088c | 1044 | return bt_event_class_get_emf_uri(this->libObjPtr()); |
74fc764d PP |
1045 | } |
1046 | ||
dcb8ae9b | 1047 | void payloadFieldClass(const StructureFieldClass fc) const |
74fc764d | 1048 | { |
5c895f64 | 1049 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d PP |
1050 | |
1051 | const auto status = | |
341a67c4 | 1052 | bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr()); |
74fc764d PP |
1053 | |
1054 | if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { | |
39278ebc | 1055 | throw MemoryError {}; |
74fc764d PP |
1056 | } |
1057 | } | |
1058 | ||
c022776a | 1059 | bt2s::optional<_StructureFieldClass> payloadFieldClass() const noexcept |
74fc764d | 1060 | { |
341a67c4 | 1061 | const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr()); |
74fc764d PP |
1062 | |
1063 | if (libObjPtr) { | |
1064 | return _StructureFieldClass {libObjPtr}; | |
1065 | } | |
1066 | ||
c022776a | 1067 | return bt2s::nullopt; |
74fc764d PP |
1068 | } |
1069 | ||
dcb8ae9b | 1070 | void specificContextFieldClass(const StructureFieldClass fc) const |
74fc764d | 1071 | { |
5c895f64 | 1072 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d PP |
1073 | |
1074 | const auto status = | |
341a67c4 | 1075 | bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr()); |
74fc764d PP |
1076 | |
1077 | if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { | |
39278ebc | 1078 | throw MemoryError {}; |
74fc764d PP |
1079 | } |
1080 | } | |
1081 | ||
c022776a | 1082 | bt2s::optional<_StructureFieldClass> specificContextFieldClass() const noexcept |
74fc764d | 1083 | { |
341a67c4 | 1084 | const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr()); |
74fc764d PP |
1085 | |
1086 | if (libObjPtr) { | |
1087 | return _StructureFieldClass {libObjPtr}; | |
1088 | } | |
1089 | ||
c022776a | 1090 | return bt2s::nullopt; |
74fc764d PP |
1091 | } |
1092 | ||
1093 | template <typename LibValT> | |
b7ffa6f0 | 1094 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
74fc764d | 1095 | { |
5c895f64 | 1096 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
74fc764d | 1097 | |
341a67c4 | 1098 | bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
1099 | } |
1100 | ||
dcb8ae9b | 1101 | UserAttributes userAttributes() const noexcept |
74fc764d | 1102 | { |
341a67c4 | 1103 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
1104 | } |
1105 | ||
1106 | Shared shared() const noexcept | |
1107 | { | |
c9c0b6e2 | 1108 | return Shared::createWithRef(*this); |
74fc764d PP |
1109 | } |
1110 | }; | |
1111 | ||
1112 | using EventClass = CommonEventClass<bt_event_class>; | |
1113 | using ConstEventClass = CommonEventClass<const bt_event_class>; | |
1114 | ||
4927bae7 PP |
1115 | namespace internal { |
1116 | ||
1117 | struct EventClassTypeDescr | |
1118 | { | |
1119 | using Const = ConstEventClass; | |
1120 | using NonConst = EventClass; | |
1121 | }; | |
1122 | ||
1123 | template <> | |
1124 | struct TypeDescr<EventClass> : public EventClassTypeDescr | |
1125 | { | |
1126 | }; | |
1127 | ||
1128 | template <> | |
1129 | struct TypeDescr<ConstEventClass> : public EventClassTypeDescr | |
1130 | { | |
1131 | }; | |
1132 | ||
1133 | } /* namespace internal */ | |
1134 | ||
74fc764d | 1135 | template <typename LibObjT> |
dcb8ae9b | 1136 | typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept |
74fc764d | 1137 | { |
341a67c4 | 1138 | return Class {_Spec::cls(this->libObjPtr())}; |
74fc764d PP |
1139 | } |
1140 | ||
1141 | namespace internal { | |
1142 | ||
1143 | struct StreamClassRefFuncs final | |
1144 | { | |
c677c492 | 1145 | static void get(const bt_stream_class * const libObjPtr) noexcept |
74fc764d PP |
1146 | { |
1147 | bt_stream_class_get_ref(libObjPtr); | |
1148 | } | |
1149 | ||
c677c492 | 1150 | static void put(const bt_stream_class * const libObjPtr) noexcept |
74fc764d PP |
1151 | { |
1152 | bt_stream_class_put_ref(libObjPtr); | |
1153 | } | |
1154 | }; | |
1155 | ||
1156 | template <typename LibObjT> | |
1157 | struct CommonStreamClassSpec; | |
1158 | ||
b5f55e9f | 1159 | /* Functions specific to mutable stream classes */ |
74fc764d PP |
1160 | template <> |
1161 | struct CommonStreamClassSpec<bt_stream_class> final | |
1162 | { | |
1163 | static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept | |
1164 | { | |
1165 | return bt_stream_class_borrow_trace_class(libObjPtr); | |
1166 | } | |
1167 | ||
1168 | static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr, | |
1169 | const std::uint64_t index) noexcept | |
1170 | { | |
1171 | return bt_stream_class_borrow_event_class_by_index(libObjPtr, index); | |
1172 | } | |
1173 | ||
1174 | static bt_event_class *eventClassById(bt_stream_class * const libObjPtr, | |
1175 | const std::uint64_t id) noexcept | |
1176 | { | |
1177 | return bt_stream_class_borrow_event_class_by_id(libObjPtr, id); | |
1178 | } | |
1179 | ||
1180 | static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept | |
1181 | { | |
1182 | return bt_stream_class_borrow_default_clock_class(libObjPtr); | |
1183 | } | |
1184 | ||
1185 | static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept | |
1186 | { | |
1187 | return bt_stream_class_borrow_packet_context_field_class(libObjPtr); | |
1188 | } | |
1189 | ||
1190 | static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept | |
1191 | { | |
1192 | return bt_stream_class_borrow_event_common_context_field_class(libObjPtr); | |
1193 | } | |
1194 | ||
1195 | static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept | |
1196 | { | |
1197 | return bt_stream_class_borrow_user_attributes(libObjPtr); | |
1198 | } | |
1199 | }; | |
1200 | ||
b5f55e9f | 1201 | /* Functions specific to constant stream classes */ |
74fc764d PP |
1202 | template <> |
1203 | struct CommonStreamClassSpec<const bt_stream_class> final | |
1204 | { | |
1205 | static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept | |
1206 | { | |
1207 | return bt_stream_class_borrow_trace_class_const(libObjPtr); | |
1208 | } | |
1209 | ||
1210 | static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr, | |
1211 | const std::uint64_t index) noexcept | |
1212 | { | |
1213 | return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index); | |
1214 | } | |
1215 | ||
1216 | static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr, | |
1217 | const std::uint64_t id) noexcept | |
1218 | { | |
1219 | return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id); | |
1220 | } | |
1221 | ||
1222 | static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept | |
1223 | { | |
1224 | return bt_stream_class_borrow_default_clock_class_const(libObjPtr); | |
1225 | } | |
1226 | ||
1227 | static const bt_field_class * | |
1228 | packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept | |
1229 | { | |
1230 | return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr); | |
1231 | } | |
1232 | ||
1233 | static const bt_field_class * | |
1234 | eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept | |
1235 | { | |
1236 | return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr); | |
1237 | } | |
1238 | ||
1239 | static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept | |
1240 | { | |
1241 | return bt_stream_class_borrow_user_attributes_const(libObjPtr); | |
1242 | } | |
1243 | }; | |
1244 | ||
b5f55e9f | 1245 | } /* namespace internal */ |
74fc764d PP |
1246 | |
1247 | template <typename LibObjT> | |
0d218157 | 1248 | class CommonStreamClass final : public BorrowedObject<LibObjT> |
74fc764d PP |
1249 | { |
1250 | private: | |
0d218157 | 1251 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
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: | |
d246c457 | 1264 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 1265 | using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>; |
8047a175 | 1266 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
74fc764d | 1267 | |
d246c457 | 1268 | explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _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 | 1680 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
d246c457 | 1681 | |
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: | |
d246c457 | 1688 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
ac19444e | 1689 | using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>; |
8047a175 | 1690 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
74fc764d | 1691 | |
d246c457 | 1692 | explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
1693 | { |
1694 | } | |
1695 | ||
1696 | template <typename OtherLibObjT> | |
100fa861 | 1697 | CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept : |
0d218157 | 1698 | _ThisBorrowedObject {traceClass} |
74fc764d PP |
1699 | { |
1700 | } | |
1701 | ||
1702 | template <typename OtherLibObjT> | |
ac30a470 | 1703 | CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept |
74fc764d | 1704 | { |
0d218157 | 1705 | _ThisBorrowedObject::operator=(traceClass); |
74fc764d PP |
1706 | return *this; |
1707 | } | |
1708 | ||
328a274a PP |
1709 | CommonTraceClass<const bt_trace_class> asConst() const noexcept |
1710 | { | |
1711 | return CommonTraceClass<const bt_trace_class> {*this}; | |
1712 | } | |
1713 | ||
dcb8ae9b | 1714 | Trace::Shared instantiate() const |
74fc764d | 1715 | { |
5c895f64 | 1716 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1717 | |
341a67c4 | 1718 | const auto libObjPtr = bt_trace_create(this->libObjPtr()); |
74fc764d PP |
1719 | |
1720 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1721 | return Trace::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1722 | } |
1723 | ||
dcb8ae9b | 1724 | StreamClass::Shared createStreamClass() const |
74fc764d | 1725 | { |
5c895f64 | 1726 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1727 | |
341a67c4 | 1728 | const auto libObjPtr = bt_stream_class_create(this->libObjPtr()); |
74fc764d PP |
1729 | |
1730 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1731 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1732 | } |
1733 | ||
dcb8ae9b | 1734 | StreamClass::Shared createStreamClass(const std::uint64_t id) const |
74fc764d | 1735 | { |
5c895f64 | 1736 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1737 | |
341a67c4 | 1738 | const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id); |
74fc764d PP |
1739 | |
1740 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1741 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1742 | } |
1743 | ||
dcb8ae9b | 1744 | FieldClass::Shared createBoolFieldClass() const |
74fc764d | 1745 | { |
5c895f64 | 1746 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1747 | |
341a67c4 | 1748 | const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr()); |
74fc764d PP |
1749 | |
1750 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1751 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1752 | } |
1753 | ||
dcb8ae9b | 1754 | BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const |
74fc764d | 1755 | { |
5c895f64 | 1756 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1757 | |
341a67c4 | 1758 | const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length); |
74fc764d PP |
1759 | |
1760 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1761 | return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1762 | } |
1763 | ||
dcb8ae9b | 1764 | IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const |
74fc764d | 1765 | { |
5c895f64 | 1766 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1767 | |
341a67c4 | 1768 | const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr()); |
74fc764d PP |
1769 | |
1770 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1771 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1772 | } |
1773 | ||
dcb8ae9b | 1774 | IntegerFieldClass::Shared createSignedIntegerFieldClass() const |
74fc764d | 1775 | { |
5c895f64 | 1776 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1777 | |
341a67c4 | 1778 | const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr()); |
74fc764d PP |
1779 | |
1780 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1781 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1782 | } |
1783 | ||
dcb8ae9b | 1784 | UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const |
74fc764d | 1785 | { |
5c895f64 | 1786 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1787 | |
341a67c4 | 1788 | const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr()); |
74fc764d PP |
1789 | |
1790 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1791 | return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1792 | } |
1793 | ||
dcb8ae9b | 1794 | SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const |
74fc764d | 1795 | { |
5c895f64 | 1796 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1797 | |
341a67c4 | 1798 | const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr()); |
74fc764d PP |
1799 | |
1800 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1801 | return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1802 | } |
1803 | ||
dcb8ae9b | 1804 | FieldClass::Shared createSinglePrecisionRealFieldClass() const |
74fc764d | 1805 | { |
5c895f64 | 1806 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1807 | |
341a67c4 | 1808 | const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr()); |
74fc764d PP |
1809 | |
1810 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1811 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1812 | } |
1813 | ||
dcb8ae9b | 1814 | FieldClass::Shared createDoublePrecisionRealFieldClass() const |
74fc764d | 1815 | { |
5c895f64 | 1816 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1817 | |
341a67c4 | 1818 | const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr()); |
74fc764d PP |
1819 | |
1820 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1821 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1822 | } |
1823 | ||
dcb8ae9b | 1824 | FieldClass::Shared createStringFieldClass() const |
74fc764d | 1825 | { |
5c895f64 | 1826 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1827 | |
341a67c4 | 1828 | const auto libObjPtr = bt_field_class_string_create(this->libObjPtr()); |
74fc764d PP |
1829 | |
1830 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1831 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1832 | } |
1833 | ||
100fa861 | 1834 | StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass, |
dcb8ae9b | 1835 | const std::uint64_t length) const |
74fc764d | 1836 | { |
5c895f64 | 1837 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1838 | |
1839 | const auto libObjPtr = bt_field_class_array_static_create( | |
341a67c4 | 1840 | this->libObjPtr(), elementFieldClass.libObjPtr(), length); |
74fc764d PP |
1841 | |
1842 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1843 | return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1844 | } |
1845 | ||
dcb8ae9b | 1846 | ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const |
74fc764d | 1847 | { |
5c895f64 | 1848 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1849 | |
1850 | const auto libObjPtr = bt_field_class_array_dynamic_create( | |
341a67c4 | 1851 | this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr); |
74fc764d PP |
1852 | |
1853 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1854 | return ArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1855 | } |
1856 | ||
1857 | DynamicArrayWithLengthFieldClass::Shared | |
100fa861 | 1858 | createDynamicArrayFieldClass(const FieldClass elementFieldClass, |
dcb8ae9b | 1859 | const IntegerFieldClass lengthFieldClass) const |
74fc764d | 1860 | { |
5c895f64 | 1861 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1862 | |
1863 | const auto libObjPtr = bt_field_class_array_dynamic_create( | |
341a67c4 | 1864 | this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr()); |
74fc764d PP |
1865 | |
1866 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1867 | return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1868 | } |
1869 | ||
dcb8ae9b | 1870 | StructureFieldClass::Shared createStructureFieldClass() const |
74fc764d | 1871 | { |
5c895f64 | 1872 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1873 | |
341a67c4 | 1874 | const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr()); |
74fc764d PP |
1875 | |
1876 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1877 | return StructureFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1878 | } |
1879 | ||
dcb8ae9b | 1880 | OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const |
74fc764d | 1881 | { |
5c895f64 | 1882 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1883 | |
1884 | const auto libObjPtr = bt_field_class_option_without_selector_create( | |
341a67c4 | 1885 | this->libObjPtr(), optionalFieldClass.libObjPtr()); |
74fc764d PP |
1886 | |
1887 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1888 | return OptionFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1889 | } |
1890 | ||
1891 | OptionWithBoolSelectorFieldClass::Shared | |
100fa861 | 1892 | createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass, |
dcb8ae9b | 1893 | const FieldClass selectorFieldClass) const |
74fc764d | 1894 | { |
5c895f64 | 1895 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1896 | |
1897 | const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create( | |
341a67c4 | 1898 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr()); |
74fc764d PP |
1899 | |
1900 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1901 | return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1902 | } |
1903 | ||
1904 | OptionWithUnsignedIntegerSelectorFieldClass::Shared | |
dcb8ae9b PP |
1905 | createOptionWithUnsignedIntegerSelectorFieldClass( |
1906 | const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass, | |
1907 | const ConstUnsignedIntegerRangeSet ranges) const | |
74fc764d | 1908 | { |
5c895f64 | 1909 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
1910 | |
1911 | const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create( | |
341a67c4 FD |
1912 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
1913 | ranges.libObjPtr()); | |
74fc764d PP |
1914 | |
1915 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1916 | return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1917 | } |
1918 | ||
1919 | OptionWithSignedIntegerSelectorFieldClass::Shared | |
100fa861 PP |
1920 | createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass, |
1921 | const IntegerFieldClass selectorFieldClass, | |
dcb8ae9b | 1922 | const ConstSignedIntegerRangeSet ranges) 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_option_with_selector_field_integer_signed_create( | |
341a67c4 FD |
1927 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
1928 | ranges.libObjPtr()); | |
74fc764d PP |
1929 | |
1930 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1931 | return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1932 | } |
1933 | ||
dcb8ae9b | 1934 | VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const |
74fc764d | 1935 | { |
5c895f64 | 1936 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1937 | |
341a67c4 | 1938 | const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr); |
74fc764d PP |
1939 | |
1940 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1941 | return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1942 | } |
1943 | ||
1944 | VariantWithUnsignedIntegerSelectorFieldClass::Shared | |
dcb8ae9b PP |
1945 | createVariantWithUnsignedIntegerSelectorFieldClass( |
1946 | const IntegerFieldClass selectorFieldClass) const | |
74fc764d | 1947 | { |
69d96f80 FD |
1948 | return this->_createVariantWithIntegerSelectorFieldClass< |
1949 | VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass); | |
74fc764d PP |
1950 | } |
1951 | ||
1952 | VariantWithSignedIntegerSelectorFieldClass::Shared | |
dcb8ae9b PP |
1953 | createVariantWithSignedIntegerSelectorFieldClass( |
1954 | const IntegerFieldClass selectorFieldClass) const | |
74fc764d | 1955 | { |
69d96f80 FD |
1956 | return this->_createVariantWithIntegerSelectorFieldClass< |
1957 | VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass); | |
74fc764d PP |
1958 | } |
1959 | ||
dcb8ae9b | 1960 | void assignsAutomaticStreamClassId(const bool val) const noexcept |
74fc764d | 1961 | { |
5c895f64 | 1962 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1963 | |
341a67c4 | 1964 | bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(), |
74fc764d PP |
1965 | static_cast<bt_bool>(val)); |
1966 | } | |
1967 | ||
1968 | bool assignsAutomaticStreamClassId() const noexcept | |
1969 | { | |
1970 | return static_cast<bool>( | |
341a67c4 | 1971 | bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr())); |
74fc764d PP |
1972 | } |
1973 | ||
c0b73c63 | 1974 | std::uint64_t length() const noexcept |
74fc764d | 1975 | { |
341a67c4 | 1976 | return bt_trace_class_get_stream_class_count(this->libObjPtr()); |
74fc764d PP |
1977 | } |
1978 | ||
dcb8ae9b | 1979 | _StreamClass operator[](const std::uint64_t index) const noexcept |
74fc764d | 1980 | { |
341a67c4 | 1981 | return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
1982 | } |
1983 | ||
c022776a | 1984 | bt2s::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept |
74fc764d | 1985 | { |
341a67c4 | 1986 | const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id); |
74fc764d PP |
1987 | |
1988 | if (libObjPtr) { | |
1989 | return _StreamClass {libObjPtr}; | |
1990 | } | |
1991 | ||
c022776a | 1992 | return bt2s::nullopt; |
74fc764d PP |
1993 | } |
1994 | ||
1995 | template <typename LibValT> | |
b7ffa6f0 | 1996 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
74fc764d | 1997 | { |
5c895f64 | 1998 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d | 1999 | |
341a67c4 | 2000 | bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
2001 | } |
2002 | ||
dcb8ae9b | 2003 | UserAttributes userAttributes() const noexcept |
74fc764d | 2004 | { |
341a67c4 | 2005 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
2006 | } |
2007 | ||
2008 | Shared shared() const noexcept | |
2009 | { | |
c9c0b6e2 | 2010 | return Shared::createWithRef(*this); |
74fc764d PP |
2011 | } |
2012 | ||
2013 | private: | |
69d96f80 FD |
2014 | template <typename ObjT> |
2015 | typename ObjT::Shared | |
dcb8ae9b | 2016 | _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const |
74fc764d | 2017 | { |
5c895f64 | 2018 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
74fc764d PP |
2019 | |
2020 | const auto libObjPtr = | |
341a67c4 | 2021 | bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr()); |
74fc764d PP |
2022 | |
2023 | internal::validateCreatedObjPtr(libObjPtr); | |
69d96f80 | 2024 | return ObjT::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2025 | } |
2026 | }; | |
2027 | ||
2028 | using TraceClass = CommonTraceClass<bt_trace_class>; | |
2029 | using ConstTraceClass = CommonTraceClass<const bt_trace_class>; | |
2030 | ||
4927bae7 PP |
2031 | namespace internal { |
2032 | ||
2033 | struct TraceClassTypeDescr | |
2034 | { | |
2035 | using Const = ConstTraceClass; | |
2036 | using NonConst = TraceClass; | |
2037 | }; | |
2038 | ||
2039 | template <> | |
2040 | struct TypeDescr<TraceClass> : public TraceClassTypeDescr | |
2041 | { | |
2042 | }; | |
2043 | ||
2044 | template <> | |
2045 | struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr | |
2046 | { | |
2047 | }; | |
2048 | ||
2049 | } /* namespace internal */ | |
2050 | ||
74fc764d | 2051 | template <typename LibObjT> |
dcb8ae9b PP |
2052 | typename CommonStreamClass<LibObjT>::_TraceClass |
2053 | CommonStreamClass<LibObjT>::traceClass() const noexcept | |
74fc764d | 2054 | { |
341a67c4 | 2055 | return _TraceClass {_Spec::traceClass(this->libObjPtr())}; |
74fc764d PP |
2056 | } |
2057 | ||
2058 | template <typename LibObjT> | |
dcb8ae9b | 2059 | typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept |
74fc764d | 2060 | { |
341a67c4 | 2061 | return Class {_Spec::cls(this->libObjPtr())}; |
74fc764d PP |
2062 | } |
2063 | ||
b5f55e9f | 2064 | } /* namespace bt2 */ |
74fc764d | 2065 | |
b5f55e9f | 2066 | #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */ |