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