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