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