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