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" |
c802cacb | 23 | #include "value.hpp" |
74fc764d PP |
24 | |
25 | namespace bt2 { | |
26 | ||
27 | template <typename LibObjT> | |
28 | class CommonEvent; | |
29 | ||
30 | template <typename LibObjT> | |
31 | class CommonPacket; | |
32 | ||
33 | template <typename LibObjT> | |
34 | class CommonStream; | |
35 | ||
36 | template <typename LibObjT> | |
37 | class CommonTrace; | |
38 | ||
39 | template <typename LibObjT> | |
40 | class CommonEventClass; | |
41 | ||
42 | template <typename LibObjT> | |
43 | class CommonStreamClass; | |
44 | ||
45 | template <typename LibObjT> | |
46 | class CommonTraceClass; | |
47 | ||
48 | namespace internal { | |
49 | ||
50 | template <typename LibObjT> | |
51 | struct CommonEventSpec; | |
52 | ||
b5f55e9f | 53 | /* Functions specific to mutable events */ |
74fc764d PP |
54 | template <> |
55 | struct CommonEventSpec<bt_event> final | |
56 | { | |
57 | static bt_event_class *cls(bt_event * const libObjPtr) noexcept | |
58 | { | |
59 | return bt_event_borrow_class(libObjPtr); | |
60 | } | |
61 | ||
62 | static bt_stream *stream(bt_event * const libObjPtr) noexcept | |
63 | { | |
64 | return bt_event_borrow_stream(libObjPtr); | |
65 | } | |
66 | ||
67 | static bt_packet *packet(bt_event * const libObjPtr) noexcept | |
68 | { | |
69 | return bt_event_borrow_packet(libObjPtr); | |
70 | } | |
71 | ||
72 | static bt_field *payloadField(bt_event * const libObjPtr) noexcept | |
73 | { | |
74 | return bt_event_borrow_payload_field(libObjPtr); | |
75 | } | |
76 | ||
77 | static bt_field *specificContextField(bt_event * const libObjPtr) noexcept | |
78 | { | |
79 | return bt_event_borrow_specific_context_field(libObjPtr); | |
80 | } | |
81 | ||
82 | static bt_field *commonContextField(bt_event * const libObjPtr) noexcept | |
83 | { | |
84 | return bt_event_borrow_common_context_field(libObjPtr); | |
85 | } | |
86 | }; | |
87 | ||
b5f55e9f | 88 | /* Functions specific to constant events */ |
74fc764d PP |
89 | template <> |
90 | struct CommonEventSpec<const bt_event> final | |
91 | { | |
92 | static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept | |
93 | { | |
94 | return bt_event_borrow_class_const(libObjPtr); | |
95 | } | |
96 | ||
97 | static const bt_stream *stream(const bt_event * const libObjPtr) noexcept | |
98 | { | |
99 | return bt_event_borrow_stream_const(libObjPtr); | |
100 | } | |
101 | ||
102 | static const bt_packet *packet(const bt_event * const libObjPtr) noexcept | |
103 | { | |
104 | return bt_event_borrow_packet_const(libObjPtr); | |
105 | } | |
106 | ||
107 | static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept | |
108 | { | |
109 | return bt_event_borrow_payload_field_const(libObjPtr); | |
110 | } | |
111 | ||
112 | static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept | |
113 | { | |
114 | return bt_event_borrow_specific_context_field_const(libObjPtr); | |
115 | } | |
116 | ||
117 | static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept | |
118 | { | |
119 | return bt_event_borrow_common_context_field_const(libObjPtr); | |
120 | } | |
121 | }; | |
122 | ||
b5f55e9f | 123 | } /* namespace internal */ |
74fc764d PP |
124 | |
125 | template <typename LibObjT> | |
0d218157 | 126 | class CommonEvent final : public BorrowedObject<LibObjT> |
74fc764d PP |
127 | { |
128 | private: | |
0d218157 PP |
129 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
130 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
131 | using _ConstSpec = internal::CommonEventSpec<const bt_event>; |
132 | using _Spec = internal::CommonEventSpec<LibObjT>; | |
133 | ||
134 | using _Packet = | |
135 | typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>, | |
136 | CommonPacket<bt_packet>>::type; | |
137 | ||
138 | using _Stream = | |
139 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
140 | CommonStream<bt_stream>>::type; | |
141 | ||
142 | using _StructureField = typename std::conditional<std::is_const<LibObjT>::value, | |
143 | ConstStructureField, StructureField>::type; | |
144 | ||
145 | public: | |
146 | using Class = typename std::conditional<std::is_const<LibObjT>::value, | |
147 | CommonEventClass<const bt_event_class>, | |
148 | CommonEventClass<bt_event_class>>::type; | |
149 | ||
0d218157 | 150 | explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
151 | { |
152 | } | |
153 | ||
154 | template <typename OtherLibObjT> | |
0d218157 | 155 | CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event} |
74fc764d PP |
156 | { |
157 | } | |
158 | ||
159 | template <typename OtherLibObjT> | |
100fa861 | 160 | CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept |
74fc764d | 161 | { |
0d218157 | 162 | _ThisBorrowedObject::operator=(event); |
74fc764d PP |
163 | return *this; |
164 | } | |
165 | ||
166 | CommonEventClass<const bt_event_class> cls() const noexcept; | |
167 | Class cls() noexcept; | |
168 | CommonStream<const bt_stream> stream() const noexcept; | |
169 | _Stream stream() noexcept; | |
170 | nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept; | |
171 | nonstd::optional<_Packet> packet() noexcept; | |
172 | ||
173 | nonstd::optional<ConstStructureField> payloadField() const noexcept | |
174 | { | |
341a67c4 | 175 | const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr()); |
74fc764d PP |
176 | |
177 | if (libObjPtr) { | |
178 | return ConstStructureField {libObjPtr}; | |
179 | } | |
180 | ||
181 | return nonstd::nullopt; | |
182 | } | |
183 | ||
184 | nonstd::optional<_StructureField> payloadField() noexcept | |
185 | { | |
341a67c4 | 186 | const auto libObjPtr = _Spec::payloadField(this->libObjPtr()); |
74fc764d PP |
187 | |
188 | if (libObjPtr) { | |
189 | return _StructureField {libObjPtr}; | |
190 | } | |
191 | ||
192 | return nonstd::nullopt; | |
193 | } | |
194 | ||
195 | nonstd::optional<ConstStructureField> specificContextField() const noexcept | |
196 | { | |
341a67c4 | 197 | const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr()); |
74fc764d PP |
198 | |
199 | if (libObjPtr) { | |
200 | return ConstStructureField {libObjPtr}; | |
201 | } | |
202 | ||
203 | return nonstd::nullopt; | |
204 | } | |
205 | ||
206 | nonstd::optional<_StructureField> specificContextField() noexcept | |
207 | { | |
341a67c4 | 208 | const auto libObjPtr = _Spec::specificContextField(this->libObjPtr()); |
74fc764d PP |
209 | |
210 | if (libObjPtr) { | |
211 | return _StructureField {libObjPtr}; | |
212 | } | |
213 | ||
214 | return nonstd::nullopt; | |
215 | } | |
216 | ||
217 | nonstd::optional<ConstStructureField> commonContextField() const noexcept | |
218 | { | |
341a67c4 | 219 | const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr()); |
74fc764d PP |
220 | |
221 | if (libObjPtr) { | |
222 | return ConstStructureField {libObjPtr}; | |
223 | } | |
224 | ||
225 | return nonstd::nullopt; | |
226 | } | |
227 | ||
228 | nonstd::optional<_StructureField> commonContextField() noexcept | |
229 | { | |
341a67c4 | 230 | const auto libObjPtr = _Spec::commonContextField(this->libObjPtr()); |
74fc764d PP |
231 | |
232 | if (libObjPtr) { | |
233 | return _StructureField {libObjPtr}; | |
234 | } | |
235 | ||
236 | return nonstd::nullopt; | |
237 | } | |
238 | }; | |
239 | ||
240 | using Event = CommonEvent<bt_event>; | |
241 | using ConstEvent = CommonEvent<const bt_event>; | |
242 | ||
243 | namespace internal { | |
244 | ||
4927bae7 PP |
245 | struct EventTypeDescr |
246 | { | |
247 | using Const = ConstEvent; | |
248 | using NonConst = Event; | |
249 | }; | |
250 | ||
251 | template <> | |
252 | struct TypeDescr<Event> : public EventTypeDescr | |
253 | { | |
254 | }; | |
255 | ||
256 | template <> | |
257 | struct TypeDescr<ConstEvent> : public EventTypeDescr | |
258 | { | |
259 | }; | |
260 | ||
74fc764d PP |
261 | struct PacketRefFuncs final |
262 | { | |
263 | static void get(const bt_packet * const libObjPtr) | |
264 | { | |
265 | bt_packet_get_ref(libObjPtr); | |
266 | } | |
267 | ||
268 | static void put(const bt_packet * const libObjPtr) | |
269 | { | |
270 | bt_packet_put_ref(libObjPtr); | |
271 | } | |
272 | }; | |
273 | ||
274 | template <typename LibObjT> | |
275 | struct CommonPacketSpec; | |
276 | ||
b5f55e9f | 277 | /* Functions specific to mutable packets */ |
74fc764d PP |
278 | template <> |
279 | struct CommonPacketSpec<bt_packet> final | |
280 | { | |
281 | static bt_stream *stream(bt_packet * const libObjPtr) noexcept | |
282 | { | |
283 | return bt_packet_borrow_stream(libObjPtr); | |
284 | } | |
285 | ||
286 | static bt_field *contextField(bt_packet * const libObjPtr) noexcept | |
287 | { | |
288 | return bt_packet_borrow_context_field(libObjPtr); | |
289 | } | |
290 | }; | |
291 | ||
b5f55e9f | 292 | /* Functions specific to constant packets */ |
74fc764d PP |
293 | template <> |
294 | struct CommonPacketSpec<const bt_packet> final | |
295 | { | |
296 | static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept | |
297 | { | |
298 | return bt_packet_borrow_stream_const(libObjPtr); | |
299 | } | |
300 | ||
301 | static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept | |
302 | { | |
303 | return bt_packet_borrow_context_field_const(libObjPtr); | |
304 | } | |
305 | }; | |
306 | ||
b5f55e9f | 307 | } /* namespace internal */ |
74fc764d PP |
308 | |
309 | template <typename LibObjT> | |
0d218157 | 310 | class CommonPacket final : public BorrowedObject<LibObjT> |
74fc764d PP |
311 | { |
312 | private: | |
0d218157 PP |
313 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
314 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
315 | using _ConstSpec = internal::CommonPacketSpec<const bt_packet>; |
316 | using _Spec = internal::CommonPacketSpec<LibObjT>; | |
317 | using _ThisCommonPacket = CommonPacket<LibObjT>; | |
318 | ||
319 | using _Stream = | |
320 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
321 | CommonStream<bt_stream>>::type; | |
322 | ||
323 | using _StructureField = typename std::conditional<std::is_const<LibObjT>::value, | |
324 | ConstStructureField, StructureField>::type; | |
325 | ||
326 | public: | |
327 | using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>; | |
328 | ||
0d218157 | 329 | explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
330 | { |
331 | } | |
332 | ||
333 | template <typename OtherLibObjT> | |
0d218157 | 334 | CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet} |
74fc764d PP |
335 | { |
336 | } | |
337 | ||
338 | template <typename OtherLibObjT> | |
100fa861 | 339 | _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept |
74fc764d | 340 | { |
0d218157 | 341 | _ThisBorrowedObject::operator=(packet); |
74fc764d PP |
342 | return *this; |
343 | } | |
344 | ||
345 | CommonStream<const bt_stream> stream() const noexcept; | |
346 | _Stream stream() noexcept; | |
347 | ||
348 | nonstd::optional<ConstStructureField> contextField() const noexcept | |
349 | { | |
341a67c4 | 350 | const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr()); |
74fc764d PP |
351 | |
352 | if (libObjPtr) { | |
353 | return ConstStructureField {libObjPtr}; | |
354 | } | |
355 | ||
356 | return nonstd::nullopt; | |
357 | } | |
358 | ||
359 | nonstd::optional<_StructureField> contextField() noexcept | |
360 | { | |
341a67c4 | 361 | const auto libObjPtr = _Spec::contextField(this->libObjPtr()); |
74fc764d PP |
362 | |
363 | if (libObjPtr) { | |
364 | return _StructureField {libObjPtr}; | |
365 | } | |
366 | ||
367 | return nonstd::nullopt; | |
368 | } | |
369 | ||
370 | Shared shared() const noexcept | |
371 | { | |
c9c0b6e2 | 372 | return Shared::createWithRef(*this); |
74fc764d PP |
373 | } |
374 | }; | |
375 | ||
376 | using Packet = CommonPacket<bt_packet>; | |
377 | using ConstPacket = CommonPacket<const bt_packet>; | |
378 | ||
4927bae7 PP |
379 | namespace internal { |
380 | ||
381 | struct PacketTypeDescr | |
382 | { | |
383 | using Const = ConstPacket; | |
384 | using NonConst = Packet; | |
385 | }; | |
386 | ||
387 | template <> | |
388 | struct TypeDescr<Packet> : public PacketTypeDescr | |
389 | { | |
390 | }; | |
391 | ||
392 | template <> | |
393 | struct TypeDescr<ConstPacket> : public PacketTypeDescr | |
394 | { | |
395 | }; | |
396 | ||
397 | } /* namespace internal */ | |
398 | ||
74fc764d PP |
399 | template <typename LibObjT> |
400 | nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept | |
401 | { | |
341a67c4 | 402 | const auto libObjPtr = _ConstSpec::packet(this->libObjPtr()); |
74fc764d PP |
403 | |
404 | if (libObjPtr) { | |
405 | return ConstPacket {libObjPtr}; | |
406 | } | |
407 | ||
408 | return nonstd::nullopt; | |
409 | } | |
410 | ||
411 | template <typename LibObjT> | |
412 | nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept | |
413 | { | |
341a67c4 | 414 | const auto libObjPtr = _Spec::packet(this->libObjPtr()); |
74fc764d PP |
415 | |
416 | if (libObjPtr) { | |
417 | return _Packet {libObjPtr}; | |
418 | } | |
419 | ||
420 | return nonstd::nullopt; | |
421 | } | |
422 | ||
423 | namespace internal { | |
424 | ||
425 | struct StreamRefFuncs final | |
426 | { | |
427 | static void get(const bt_stream * const libObjPtr) | |
428 | { | |
429 | bt_stream_get_ref(libObjPtr); | |
430 | } | |
431 | ||
432 | static void put(const bt_stream * const libObjPtr) | |
433 | { | |
434 | bt_stream_put_ref(libObjPtr); | |
435 | } | |
436 | }; | |
437 | ||
438 | template <typename LibObjT> | |
439 | struct CommonStreamSpec; | |
440 | ||
b5f55e9f | 441 | /* Functions specific to mutable streams */ |
74fc764d PP |
442 | template <> |
443 | struct CommonStreamSpec<bt_stream> final | |
444 | { | |
445 | static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept | |
446 | { | |
447 | return bt_stream_borrow_class(libObjPtr); | |
448 | } | |
449 | ||
450 | static bt_trace *trace(bt_stream * const libObjPtr) noexcept | |
451 | { | |
452 | return bt_stream_borrow_trace(libObjPtr); | |
453 | } | |
454 | ||
455 | static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept | |
456 | { | |
457 | return bt_stream_borrow_user_attributes(libObjPtr); | |
458 | } | |
459 | }; | |
460 | ||
b5f55e9f | 461 | /* Functions specific to constant streams */ |
74fc764d PP |
462 | template <> |
463 | struct CommonStreamSpec<const bt_stream> final | |
464 | { | |
465 | static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept | |
466 | { | |
467 | return bt_stream_borrow_class_const(libObjPtr); | |
468 | } | |
469 | ||
470 | static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept | |
471 | { | |
472 | return bt_stream_borrow_trace_const(libObjPtr); | |
473 | } | |
474 | ||
475 | static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept | |
476 | { | |
477 | return bt_stream_borrow_user_attributes_const(libObjPtr); | |
478 | } | |
479 | }; | |
480 | ||
b5f55e9f | 481 | } /* namespace internal */ |
74fc764d PP |
482 | |
483 | template <typename LibObjT> | |
0d218157 | 484 | class CommonStream final : public BorrowedObject<LibObjT> |
74fc764d PP |
485 | { |
486 | private: | |
0d218157 PP |
487 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
488 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
489 | using _ConstSpec = internal::CommonStreamSpec<const bt_stream>; |
490 | using _Spec = internal::CommonStreamSpec<LibObjT>; | |
491 | using _ThisCommonStream = CommonStream<LibObjT>; | |
492 | ||
493 | using _Trace = | |
494 | typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>, | |
495 | CommonTrace<bt_trace>>::type; | |
496 | ||
497 | public: | |
498 | using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>; | |
499 | ||
500 | using Class = typename std::conditional<std::is_const<LibObjT>::value, | |
501 | CommonStreamClass<const bt_stream_class>, | |
502 | CommonStreamClass<bt_stream_class>>::type; | |
503 | ||
504 | using UserAttributes = | |
505 | typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type; | |
506 | ||
0d218157 | 507 | explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
508 | { |
509 | } | |
510 | ||
511 | template <typename OtherLibObjT> | |
0d218157 | 512 | CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream} |
74fc764d PP |
513 | { |
514 | } | |
515 | ||
516 | template <typename OtherLibObjT> | |
100fa861 | 517 | _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept |
74fc764d | 518 | { |
0d218157 | 519 | _ThisBorrowedObject::operator=(stream); |
74fc764d PP |
520 | return *this; |
521 | } | |
522 | ||
523 | Packet::Shared createPacket() | |
524 | { | |
525 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
526 | ||
341a67c4 | 527 | const auto libObjPtr = bt_packet_create(this->libObjPtr()); |
74fc764d PP |
528 | |
529 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 530 | return Packet::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
531 | } |
532 | ||
533 | CommonStreamClass<const bt_stream_class> cls() const noexcept; | |
534 | Class cls() noexcept; | |
535 | CommonTrace<const bt_trace> trace() const noexcept; | |
536 | _Trace trace() noexcept; | |
537 | ||
538 | std::uint64_t id() const noexcept | |
539 | { | |
341a67c4 | 540 | return bt_stream_get_id(this->libObjPtr()); |
74fc764d PP |
541 | } |
542 | ||
543 | void name(const char * const name) | |
544 | { | |
545 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
546 | ||
341a67c4 | 547 | const auto status = bt_stream_set_name(this->libObjPtr(), name); |
74fc764d PP |
548 | |
549 | if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 550 | throw MemoryError {}; |
74fc764d PP |
551 | } |
552 | } | |
553 | ||
554 | void name(const std::string& name) | |
555 | { | |
556 | this->name(name.data()); | |
557 | } | |
558 | ||
559 | nonstd::optional<bpstd::string_view> name() const noexcept | |
560 | { | |
341a67c4 | 561 | const auto name = bt_stream_get_name(this->libObjPtr()); |
74fc764d PP |
562 | |
563 | if (name) { | |
564 | return name; | |
565 | } | |
566 | ||
567 | return nonstd::nullopt; | |
568 | } | |
569 | ||
570 | template <typename LibValT> | |
100fa861 | 571 | void userAttributes(const CommonMapValue<LibValT> userAttrs) |
74fc764d PP |
572 | { |
573 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
574 | ||
341a67c4 | 575 | bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
576 | } |
577 | ||
578 | ConstMapValue userAttributes() const noexcept | |
579 | { | |
341a67c4 | 580 | return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
581 | } |
582 | ||
583 | UserAttributes userAttributes() noexcept | |
584 | { | |
341a67c4 | 585 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
586 | } |
587 | ||
588 | Shared shared() const noexcept | |
589 | { | |
c9c0b6e2 | 590 | return Shared::createWithRef(*this); |
74fc764d PP |
591 | } |
592 | }; | |
593 | ||
594 | using Stream = CommonStream<bt_stream>; | |
595 | using ConstStream = CommonStream<const bt_stream>; | |
596 | ||
4927bae7 PP |
597 | namespace internal { |
598 | ||
599 | struct StreamTypeDescr | |
600 | { | |
601 | using Const = ConstStream; | |
602 | using NonConst = Stream; | |
603 | }; | |
604 | ||
605 | template <> | |
606 | struct TypeDescr<Stream> : public StreamTypeDescr | |
607 | { | |
608 | }; | |
609 | ||
610 | template <> | |
611 | struct TypeDescr<ConstStream> : public StreamTypeDescr | |
612 | { | |
613 | }; | |
614 | ||
615 | } /* namespace internal */ | |
616 | ||
74fc764d PP |
617 | template <typename LibObjT> |
618 | ConstStream CommonEvent<LibObjT>::stream() const noexcept | |
619 | { | |
341a67c4 | 620 | return ConstStream {_ConstSpec::stream(this->libObjPtr())}; |
74fc764d PP |
621 | } |
622 | ||
623 | template <typename LibObjT> | |
624 | typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept | |
625 | { | |
341a67c4 | 626 | return _Stream {_Spec::stream(this->libObjPtr())}; |
74fc764d PP |
627 | } |
628 | ||
629 | template <typename LibObjT> | |
630 | ConstStream CommonPacket<LibObjT>::stream() const noexcept | |
631 | { | |
341a67c4 | 632 | return ConstStream {_ConstSpec::stream(this->libObjPtr())}; |
74fc764d PP |
633 | } |
634 | ||
635 | template <typename LibObjT> | |
636 | typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept | |
637 | { | |
341a67c4 | 638 | return _Stream {_Spec::stream(this->libObjPtr())}; |
74fc764d PP |
639 | } |
640 | ||
641 | namespace internal { | |
642 | ||
643 | struct TraceRefFuncs final | |
644 | { | |
645 | static void get(const bt_trace * const libObjPtr) | |
646 | { | |
647 | bt_trace_get_ref(libObjPtr); | |
648 | } | |
649 | ||
650 | static void put(const bt_trace * const libObjPtr) | |
651 | { | |
652 | bt_trace_put_ref(libObjPtr); | |
653 | } | |
654 | }; | |
655 | ||
656 | template <typename LibObjT> | |
657 | struct CommonTraceSpec; | |
658 | ||
b5f55e9f | 659 | /* Functions specific to mutable traces */ |
74fc764d PP |
660 | template <> |
661 | struct CommonTraceSpec<bt_trace> final | |
662 | { | |
663 | static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept | |
664 | { | |
665 | return bt_trace_borrow_class(libObjPtr); | |
666 | } | |
667 | ||
668 | static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept | |
669 | { | |
670 | return bt_trace_borrow_stream_by_index(libObjPtr, index); | |
671 | } | |
672 | ||
673 | static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept | |
674 | { | |
675 | return bt_trace_borrow_stream_by_id(libObjPtr, id); | |
676 | } | |
677 | ||
678 | static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept | |
679 | { | |
680 | return bt_trace_borrow_user_attributes(libObjPtr); | |
681 | } | |
682 | }; | |
683 | ||
b5f55e9f | 684 | /* Functions specific to constant traces */ |
74fc764d PP |
685 | template <> |
686 | struct CommonTraceSpec<const bt_trace> final | |
687 | { | |
688 | static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept | |
689 | { | |
690 | return bt_trace_borrow_class_const(libObjPtr); | |
691 | } | |
692 | ||
693 | static const bt_stream *streamByIndex(const bt_trace * const libObjPtr, | |
694 | const std::uint64_t index) noexcept | |
695 | { | |
696 | return bt_trace_borrow_stream_by_index_const(libObjPtr, index); | |
697 | } | |
698 | ||
699 | static const bt_stream *streamById(const bt_trace * const libObjPtr, | |
700 | const std::uint64_t id) noexcept | |
701 | { | |
702 | return bt_trace_borrow_stream_by_id_const(libObjPtr, id); | |
703 | } | |
704 | ||
705 | static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept | |
706 | { | |
707 | return bt_trace_borrow_user_attributes_const(libObjPtr); | |
708 | } | |
709 | }; | |
710 | ||
b5f55e9f | 711 | } /* namespace internal */ |
74fc764d PP |
712 | |
713 | template <typename LibObjT> | |
0d218157 | 714 | class CommonTrace final : public BorrowedObject<LibObjT> |
74fc764d | 715 | { |
341a67c4 | 716 | /* Allow instantiate() to call `trace.libObjPtr()` */ |
74fc764d PP |
717 | friend class CommonStreamClass<bt_stream_class>; |
718 | ||
719 | private: | |
0d218157 PP |
720 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
721 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
722 | using _ConstSpec = internal::CommonTraceSpec<const bt_trace>; |
723 | using _Spec = internal::CommonTraceSpec<LibObjT>; | |
724 | using _ThisCommonTrace = CommonTrace<LibObjT>; | |
725 | ||
726 | using _Stream = | |
727 | typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>, | |
728 | CommonStream<bt_stream>>::type; | |
729 | ||
730 | public: | |
731 | using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>; | |
732 | ||
733 | using Class = typename std::conditional<std::is_const<LibObjT>::value, | |
734 | CommonTraceClass<const bt_trace_class>, | |
735 | CommonTraceClass<bt_trace_class>>::type; | |
736 | ||
737 | using UserAttributes = | |
738 | typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type; | |
739 | ||
740 | struct ConstEnvironmentEntry | |
741 | { | |
742 | bpstd::string_view name; | |
743 | ConstValue value; | |
744 | }; | |
745 | ||
0d218157 | 746 | explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
747 | { |
748 | } | |
749 | ||
750 | template <typename OtherLibObjT> | |
0d218157 | 751 | CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace} |
74fc764d PP |
752 | { |
753 | } | |
754 | ||
755 | template <typename OtherLibObjT> | |
100fa861 | 756 | _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept |
74fc764d | 757 | { |
0d218157 | 758 | _ThisBorrowedObject::operator=(trace); |
74fc764d PP |
759 | return *this; |
760 | } | |
761 | ||
762 | CommonTraceClass<const bt_trace_class> cls() const noexcept; | |
763 | Class cls() noexcept; | |
764 | ||
765 | void name(const char * const name) | |
766 | { | |
767 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
768 | ||
341a67c4 | 769 | const auto status = bt_trace_set_name(this->libObjPtr(), name); |
74fc764d PP |
770 | |
771 | if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 772 | throw MemoryError {}; |
74fc764d PP |
773 | } |
774 | } | |
775 | ||
776 | void name(const std::string& name) | |
777 | { | |
778 | this->name(name.data()); | |
779 | } | |
780 | ||
781 | nonstd::optional<bpstd::string_view> name() const noexcept | |
782 | { | |
341a67c4 | 783 | const auto name = bt_trace_get_name(this->libObjPtr()); |
74fc764d PP |
784 | |
785 | if (name) { | |
786 | return name; | |
787 | } | |
788 | ||
789 | return nonstd::nullopt; | |
790 | } | |
791 | ||
81d250db | 792 | void uuid(const bt2_common::UuidView& uuid) noexcept |
74fc764d | 793 | { |
81d250db | 794 | bt_trace_set_uuid(this->libObjPtr(), uuid.begin()); |
74fc764d PP |
795 | } |
796 | ||
797 | nonstd::optional<bt2_common::UuidView> uuid() const noexcept | |
798 | { | |
341a67c4 | 799 | const auto uuid = bt_trace_get_uuid(this->libObjPtr()); |
74fc764d PP |
800 | |
801 | if (uuid) { | |
802 | return bt2_common::UuidView {uuid}; | |
803 | } | |
804 | ||
805 | return nonstd::nullopt; | |
806 | } | |
807 | ||
808 | std::uint64_t size() const noexcept | |
809 | { | |
341a67c4 | 810 | return bt_trace_get_stream_count(this->libObjPtr()); |
74fc764d PP |
811 | } |
812 | ||
813 | ConstStream operator[](const std::uint64_t index) const noexcept | |
814 | { | |
341a67c4 | 815 | return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
816 | } |
817 | ||
818 | _Stream operator[](const std::uint64_t index) noexcept | |
819 | { | |
341a67c4 | 820 | return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
821 | } |
822 | ||
823 | nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept | |
824 | { | |
341a67c4 | 825 | const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id); |
74fc764d PP |
826 | |
827 | if (libObjPtr) { | |
828 | return ConstStream {libObjPtr}; | |
829 | } | |
830 | ||
831 | return nonstd::nullopt; | |
832 | } | |
833 | ||
834 | nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept | |
835 | { | |
341a67c4 | 836 | const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id); |
74fc764d PP |
837 | |
838 | if (libObjPtr) { | |
839 | return _Stream {libObjPtr}; | |
840 | } | |
841 | ||
842 | return nonstd::nullopt; | |
843 | } | |
844 | ||
845 | void environmentEntry(const char * const name, const std::int64_t val) | |
846 | { | |
847 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
848 | ||
341a67c4 | 849 | const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val); |
74fc764d PP |
850 | |
851 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { | |
39278ebc | 852 | throw MemoryError {}; |
74fc764d PP |
853 | } |
854 | } | |
855 | ||
856 | void environmentEntry(const std::string& name, const std::int64_t val) | |
857 | { | |
858 | this->environmentEntry(name.data(), val); | |
859 | } | |
860 | ||
861 | void environmentEntry(const char * const name, const char * const val) | |
862 | { | |
863 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
864 | ||
341a67c4 | 865 | const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val); |
74fc764d PP |
866 | |
867 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { | |
39278ebc | 868 | throw MemoryError {}; |
74fc764d PP |
869 | } |
870 | } | |
871 | ||
872 | void environmentEntry(const std::string& name, const char * const val) | |
873 | { | |
874 | this->environmentEntry(name.data(), val); | |
875 | } | |
876 | ||
877 | void environmentEntry(const char * const name, const std::string& val) | |
878 | { | |
879 | this->environmentEntry(name, val.data()); | |
880 | } | |
881 | ||
882 | void environmentEntry(const std::string& name, const std::string& val) | |
883 | { | |
884 | this->environmentEntry(name.data(), val.data()); | |
885 | } | |
886 | ||
887 | std::uint64_t environmentSize() const noexcept | |
888 | { | |
341a67c4 | 889 | return bt_trace_get_environment_entry_count(this->libObjPtr()); |
74fc764d PP |
890 | } |
891 | ||
892 | ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept | |
893 | { | |
894 | const char *name; | |
895 | const bt_value *libObjPtr; | |
896 | ||
341a67c4 | 897 | bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name, |
74fc764d PP |
898 | &libObjPtr); |
899 | return ConstEnvironmentEntry {name, ConstValue {libObjPtr}}; | |
900 | } | |
901 | ||
902 | nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept | |
903 | { | |
904 | const auto libObjPtr = | |
341a67c4 | 905 | bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name); |
74fc764d PP |
906 | |
907 | if (libObjPtr) { | |
908 | return ConstValue {libObjPtr}; | |
909 | } | |
910 | ||
911 | return nonstd::nullopt; | |
912 | } | |
913 | ||
914 | nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept | |
915 | { | |
916 | return this->environmentEntry(name.data()); | |
917 | } | |
918 | ||
919 | template <typename LibValT> | |
100fa861 | 920 | void userAttributes(const CommonMapValue<LibValT> userAttrs) |
74fc764d PP |
921 | { |
922 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
923 | ||
341a67c4 | 924 | bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
925 | } |
926 | ||
927 | ConstMapValue userAttributes() const noexcept | |
928 | { | |
341a67c4 | 929 | return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
930 | } |
931 | ||
932 | UserAttributes userAttributes() noexcept | |
933 | { | |
341a67c4 | 934 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
935 | } |
936 | ||
937 | Shared shared() const noexcept | |
938 | { | |
c9c0b6e2 | 939 | return Shared::createWithRef(*this); |
74fc764d PP |
940 | } |
941 | }; | |
942 | ||
943 | using Trace = CommonTrace<bt_trace>; | |
944 | using ConstTrace = CommonTrace<const bt_trace>; | |
945 | ||
4927bae7 PP |
946 | namespace internal { |
947 | ||
948 | struct TraceTypeDescr | |
949 | { | |
950 | using Const = ConstTrace; | |
951 | using NonConst = Trace; | |
952 | }; | |
953 | ||
954 | template <> | |
955 | struct TypeDescr<Trace> : public TraceTypeDescr | |
956 | { | |
957 | }; | |
958 | ||
959 | template <> | |
960 | struct TypeDescr<ConstTrace> : public TraceTypeDescr | |
961 | { | |
962 | }; | |
963 | ||
964 | } /* namespace internal */ | |
965 | ||
74fc764d PP |
966 | template <typename LibObjT> |
967 | ConstTrace CommonStream<LibObjT>::trace() const noexcept | |
968 | { | |
341a67c4 | 969 | return ConstTrace {_ConstSpec::trace(this->libObjPtr())}; |
74fc764d PP |
970 | } |
971 | ||
972 | template <typename LibObjT> | |
973 | typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept | |
974 | { | |
341a67c4 | 975 | return _Trace {_Spec::trace(this->libObjPtr())}; |
74fc764d PP |
976 | } |
977 | ||
978 | namespace internal { | |
979 | ||
980 | struct EventClassRefFuncs final | |
981 | { | |
982 | static void get(const bt_event_class * const libObjPtr) | |
983 | { | |
984 | bt_event_class_get_ref(libObjPtr); | |
985 | } | |
986 | ||
987 | static void put(const bt_event_class * const libObjPtr) | |
988 | { | |
989 | bt_event_class_put_ref(libObjPtr); | |
990 | } | |
991 | }; | |
992 | ||
993 | template <typename LibObjT> | |
994 | struct CommonEventClassSpec; | |
995 | ||
b5f55e9f | 996 | /* Functions specific to mutable event classes */ |
74fc764d PP |
997 | template <> |
998 | struct CommonEventClassSpec<bt_event_class> final | |
999 | { | |
1000 | static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept | |
1001 | { | |
1002 | return bt_event_class_borrow_stream_class(libObjPtr); | |
1003 | } | |
1004 | ||
1005 | static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept | |
1006 | { | |
1007 | return bt_event_class_borrow_payload_field_class(libObjPtr); | |
1008 | } | |
1009 | ||
1010 | static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept | |
1011 | { | |
1012 | return bt_event_class_borrow_specific_context_field_class(libObjPtr); | |
1013 | } | |
1014 | ||
1015 | static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept | |
1016 | { | |
1017 | return bt_event_class_borrow_user_attributes(libObjPtr); | |
1018 | } | |
1019 | }; | |
1020 | ||
b5f55e9f | 1021 | /* Functions specific to constant event classes */ |
74fc764d PP |
1022 | template <> |
1023 | struct CommonEventClassSpec<const bt_event_class> final | |
1024 | { | |
1025 | static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept | |
1026 | { | |
1027 | return bt_event_class_borrow_stream_class_const(libObjPtr); | |
1028 | } | |
1029 | ||
1030 | static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept | |
1031 | { | |
1032 | return bt_event_class_borrow_payload_field_class_const(libObjPtr); | |
1033 | } | |
1034 | ||
1035 | static const bt_field_class * | |
1036 | specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept | |
1037 | { | |
1038 | return bt_event_class_borrow_specific_context_field_class_const(libObjPtr); | |
1039 | } | |
1040 | ||
1041 | static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept | |
1042 | { | |
1043 | return bt_event_class_borrow_user_attributes_const(libObjPtr); | |
1044 | } | |
1045 | }; | |
1046 | ||
b5f55e9f | 1047 | } /* namespace internal */ |
74fc764d PP |
1048 | |
1049 | template <typename LibObjT> | |
0d218157 | 1050 | class CommonEventClass final : public BorrowedObject<LibObjT> |
74fc764d PP |
1051 | { |
1052 | private: | |
0d218157 PP |
1053 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
1054 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
1055 | using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>; |
1056 | using _Spec = internal::CommonEventClassSpec<LibObjT>; | |
1057 | using _ThisCommonEventClass = CommonEventClass<LibObjT>; | |
1058 | ||
1059 | using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value, | |
1060 | CommonStreamClass<const bt_stream_class>, | |
1061 | CommonStreamClass<bt_stream_class>>::type; | |
1062 | ||
1063 | using _StructureFieldClass = | |
1064 | typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass, | |
1065 | StructureFieldClass>::type; | |
1066 | ||
1067 | public: | |
1068 | using Shared = | |
1069 | internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>; | |
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: | |
1451 | using Shared = | |
1452 | internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>; | |
1453 | ||
1454 | using UserAttributes = | |
1455 | typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type; | |
1456 | ||
0d218157 PP |
1457 | explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : |
1458 | _ThisBorrowedObject {libObjPtr} | |
74fc764d PP |
1459 | { |
1460 | } | |
1461 | ||
1462 | template <typename OtherLibObjT> | |
100fa861 | 1463 | CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept : |
0d218157 | 1464 | _ThisBorrowedObject {streamClass} |
74fc764d PP |
1465 | { |
1466 | } | |
1467 | ||
1468 | template <typename OtherLibObjT> | |
100fa861 | 1469 | _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept |
74fc764d | 1470 | { |
0d218157 | 1471 | _ThisBorrowedObject::operator=(streamClass); |
74fc764d PP |
1472 | return *this; |
1473 | } | |
1474 | ||
100fa861 | 1475 | Stream::Shared instantiate(const Trace trace) |
74fc764d PP |
1476 | { |
1477 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1478 | ||
341a67c4 | 1479 | const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr()); |
74fc764d PP |
1480 | |
1481 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1482 | return Stream::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1483 | } |
1484 | ||
100fa861 | 1485 | Stream::Shared instantiate(const Trace trace, const std::uint64_t id) |
74fc764d PP |
1486 | { |
1487 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1488 | ||
341a67c4 | 1489 | const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id); |
74fc764d PP |
1490 | |
1491 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1492 | return Stream::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1493 | } |
1494 | ||
1495 | EventClass::Shared createEventClass() | |
1496 | { | |
1497 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1498 | ||
341a67c4 | 1499 | const auto libObjPtr = bt_event_class_create(this->libObjPtr()); |
74fc764d PP |
1500 | |
1501 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1502 | return EventClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1503 | } |
1504 | ||
1505 | EventClass::Shared createEventClass(const std::uint64_t id) | |
1506 | { | |
1507 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1508 | ||
341a67c4 | 1509 | const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id); |
74fc764d PP |
1510 | |
1511 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1512 | return EventClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1513 | } |
1514 | ||
1515 | CommonTraceClass<const bt_trace_class> traceClass() const noexcept; | |
1516 | _TraceClass traceClass() noexcept; | |
1517 | ||
1518 | std::uint64_t id() const noexcept | |
1519 | { | |
341a67c4 | 1520 | return bt_stream_class_get_id(this->libObjPtr()); |
74fc764d PP |
1521 | } |
1522 | ||
1523 | void name(const char * const name) | |
1524 | { | |
1525 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1526 | ||
341a67c4 | 1527 | const auto status = bt_stream_class_set_name(this->libObjPtr(), name); |
74fc764d PP |
1528 | |
1529 | if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { | |
39278ebc | 1530 | throw MemoryError {}; |
74fc764d PP |
1531 | } |
1532 | } | |
1533 | ||
1534 | void name(const std::string& name) | |
1535 | { | |
1536 | this->name(name.data()); | |
1537 | } | |
1538 | ||
1539 | nonstd::optional<bpstd::string_view> name() const noexcept | |
1540 | { | |
341a67c4 | 1541 | const auto name = bt_stream_class_get_name(this->libObjPtr()); |
74fc764d PP |
1542 | |
1543 | if (name) { | |
1544 | return name; | |
1545 | } | |
1546 | ||
1547 | return nonstd::nullopt; | |
1548 | } | |
1549 | ||
1550 | void assignsAutomaticEventClassId(const bool val) noexcept | |
1551 | { | |
1552 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1553 | ||
341a67c4 | 1554 | bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(), |
74fc764d PP |
1555 | static_cast<bt_bool>(val)); |
1556 | } | |
1557 | ||
1558 | bool assignsAutomaticEventClassId() const noexcept | |
1559 | { | |
1560 | return static_cast<bool>( | |
341a67c4 | 1561 | bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr())); |
74fc764d PP |
1562 | } |
1563 | ||
1564 | void assignsAutomaticStreamId(const bool val) noexcept | |
1565 | { | |
1566 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1567 | ||
341a67c4 | 1568 | bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(), |
74fc764d PP |
1569 | static_cast<bt_bool>(val)); |
1570 | } | |
1571 | ||
1572 | bool assignsAutomaticStreamId() const noexcept | |
1573 | { | |
341a67c4 | 1574 | return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr())); |
74fc764d PP |
1575 | } |
1576 | ||
1577 | void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot, | |
1578 | const bool withEndDefaultClkSnapshot) noexcept | |
1579 | { | |
1580 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1581 | ||
341a67c4 | 1582 | bt_stream_class_set_supports_packets(this->libObjPtr(), |
74fc764d PP |
1583 | static_cast<bt_bool>(supportsPackets), |
1584 | static_cast<bt_bool>(withBeginningDefaultClkSnapshot), | |
1585 | static_cast<bt_bool>(withEndDefaultClkSnapshot)); | |
1586 | } | |
1587 | ||
1588 | bool supportsPackets() const noexcept | |
1589 | { | |
341a67c4 | 1590 | return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr())); |
74fc764d PP |
1591 | } |
1592 | ||
1593 | bool packetsHaveBeginningClockSnapshot() const noexcept | |
1594 | { | |
1595 | return static_cast<bool>( | |
341a67c4 | 1596 | bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr())); |
74fc764d PP |
1597 | } |
1598 | ||
1599 | bool packetsHaveEndClockSnapshot() const noexcept | |
1600 | { | |
1601 | return static_cast<bool>( | |
341a67c4 | 1602 | bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr())); |
74fc764d PP |
1603 | } |
1604 | ||
1605 | void supportsDiscardedEvents(const bool supportsDiscardedEvents, | |
1606 | const bool withDefaultClkSnapshots) noexcept | |
1607 | { | |
1608 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1609 | ||
1610 | bt_stream_class_set_supports_discarded_events( | |
7593e646 | 1611 | this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents), |
74fc764d PP |
1612 | static_cast<bt_bool>(withDefaultClkSnapshots)); |
1613 | } | |
1614 | ||
1615 | bool supportsDiscardedEvents() const noexcept | |
1616 | { | |
341a67c4 | 1617 | return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr())); |
74fc764d PP |
1618 | } |
1619 | ||
1620 | bool discardedEventsHaveDefaultClockSnapshots() const noexcept | |
1621 | { | |
1622 | return static_cast<bool>( | |
341a67c4 | 1623 | bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr())); |
74fc764d PP |
1624 | } |
1625 | ||
1626 | void supportsDiscardedPackets(const bool supportsDiscardedPackets, | |
1627 | const bool withDefaultClkSnapshots) noexcept | |
1628 | { | |
1629 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1630 | ||
1631 | bt_stream_class_set_supports_discarded_packets( | |
7593e646 | 1632 | this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets), |
74fc764d PP |
1633 | static_cast<bt_bool>(withDefaultClkSnapshots)); |
1634 | } | |
1635 | ||
1636 | bool supportsDiscardedPackets() const noexcept | |
1637 | { | |
341a67c4 | 1638 | return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr())); |
74fc764d PP |
1639 | } |
1640 | ||
1641 | bool discardedPacketsHaveDefaultClockSnapshots() const noexcept | |
1642 | { | |
1643 | return static_cast<bool>( | |
341a67c4 | 1644 | bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr())); |
74fc764d PP |
1645 | } |
1646 | ||
100fa861 | 1647 | void defaultClockClass(const ClockClass clkCls) |
74fc764d PP |
1648 | { |
1649 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1650 | ||
1651 | const auto status = | |
341a67c4 | 1652 | bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr()); |
74fc764d PP |
1653 | |
1654 | BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK); | |
1655 | } | |
1656 | ||
1657 | nonstd::optional<ConstClockClass> defaultClockClass() const noexcept | |
1658 | { | |
341a67c4 | 1659 | const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr()); |
74fc764d PP |
1660 | |
1661 | if (libObjPtr) { | |
1662 | return ConstClockClass {libObjPtr}; | |
1663 | } | |
1664 | ||
1665 | return nonstd::nullopt; | |
1666 | } | |
1667 | ||
1668 | nonstd::optional<_ClockClass> defaultClockClass() noexcept | |
1669 | { | |
341a67c4 | 1670 | const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr()); |
74fc764d PP |
1671 | |
1672 | if (libObjPtr) { | |
1673 | return _ClockClass {libObjPtr}; | |
1674 | } | |
1675 | ||
1676 | return nonstd::nullopt; | |
1677 | } | |
1678 | ||
1679 | std::uint64_t size() const noexcept | |
1680 | { | |
341a67c4 | 1681 | return bt_stream_class_get_event_class_count(this->libObjPtr()); |
74fc764d PP |
1682 | } |
1683 | ||
1684 | ConstEventClass operator[](const std::uint64_t index) const noexcept | |
1685 | { | |
341a67c4 | 1686 | return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
1687 | } |
1688 | ||
1689 | _EventClass operator[](const std::uint64_t index) noexcept | |
1690 | { | |
341a67c4 | 1691 | return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
1692 | } |
1693 | ||
1694 | nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept | |
1695 | { | |
341a67c4 | 1696 | const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id); |
74fc764d PP |
1697 | |
1698 | if (libObjPtr) { | |
1699 | return ConstEventClass {libObjPtr}; | |
1700 | } | |
1701 | ||
1702 | return nonstd::nullopt; | |
1703 | } | |
1704 | ||
1705 | nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept | |
1706 | { | |
341a67c4 | 1707 | const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id); |
74fc764d PP |
1708 | |
1709 | if (libObjPtr) { | |
1710 | return _EventClass {libObjPtr}; | |
1711 | } | |
1712 | ||
1713 | return nonstd::nullopt; | |
1714 | } | |
1715 | ||
100fa861 | 1716 | void packetContextFieldClass(const StructureFieldClass fc) |
74fc764d PP |
1717 | { |
1718 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1719 | ||
1720 | const auto status = | |
341a67c4 | 1721 | bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr()); |
74fc764d | 1722 | |
9ce695a6 | 1723 | if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
39278ebc | 1724 | throw MemoryError {}; |
74fc764d PP |
1725 | } |
1726 | } | |
1727 | ||
1728 | nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept | |
1729 | { | |
341a67c4 | 1730 | const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr()); |
74fc764d PP |
1731 | |
1732 | if (libObjPtr) { | |
1733 | return ConstStructureFieldClass {libObjPtr}; | |
1734 | } | |
1735 | ||
1736 | return nonstd::nullopt; | |
1737 | } | |
1738 | ||
1739 | nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept | |
1740 | { | |
341a67c4 | 1741 | const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr()); |
74fc764d PP |
1742 | |
1743 | if (libObjPtr) { | |
1744 | return _StructureFieldClass {libObjPtr}; | |
1745 | } | |
1746 | ||
1747 | return nonstd::nullopt; | |
1748 | } | |
1749 | ||
100fa861 | 1750 | void eventCommonContextFieldClass(const StructureFieldClass fc) |
74fc764d PP |
1751 | { |
1752 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1753 | ||
341a67c4 FD |
1754 | const auto status = |
1755 | bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr()); | |
74fc764d | 1756 | |
9ce695a6 | 1757 | if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
39278ebc | 1758 | throw MemoryError {}; |
74fc764d PP |
1759 | } |
1760 | } | |
1761 | ||
1762 | nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept | |
1763 | { | |
341a67c4 | 1764 | const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr()); |
74fc764d PP |
1765 | |
1766 | if (libObjPtr) { | |
1767 | return ConstStructureFieldClass {libObjPtr}; | |
1768 | } | |
1769 | ||
1770 | return nonstd::nullopt; | |
1771 | } | |
1772 | ||
1773 | nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept | |
1774 | { | |
341a67c4 | 1775 | const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr()); |
74fc764d PP |
1776 | |
1777 | if (libObjPtr) { | |
1778 | return _StructureFieldClass {libObjPtr}; | |
1779 | } | |
1780 | ||
1781 | return nonstd::nullopt; | |
1782 | } | |
1783 | ||
1784 | template <typename LibValT> | |
100fa861 | 1785 | void userAttributes(const CommonMapValue<LibValT> userAttrs) |
74fc764d PP |
1786 | { |
1787 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1788 | ||
341a67c4 | 1789 | bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
1790 | } |
1791 | ||
1792 | ConstMapValue userAttributes() const noexcept | |
1793 | { | |
341a67c4 | 1794 | return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
1795 | } |
1796 | ||
1797 | UserAttributes userAttributes() noexcept | |
1798 | { | |
341a67c4 | 1799 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
1800 | } |
1801 | ||
1802 | Shared shared() const noexcept | |
1803 | { | |
c9c0b6e2 | 1804 | return Shared::createWithRef(*this); |
74fc764d PP |
1805 | } |
1806 | }; | |
1807 | ||
1808 | using StreamClass = CommonStreamClass<bt_stream_class>; | |
1809 | using ConstStreamClass = CommonStreamClass<const bt_stream_class>; | |
1810 | ||
4927bae7 PP |
1811 | namespace internal { |
1812 | ||
1813 | struct StreamClassTypeDescr | |
1814 | { | |
1815 | using Const = ConstStreamClass; | |
1816 | using NonConst = StreamClass; | |
1817 | }; | |
1818 | ||
1819 | template <> | |
1820 | struct TypeDescr<StreamClass> : public StreamClassTypeDescr | |
1821 | { | |
1822 | }; | |
1823 | ||
1824 | template <> | |
1825 | struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr | |
1826 | { | |
1827 | }; | |
1828 | ||
1829 | } /* namespace internal */ | |
1830 | ||
74fc764d PP |
1831 | template <typename LibObjT> |
1832 | ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept | |
1833 | { | |
341a67c4 | 1834 | return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())}; |
74fc764d PP |
1835 | } |
1836 | ||
1837 | template <typename LibObjT> | |
1838 | typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept | |
1839 | { | |
341a67c4 | 1840 | return _StreamClass {_Spec::streamClass(this->libObjPtr())}; |
74fc764d PP |
1841 | } |
1842 | ||
1843 | template <typename LibObjT> | |
1844 | ConstStreamClass CommonStream<LibObjT>::cls() const noexcept | |
1845 | { | |
341a67c4 | 1846 | return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())}; |
74fc764d PP |
1847 | } |
1848 | ||
1849 | template <typename LibObjT> | |
1850 | typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept | |
1851 | { | |
341a67c4 | 1852 | return Class {_Spec::cls(this->libObjPtr())}; |
74fc764d PP |
1853 | } |
1854 | ||
1855 | namespace internal { | |
1856 | ||
1857 | struct TraceClassRefFuncs final | |
1858 | { | |
1859 | static void get(const bt_trace_class * const libObjPtr) | |
1860 | { | |
1861 | bt_trace_class_get_ref(libObjPtr); | |
1862 | } | |
1863 | ||
1864 | static void put(const bt_trace_class * const libObjPtr) | |
1865 | { | |
1866 | bt_trace_class_put_ref(libObjPtr); | |
1867 | } | |
1868 | }; | |
1869 | ||
1870 | template <typename LibObjT> | |
1871 | struct CommonTraceClassSpec; | |
1872 | ||
b5f55e9f | 1873 | /* Functions specific to mutable stream classes */ |
74fc764d PP |
1874 | template <> |
1875 | struct CommonTraceClassSpec<bt_trace_class> final | |
1876 | { | |
1877 | static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr, | |
1878 | const std::uint64_t index) noexcept | |
1879 | { | |
1880 | return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index); | |
1881 | } | |
1882 | ||
1883 | static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr, | |
1884 | const std::uint64_t id) noexcept | |
1885 | { | |
1886 | return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id); | |
1887 | } | |
1888 | ||
1889 | static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept | |
1890 | { | |
1891 | return bt_trace_class_borrow_user_attributes(libObjPtr); | |
1892 | } | |
1893 | }; | |
1894 | ||
b5f55e9f | 1895 | /* Functions specific to constant stream classes */ |
74fc764d PP |
1896 | template <> |
1897 | struct CommonTraceClassSpec<const bt_trace_class> final | |
1898 | { | |
1899 | static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr, | |
1900 | const std::uint64_t index) noexcept | |
1901 | { | |
1902 | return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index); | |
1903 | } | |
1904 | ||
1905 | static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr, | |
1906 | const std::uint64_t id) noexcept | |
1907 | { | |
1908 | return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id); | |
1909 | } | |
1910 | ||
1911 | static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept | |
1912 | { | |
1913 | return bt_trace_class_borrow_user_attributes_const(libObjPtr); | |
1914 | } | |
1915 | }; | |
1916 | ||
b5f55e9f | 1917 | } /* namespace internal */ |
74fc764d PP |
1918 | |
1919 | template <typename LibObjT> | |
0d218157 | 1920 | class CommonTraceClass final : public BorrowedObject<LibObjT> |
74fc764d PP |
1921 | { |
1922 | private: | |
0d218157 PP |
1923 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
1924 | using typename BorrowedObject<LibObjT>::_LibObjPtr; | |
74fc764d PP |
1925 | using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>; |
1926 | using _Spec = internal::CommonTraceClassSpec<LibObjT>; | |
1927 | using _ThisCommonTraceClass = CommonTraceClass<LibObjT>; | |
1928 | ||
1929 | using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value, | |
1930 | CommonStreamClass<const bt_stream_class>, | |
1931 | CommonStreamClass<bt_stream_class>>::type; | |
1932 | ||
1933 | public: | |
1934 | using Shared = | |
1935 | internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>; | |
1936 | ||
1937 | using UserAttributes = | |
1938 | typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type; | |
1939 | ||
0d218157 | 1940 | explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
74fc764d PP |
1941 | { |
1942 | } | |
1943 | ||
1944 | template <typename OtherLibObjT> | |
100fa861 | 1945 | CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept : |
0d218157 | 1946 | _ThisBorrowedObject {traceClass} |
74fc764d PP |
1947 | { |
1948 | } | |
1949 | ||
1950 | template <typename OtherLibObjT> | |
100fa861 | 1951 | _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept |
74fc764d | 1952 | { |
0d218157 | 1953 | _ThisBorrowedObject::operator=(traceClass); |
74fc764d PP |
1954 | return *this; |
1955 | } | |
1956 | ||
64052204 | 1957 | Trace::Shared instantiate() |
74fc764d PP |
1958 | { |
1959 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1960 | ||
341a67c4 | 1961 | const auto libObjPtr = bt_trace_create(this->libObjPtr()); |
74fc764d PP |
1962 | |
1963 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1964 | return Trace::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1965 | } |
1966 | ||
1967 | StreamClass::Shared createStreamClass() | |
1968 | { | |
1969 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1970 | ||
341a67c4 | 1971 | const auto libObjPtr = bt_stream_class_create(this->libObjPtr()); |
74fc764d PP |
1972 | |
1973 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1974 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1975 | } |
1976 | ||
1977 | StreamClass::Shared createStreamClass(const std::uint64_t id) | |
1978 | { | |
1979 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1980 | ||
341a67c4 | 1981 | const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id); |
74fc764d PP |
1982 | |
1983 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1984 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1985 | } |
1986 | ||
1987 | FieldClass::Shared createBoolFieldClass() | |
1988 | { | |
1989 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
1990 | ||
341a67c4 | 1991 | const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr()); |
74fc764d PP |
1992 | |
1993 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 1994 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
1995 | } |
1996 | ||
1997 | BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) | |
1998 | { | |
1999 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2000 | ||
341a67c4 | 2001 | const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length); |
74fc764d PP |
2002 | |
2003 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2004 | return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2005 | } |
2006 | ||
2007 | IntegerFieldClass::Shared createUnsignedIntegerFieldClass() | |
2008 | { | |
2009 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2010 | ||
341a67c4 | 2011 | const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr()); |
74fc764d PP |
2012 | |
2013 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2014 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2015 | } |
2016 | ||
2017 | IntegerFieldClass::Shared createSignedIntegerFieldClass() | |
2018 | { | |
2019 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2020 | ||
341a67c4 | 2021 | const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr()); |
74fc764d PP |
2022 | |
2023 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2024 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2025 | } |
2026 | ||
2027 | UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() | |
2028 | { | |
2029 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2030 | ||
341a67c4 | 2031 | const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr()); |
74fc764d PP |
2032 | |
2033 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2034 | return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2035 | } |
2036 | ||
2037 | SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() | |
2038 | { | |
2039 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2040 | ||
341a67c4 | 2041 | const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr()); |
74fc764d PP |
2042 | |
2043 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2044 | return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2045 | } |
2046 | ||
2047 | FieldClass::Shared createSinglePrecisionRealFieldClass() | |
2048 | { | |
2049 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2050 | ||
341a67c4 | 2051 | const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr()); |
74fc764d PP |
2052 | |
2053 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2054 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2055 | } |
2056 | ||
2057 | FieldClass::Shared createDoublePrecisionRealFieldClass() | |
2058 | { | |
2059 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2060 | ||
341a67c4 | 2061 | const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr()); |
74fc764d PP |
2062 | |
2063 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2064 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2065 | } |
2066 | ||
2067 | FieldClass::Shared createStringFieldClass() | |
2068 | { | |
2069 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2070 | ||
341a67c4 | 2071 | const auto libObjPtr = bt_field_class_string_create(this->libObjPtr()); |
74fc764d PP |
2072 | |
2073 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2074 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2075 | } |
2076 | ||
100fa861 | 2077 | StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass, |
74fc764d PP |
2078 | const std::uint64_t length) |
2079 | { | |
2080 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2081 | ||
2082 | const auto libObjPtr = bt_field_class_array_static_create( | |
341a67c4 | 2083 | this->libObjPtr(), elementFieldClass.libObjPtr(), length); |
74fc764d PP |
2084 | |
2085 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2086 | return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2087 | } |
2088 | ||
100fa861 | 2089 | ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) |
74fc764d PP |
2090 | { |
2091 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2092 | ||
2093 | const auto libObjPtr = bt_field_class_array_dynamic_create( | |
341a67c4 | 2094 | this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr); |
74fc764d PP |
2095 | |
2096 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2097 | return ArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2098 | } |
2099 | ||
2100 | DynamicArrayWithLengthFieldClass::Shared | |
100fa861 PP |
2101 | createDynamicArrayFieldClass(const FieldClass elementFieldClass, |
2102 | const IntegerFieldClass lengthFieldClass) | |
74fc764d PP |
2103 | { |
2104 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2105 | ||
2106 | const auto libObjPtr = bt_field_class_array_dynamic_create( | |
341a67c4 | 2107 | this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr()); |
74fc764d PP |
2108 | |
2109 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2110 | return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2111 | } |
2112 | ||
e1acf2c7 | 2113 | StructureFieldClass::Shared createStructureFieldClass() |
74fc764d PP |
2114 | { |
2115 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2116 | ||
341a67c4 | 2117 | const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr()); |
74fc764d PP |
2118 | |
2119 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2120 | return StructureFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2121 | } |
2122 | ||
100fa861 | 2123 | OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) |
74fc764d PP |
2124 | { |
2125 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2126 | ||
2127 | const auto libObjPtr = bt_field_class_option_without_selector_create( | |
341a67c4 | 2128 | this->libObjPtr(), optionalFieldClass.libObjPtr()); |
74fc764d PP |
2129 | |
2130 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2131 | return OptionFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2132 | } |
2133 | ||
2134 | OptionWithBoolSelectorFieldClass::Shared | |
100fa861 PP |
2135 | createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass, |
2136 | const FieldClass selectorFieldClass) | |
74fc764d PP |
2137 | { |
2138 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2139 | ||
2140 | const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create( | |
341a67c4 | 2141 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr()); |
74fc764d PP |
2142 | |
2143 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2144 | return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2145 | } |
2146 | ||
2147 | OptionWithUnsignedIntegerSelectorFieldClass::Shared | |
100fa861 PP |
2148 | createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass, |
2149 | const IntegerFieldClass selectorFieldClass, | |
2150 | const ConstUnsignedIntegerRangeSet ranges) | |
74fc764d PP |
2151 | { |
2152 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2153 | ||
2154 | const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create( | |
341a67c4 FD |
2155 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
2156 | ranges.libObjPtr()); | |
74fc764d PP |
2157 | |
2158 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2159 | return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2160 | } |
2161 | ||
2162 | OptionWithSignedIntegerSelectorFieldClass::Shared | |
100fa861 PP |
2163 | createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass, |
2164 | const IntegerFieldClass selectorFieldClass, | |
2165 | const ConstSignedIntegerRangeSet ranges) | |
74fc764d PP |
2166 | { |
2167 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2168 | ||
2169 | const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create( | |
341a67c4 FD |
2170 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
2171 | ranges.libObjPtr()); | |
74fc764d PP |
2172 | |
2173 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2174 | return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2175 | } |
2176 | ||
2177 | VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() | |
2178 | { | |
2179 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2180 | ||
341a67c4 | 2181 | const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr); |
74fc764d PP |
2182 | |
2183 | internal::validateCreatedObjPtr(libObjPtr); | |
c9c0b6e2 | 2184 | return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2185 | } |
2186 | ||
2187 | VariantWithUnsignedIntegerSelectorFieldClass::Shared | |
100fa861 | 2188 | createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) |
74fc764d | 2189 | { |
69d96f80 FD |
2190 | return this->_createVariantWithIntegerSelectorFieldClass< |
2191 | VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass); | |
74fc764d PP |
2192 | } |
2193 | ||
2194 | VariantWithSignedIntegerSelectorFieldClass::Shared | |
100fa861 | 2195 | createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) |
74fc764d | 2196 | { |
69d96f80 FD |
2197 | return this->_createVariantWithIntegerSelectorFieldClass< |
2198 | VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass); | |
74fc764d PP |
2199 | } |
2200 | ||
2201 | void assignsAutomaticStreamClassId(const bool val) noexcept | |
2202 | { | |
2203 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2204 | ||
341a67c4 | 2205 | bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(), |
74fc764d PP |
2206 | static_cast<bt_bool>(val)); |
2207 | } | |
2208 | ||
2209 | bool assignsAutomaticStreamClassId() const noexcept | |
2210 | { | |
2211 | return static_cast<bool>( | |
341a67c4 | 2212 | bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr())); |
74fc764d PP |
2213 | } |
2214 | ||
2215 | std::uint64_t size() const noexcept | |
2216 | { | |
341a67c4 | 2217 | return bt_trace_class_get_stream_class_count(this->libObjPtr()); |
74fc764d PP |
2218 | } |
2219 | ||
2220 | ConstStreamClass operator[](const std::uint64_t index) const noexcept | |
2221 | { | |
341a67c4 | 2222 | return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
2223 | } |
2224 | ||
2225 | _StreamClass operator[](const std::uint64_t index) noexcept | |
2226 | { | |
341a67c4 | 2227 | return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)}; |
74fc764d PP |
2228 | } |
2229 | ||
2230 | nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept | |
2231 | { | |
341a67c4 | 2232 | const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id); |
74fc764d PP |
2233 | |
2234 | if (libObjPtr) { | |
2235 | return ConstStreamClass {libObjPtr}; | |
2236 | } | |
2237 | ||
2238 | return nonstd::nullopt; | |
2239 | } | |
2240 | ||
2241 | nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept | |
2242 | { | |
341a67c4 | 2243 | const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id); |
74fc764d PP |
2244 | |
2245 | if (libObjPtr) { | |
2246 | return _StreamClass {libObjPtr}; | |
2247 | } | |
2248 | ||
2249 | return nonstd::nullopt; | |
2250 | } | |
2251 | ||
2252 | template <typename LibValT> | |
100fa861 | 2253 | void userAttributes(const CommonMapValue<LibValT> userAttrs) |
74fc764d PP |
2254 | { |
2255 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2256 | ||
341a67c4 | 2257 | bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
74fc764d PP |
2258 | } |
2259 | ||
2260 | ConstMapValue userAttributes() const noexcept | |
2261 | { | |
341a67c4 | 2262 | return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
2263 | } |
2264 | ||
2265 | UserAttributes userAttributes() noexcept | |
2266 | { | |
341a67c4 | 2267 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
74fc764d PP |
2268 | } |
2269 | ||
2270 | Shared shared() const noexcept | |
2271 | { | |
c9c0b6e2 | 2272 | return Shared::createWithRef(*this); |
74fc764d PP |
2273 | } |
2274 | ||
2275 | private: | |
69d96f80 FD |
2276 | template <typename ObjT> |
2277 | typename ObjT::Shared | |
100fa861 | 2278 | _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) |
74fc764d PP |
2279 | { |
2280 | static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`."); | |
2281 | ||
2282 | const auto libObjPtr = | |
341a67c4 | 2283 | bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr()); |
74fc764d PP |
2284 | |
2285 | internal::validateCreatedObjPtr(libObjPtr); | |
69d96f80 | 2286 | return ObjT::Shared::createWithoutRef(libObjPtr); |
74fc764d PP |
2287 | } |
2288 | }; | |
2289 | ||
2290 | using TraceClass = CommonTraceClass<bt_trace_class>; | |
2291 | using ConstTraceClass = CommonTraceClass<const bt_trace_class>; | |
2292 | ||
4927bae7 PP |
2293 | namespace internal { |
2294 | ||
2295 | struct TraceClassTypeDescr | |
2296 | { | |
2297 | using Const = ConstTraceClass; | |
2298 | using NonConst = TraceClass; | |
2299 | }; | |
2300 | ||
2301 | template <> | |
2302 | struct TypeDescr<TraceClass> : public TraceClassTypeDescr | |
2303 | { | |
2304 | }; | |
2305 | ||
2306 | template <> | |
2307 | struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr | |
2308 | { | |
2309 | }; | |
2310 | ||
2311 | } /* namespace internal */ | |
2312 | ||
74fc764d PP |
2313 | template <typename LibObjT> |
2314 | ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept | |
2315 | { | |
341a67c4 | 2316 | return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())}; |
74fc764d PP |
2317 | } |
2318 | ||
2319 | template <typename LibObjT> | |
2320 | typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept | |
2321 | { | |
341a67c4 | 2322 | return _TraceClass {_Spec::traceClass(this->libObjPtr())}; |
74fc764d PP |
2323 | } |
2324 | ||
2325 | template <typename LibObjT> | |
2326 | ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept | |
2327 | { | |
341a67c4 | 2328 | return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())}; |
74fc764d PP |
2329 | } |
2330 | ||
2331 | template <typename LibObjT> | |
2332 | typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept | |
2333 | { | |
341a67c4 | 2334 | return Class {_Spec::cls(this->libObjPtr())}; |
74fc764d PP |
2335 | } |
2336 | ||
b5f55e9f | 2337 | } /* namespace bt2 */ |
74fc764d | 2338 | |
b5f55e9f | 2339 | #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */ |