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