.gitignore: add some missing files
[babeltrace.git] / src / cpp-common / bt2 / component-class.hpp
CommitLineData
cb036945
SM
1/*
2 * Copyright (c) 2024 EfficiOS, Inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP
8#define BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP
9
10#include <babeltrace2/babeltrace.h>
11
12#include "cpp-common/bt2c/c-string-view.hpp"
13
14#include "borrowed-object.hpp"
ee137c4e 15#include "component-class-dev.hpp"
cb036945
SM
16#include "shared-object.hpp"
17
18namespace bt2 {
19namespace internal {
20
21struct ComponentClassRefFuncs final
22{
23 static void get(const bt_component_class * const libObjPtr) noexcept
24 {
25 bt_component_class_get_ref(libObjPtr);
26 }
27
28 static void put(const bt_component_class * const libObjPtr) noexcept
29 {
30 bt_component_class_put_ref(libObjPtr);
31 }
32};
33
34} /* namespace internal */
35
33f20928
SM
36enum class ComponentClassType
37{
38 Source = BT_COMPONENT_CLASS_TYPE_SOURCE,
39 Filter = BT_COMPONENT_CLASS_TYPE_FILTER,
40 Sink = BT_COMPONENT_CLASS_TYPE_SINK,
41};
42
cb036945
SM
43template <typename LibObjT>
44class CommonSourceComponentClass;
45
46template <typename LibObjT>
47class CommonFilterComponentClass;
48
49template <typename LibObjT>
50class CommonSinkComponentClass;
51
52template <typename LibObjT>
53class CommonComponentClass : public BorrowedObject<LibObjT>
54{
55private:
56 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
57
58public:
59 using typename _ThisBorrowedObject::LibObjPtr;
60 using Shared = SharedObject<CommonComponentClass, LibObjT, internal::ComponentClassRefFuncs>;
61
62 explicit CommonComponentClass(const LibObjPtr libObjPtr) noexcept :
63 _ThisBorrowedObject {libObjPtr}
64 {
65 }
66
67 template <typename OtherLibObjT>
68 CommonComponentClass(const CommonComponentClass<OtherLibObjT> compCls) noexcept :
69 _ThisBorrowedObject {compCls}
70 {
71 }
72
73 template <typename OtherLibObjT>
74 CommonComponentClass operator=(const CommonComponentClass<OtherLibObjT> compCls) noexcept
75 {
76 _ThisBorrowedObject::operator=(compCls);
77 return *this;
78 }
79
80 /* Not `explicit` to make them behave like copy constructors */
81 CommonComponentClass(
82 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
83 CommonComponentClass(
84 const CommonSourceComponentClass<bt_component_class_source> other) noexcept;
85 CommonComponentClass(
86 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
87 CommonComponentClass(
88 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
89 CommonComponentClass(
90 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
91 CommonComponentClass(const CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
92
93 CommonComponentClass
94 operator=(CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
95 CommonComponentClass
96 operator=(CommonSourceComponentClass<bt_component_class_source> other) noexcept;
97 CommonComponentClass
98 operator=(CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
99 CommonComponentClass
100 operator=(CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
101 CommonComponentClass
102 operator=(CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
103 CommonComponentClass
104 operator=(CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
105
106 bool isSource() const noexcept
107 {
108 return static_cast<bool>(bt_component_class_is_source(this->libObjPtr()));
109 }
110
111 bool isFilter() const noexcept
112 {
113 return static_cast<bool>(bt_component_class_is_filter(this->libObjPtr()));
114 }
115
116 bool isSink() const noexcept
117 {
118 return static_cast<bool>(bt_component_class_is_sink(this->libObjPtr()));
119 }
120
121 bt2c::CStringView name() const noexcept
122 {
123 return bt_component_class_get_name(this->libObjPtr());
124 }
125
126 bt2c::CStringView description() const noexcept
127 {
128 return bt_component_class_get_description(this->libObjPtr());
129 }
130
131 bt2c::CStringView help() const noexcept
132 {
133 return bt_component_class_get_help(this->libObjPtr());
134 }
135};
136
137using ComponentClass = CommonComponentClass<bt_component_class>;
138using ConstComponentClass = CommonComponentClass<const bt_component_class>;
139
140namespace internal {
141
142struct SourceComponentClassRefFuncs final
143{
144 static void get(const bt_component_class_source * const libObjPtr) noexcept
145 {
146 bt_component_class_source_get_ref(libObjPtr);
147 }
148
149 static void put(const bt_component_class_source * const libObjPtr) noexcept
150 {
151 bt_component_class_source_put_ref(libObjPtr);
152 }
153};
154
155} /* namespace internal */
156
157template <typename LibObjT>
158class CommonSourceComponentClass final : public BorrowedObject<LibObjT>
159{
160private:
161 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
162
163public:
164 using typename _ThisBorrowedObject::LibObjPtr;
165 using Shared =
166 SharedObject<CommonSourceComponentClass, LibObjT, internal::SourceComponentClassRefFuncs>;
167
168 CommonSourceComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
169 {
170 }
171
172 template <typename OtherLibObjT>
173 CommonSourceComponentClass(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept :
174 _ThisBorrowedObject {compCls}
175 {
176 }
177
178 template <typename OtherLibObjT>
179 CommonSourceComponentClass
180 operator=(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept
181 {
182 _ThisBorrowedObject::operator=(compCls);
183 return *this;
184 }
185
ee137c4e
PP
186 template <typename UserComponentT>
187 static CommonSourceComponentClass<LibObjT>::Shared create()
188 {
189 return CommonSourceComponentClass::Shared::createWithoutRef(
190 internal::createSourceCompCls<UserComponentT>());
191 }
192
cb036945
SM
193 bt2c::CStringView name() const noexcept
194 {
195 return this->_constComponentClass().name();
196 }
197
198 bt2c::CStringView description() const noexcept
199 {
200 return this->_constComponentClass().description();
201 }
202
203 bt2c::CStringView help() const noexcept
204 {
205 return this->_constComponentClass().help();
206 }
207
2c8e2496
SM
208 Shared shared() const noexcept
209 {
210 return Shared::createWithRef(*this);
211 }
212
cb036945
SM
213private:
214 ConstComponentClass _constComponentClass() const noexcept
215 {
216 return ConstComponentClass {
217 bt_component_class_source_as_component_class_const(this->libObjPtr())};
218 }
219};
220
221template <typename LibObjT>
222CommonComponentClass<LibObjT>::CommonComponentClass(
223 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept :
224 _ThisBorrowedObject {bt_component_class_source_as_component_class_const(other.libObjPtr())}
225{
226}
227
228template <typename LibObjT>
229CommonComponentClass<LibObjT>::CommonComponentClass(
230 const CommonSourceComponentClass<bt_component_class_source> other) noexcept :
231 _ThisBorrowedObject {bt_component_class_source_as_component_class(other.libObjPtr())}
232{
233}
234
235template <typename LibObjT>
236CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
237 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept
238{
239 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
240 bt_component_class_source_as_component_class_const(other.libObjPtr())});
241 return *this;
242}
243
244template <typename LibObjT>
245CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
246 const CommonSourceComponentClass<bt_component_class_source> other) noexcept
247{
248 BorrowedObject<LibObjT>::operator=(
249 ComponentClass {bt_component_class_source_as_component_class(other.libObjPtr())});
250 return *this;
251}
252
253using SourceComponentClass = CommonSourceComponentClass<bt_component_class_source>;
254using ConstSourceComponentClass = CommonSourceComponentClass<const bt_component_class_source>;
255
256namespace internal {
257
258struct FilterComponentClassRefFuncs final
259{
260 static void get(const bt_component_class_filter * const libObjPtr) noexcept
261 {
262 bt_component_class_filter_get_ref(libObjPtr);
263 }
264
265 static void put(const bt_component_class_filter * const libObjPtr) noexcept
266 {
267 bt_component_class_filter_put_ref(libObjPtr);
268 }
269};
270
271} /* namespace internal */
272
273template <typename LibObjT>
274class CommonFilterComponentClass final : public BorrowedObject<LibObjT>
275{
276private:
277 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
278
279public:
280 using typename _ThisBorrowedObject::LibObjPtr;
281 using Shared =
282 SharedObject<CommonFilterComponentClass, LibObjT, internal::FilterComponentClassRefFuncs>;
283
284 CommonFilterComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
285 {
286 }
287
288 template <typename OtherLibObjT>
289 CommonFilterComponentClass(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept :
290 _ThisBorrowedObject {compCls}
291 {
292 }
293
294 template <typename OtherLibObjT>
295 CommonFilterComponentClass
296 operator=(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept
297 {
298 _ThisBorrowedObject::operator=(compCls);
299 return *this;
300 }
301
ee137c4e
PP
302 template <typename UserComponentT>
303 static CommonFilterComponentClass<LibObjT>::Shared create()
304 {
305 return CommonFilterComponentClass::Shared::createWithoutRef(
306 internal::createFilterCompCls<UserComponentT>());
307 }
308
cb036945
SM
309 bt2c::CStringView name() const noexcept
310 {
311 return this->_constComponentClass().name();
312 }
313
314 bt2c::CStringView description() const noexcept
315 {
316 return this->_constComponentClass().description();
317 }
318
319 bt2c::CStringView help() const noexcept
320 {
321 return this->_constComponentClass().help();
322 }
323
2c8e2496
SM
324 Shared shared() const noexcept
325 {
326 return Shared::createWithRef(*this);
327 }
328
cb036945
SM
329private:
330 ConstComponentClass _constComponentClass() const noexcept
331 {
332 return ConstComponentClass {
333 bt_component_class_filter_as_component_class_const(this->libObjPtr())};
334 }
335};
336
337template <typename LibObjT>
338CommonComponentClass<LibObjT>::CommonComponentClass(
339 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept :
340 _ThisBorrowedObject {bt_component_class_filter_as_component_class_const(other.libObjPtr())}
341{
342}
343
344template <typename LibObjT>
345CommonComponentClass<LibObjT>::CommonComponentClass(
346 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept :
347 _ThisBorrowedObject {bt_component_class_filter_as_component_class(other.libObjPtr())}
348{
349}
350
351template <typename LibObjT>
352CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
353 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept
354{
355 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
356 bt_component_class_filter_as_component_class_const(other.libObjPtr())});
357 return *this;
358}
359
360template <typename LibObjT>
361CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
362 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept
363{
364 BorrowedObject<LibObjT>::operator=(
365 ComponentClass {bt_component_class_filter_as_component_class(other.libObjPtr())});
366 return *this;
367}
368
369using FilterComponentClass = CommonFilterComponentClass<bt_component_class_filter>;
370using ConstFilterComponentClass = CommonFilterComponentClass<const bt_component_class_filter>;
371
372namespace internal {
373
374struct SinkComponentClassRefFuncs final
375{
376 static void get(const bt_component_class_sink * const libObjPtr) noexcept
377 {
378 bt_component_class_sink_get_ref(libObjPtr);
379 }
380
381 static void put(const bt_component_class_sink * const libObjPtr) noexcept
382 {
383 bt_component_class_sink_put_ref(libObjPtr);
384 }
385};
386
387} /* namespace internal */
388
389template <typename LibObjT>
390class CommonSinkComponentClass final : public BorrowedObject<LibObjT>
391{
392private:
393 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
394
395public:
396 using typename _ThisBorrowedObject::LibObjPtr;
397 using Shared =
398 SharedObject<CommonSinkComponentClass, LibObjT, internal::SinkComponentClassRefFuncs>;
399
400 CommonSinkComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
401 {
402 }
403
404 template <typename OtherLibObjT>
405 CommonSinkComponentClass(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept :
406 _ThisBorrowedObject {compCls}
407 {
408 }
409
410 template <typename OtherLibObjT>
411 CommonSinkComponentClass
412 operator=(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept
413 {
414 _ThisBorrowedObject::operator=(compCls);
415 return *this;
416 }
417
ee137c4e
PP
418 template <typename UserComponentT>
419 static CommonSinkComponentClass<LibObjT>::Shared create()
420 {
421 return CommonSinkComponentClass::Shared::createWithoutRef(
422 internal::createSinkCompCls<UserComponentT>());
423 }
424
cb036945
SM
425 bt2c::CStringView name() const noexcept
426 {
427 return this->_constComponentClass().name();
428 }
429
430 bt2c::CStringView description() const noexcept
431 {
432 return this->_constComponentClass().description();
433 }
434
435 bt2c::CStringView help() const noexcept
436 {
437 return this->_constComponentClass().help();
438 }
439
2c8e2496
SM
440 Shared shared() const noexcept
441 {
442 return Shared::createWithRef(*this);
443 }
444
cb036945
SM
445private:
446 ConstComponentClass _constComponentClass() const noexcept
447 {
448 return ConstComponentClass {
449 bt_component_class_sink_as_component_class_const(this->libObjPtr())};
450 }
451};
452
453template <typename LibObjT>
454CommonComponentClass<LibObjT>::CommonComponentClass(
455 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept :
456 _ThisBorrowedObject {bt_component_class_sink_as_component_class_const(other.libObjPtr())}
457{
458}
459
460template <typename LibObjT>
461CommonComponentClass<LibObjT>::CommonComponentClass(
462 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept :
463 _ThisBorrowedObject {bt_component_class_sink_as_component_class(other.libObjPtr())}
464{
465}
466
467template <typename LibObjT>
468CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
469 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept
470{
471 BorrowedObject<LibObjT>::operator=(
472 ConstComponentClass {bt_component_class_sink_as_component_class_const(other.libObjPtr())});
473 return *this;
474}
475
476template <typename LibObjT>
477CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
478 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept
479{
480 BorrowedObject<LibObjT>::operator=(
481 ComponentClass {bt_component_class_sink_as_component_class(other.libObjPtr())});
482 return *this;
483}
484
485using SinkComponentClass = CommonSinkComponentClass<bt_component_class_sink>;
486using ConstSinkComponentClass = CommonSinkComponentClass<const bt_component_class_sink>;
487
488} /* namespace bt2 */
489
490#endif /* BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP */
This page took 0.048354 seconds and 4 git commands to generate.