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