2 * Copyright (c) 2024 EfficiOS, Inc.
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP
10 #include <babeltrace2/babeltrace.h>
12 #include "cpp-common/bt2c/c-string-view.hpp"
14 #include "borrowed-object.hpp"
15 #include "shared-object.hpp"
20 struct ComponentClassRefFuncs final
22 static void get(const bt_component_class * const libObjPtr) noexcept
24 bt_component_class_get_ref(libObjPtr);
27 static void put(const bt_component_class * const libObjPtr) noexcept
29 bt_component_class_put_ref(libObjPtr);
33 } /* namespace internal */
35 template <typename LibObjT>
36 class CommonSourceComponentClass;
38 template <typename LibObjT>
39 class CommonFilterComponentClass;
41 template <typename LibObjT>
42 class CommonSinkComponentClass;
44 template <typename LibObjT>
45 class CommonComponentClass : public BorrowedObject<LibObjT>
48 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
51 using typename _ThisBorrowedObject::LibObjPtr;
52 using Shared = SharedObject<CommonComponentClass, LibObjT, internal::ComponentClassRefFuncs>;
54 explicit CommonComponentClass(const LibObjPtr libObjPtr) noexcept :
55 _ThisBorrowedObject {libObjPtr}
59 template <typename OtherLibObjT>
60 CommonComponentClass(const CommonComponentClass<OtherLibObjT> compCls) noexcept :
61 _ThisBorrowedObject {compCls}
65 template <typename OtherLibObjT>
66 CommonComponentClass operator=(const CommonComponentClass<OtherLibObjT> compCls) noexcept
68 _ThisBorrowedObject::operator=(compCls);
72 /* Not `explicit` to make them behave like copy constructors */
74 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
76 const CommonSourceComponentClass<bt_component_class_source> other) noexcept;
78 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
80 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
82 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
83 CommonComponentClass(const CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
86 operator=(CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
88 operator=(CommonSourceComponentClass<bt_component_class_source> other) noexcept;
90 operator=(CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
92 operator=(CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
94 operator=(CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
96 operator=(CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
98 bool isSource() const noexcept
100 return static_cast<bool>(bt_component_class_is_source(this->libObjPtr()));
103 bool isFilter() const noexcept
105 return static_cast<bool>(bt_component_class_is_filter(this->libObjPtr()));
108 bool isSink() const noexcept
110 return static_cast<bool>(bt_component_class_is_sink(this->libObjPtr()));
113 bt2c::CStringView name() const noexcept
115 return bt_component_class_get_name(this->libObjPtr());
118 bt2c::CStringView description() const noexcept
120 return bt_component_class_get_description(this->libObjPtr());
123 bt2c::CStringView help() const noexcept
125 return bt_component_class_get_help(this->libObjPtr());
129 using ComponentClass = CommonComponentClass<bt_component_class>;
130 using ConstComponentClass = CommonComponentClass<const bt_component_class>;
134 struct SourceComponentClassRefFuncs final
136 static void get(const bt_component_class_source * const libObjPtr) noexcept
138 bt_component_class_source_get_ref(libObjPtr);
141 static void put(const bt_component_class_source * const libObjPtr) noexcept
143 bt_component_class_source_put_ref(libObjPtr);
147 } /* namespace internal */
149 template <typename LibObjT>
150 class CommonSourceComponentClass final : public BorrowedObject<LibObjT>
153 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
156 using typename _ThisBorrowedObject::LibObjPtr;
158 SharedObject<CommonSourceComponentClass, LibObjT, internal::SourceComponentClassRefFuncs>;
160 CommonSourceComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
164 template <typename OtherLibObjT>
165 CommonSourceComponentClass(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept :
166 _ThisBorrowedObject {compCls}
170 template <typename OtherLibObjT>
171 CommonSourceComponentClass
172 operator=(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept
174 _ThisBorrowedObject::operator=(compCls);
178 bt2c::CStringView name() const noexcept
180 return this->_constComponentClass().name();
183 bt2c::CStringView description() const noexcept
185 return this->_constComponentClass().description();
188 bt2c::CStringView help() const noexcept
190 return this->_constComponentClass().help();
194 ConstComponentClass _constComponentClass() const noexcept
196 return ConstComponentClass {
197 bt_component_class_source_as_component_class_const(this->libObjPtr())};
201 template <typename LibObjT>
202 CommonComponentClass<LibObjT>::CommonComponentClass(
203 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept :
204 _ThisBorrowedObject {bt_component_class_source_as_component_class_const(other.libObjPtr())}
208 template <typename LibObjT>
209 CommonComponentClass<LibObjT>::CommonComponentClass(
210 const CommonSourceComponentClass<bt_component_class_source> other) noexcept :
211 _ThisBorrowedObject {bt_component_class_source_as_component_class(other.libObjPtr())}
215 template <typename LibObjT>
216 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
217 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept
219 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
220 bt_component_class_source_as_component_class_const(other.libObjPtr())});
224 template <typename LibObjT>
225 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
226 const CommonSourceComponentClass<bt_component_class_source> other) noexcept
228 BorrowedObject<LibObjT>::operator=(
229 ComponentClass {bt_component_class_source_as_component_class(other.libObjPtr())});
233 using SourceComponentClass = CommonSourceComponentClass<bt_component_class_source>;
234 using ConstSourceComponentClass = CommonSourceComponentClass<const bt_component_class_source>;
238 struct FilterComponentClassRefFuncs final
240 static void get(const bt_component_class_filter * const libObjPtr) noexcept
242 bt_component_class_filter_get_ref(libObjPtr);
245 static void put(const bt_component_class_filter * const libObjPtr) noexcept
247 bt_component_class_filter_put_ref(libObjPtr);
251 } /* namespace internal */
253 template <typename LibObjT>
254 class CommonFilterComponentClass final : public BorrowedObject<LibObjT>
257 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
260 using typename _ThisBorrowedObject::LibObjPtr;
262 SharedObject<CommonFilterComponentClass, LibObjT, internal::FilterComponentClassRefFuncs>;
264 CommonFilterComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
268 template <typename OtherLibObjT>
269 CommonFilterComponentClass(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept :
270 _ThisBorrowedObject {compCls}
274 template <typename OtherLibObjT>
275 CommonFilterComponentClass
276 operator=(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept
278 _ThisBorrowedObject::operator=(compCls);
282 bt2c::CStringView name() const noexcept
284 return this->_constComponentClass().name();
287 bt2c::CStringView description() const noexcept
289 return this->_constComponentClass().description();
292 bt2c::CStringView help() const noexcept
294 return this->_constComponentClass().help();
298 ConstComponentClass _constComponentClass() const noexcept
300 return ConstComponentClass {
301 bt_component_class_filter_as_component_class_const(this->libObjPtr())};
305 template <typename LibObjT>
306 CommonComponentClass<LibObjT>::CommonComponentClass(
307 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept :
308 _ThisBorrowedObject {bt_component_class_filter_as_component_class_const(other.libObjPtr())}
312 template <typename LibObjT>
313 CommonComponentClass<LibObjT>::CommonComponentClass(
314 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept :
315 _ThisBorrowedObject {bt_component_class_filter_as_component_class(other.libObjPtr())}
319 template <typename LibObjT>
320 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
321 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept
323 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
324 bt_component_class_filter_as_component_class_const(other.libObjPtr())});
328 template <typename LibObjT>
329 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
330 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept
332 BorrowedObject<LibObjT>::operator=(
333 ComponentClass {bt_component_class_filter_as_component_class(other.libObjPtr())});
337 using FilterComponentClass = CommonFilterComponentClass<bt_component_class_filter>;
338 using ConstFilterComponentClass = CommonFilterComponentClass<const bt_component_class_filter>;
342 struct SinkComponentClassRefFuncs final
344 static void get(const bt_component_class_sink * const libObjPtr) noexcept
346 bt_component_class_sink_get_ref(libObjPtr);
349 static void put(const bt_component_class_sink * const libObjPtr) noexcept
351 bt_component_class_sink_put_ref(libObjPtr);
355 } /* namespace internal */
357 template <typename LibObjT>
358 class CommonSinkComponentClass final : public BorrowedObject<LibObjT>
361 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
364 using typename _ThisBorrowedObject::LibObjPtr;
366 SharedObject<CommonSinkComponentClass, LibObjT, internal::SinkComponentClassRefFuncs>;
368 CommonSinkComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
372 template <typename OtherLibObjT>
373 CommonSinkComponentClass(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept :
374 _ThisBorrowedObject {compCls}
378 template <typename OtherLibObjT>
379 CommonSinkComponentClass
380 operator=(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept
382 _ThisBorrowedObject::operator=(compCls);
386 bt2c::CStringView name() const noexcept
388 return this->_constComponentClass().name();
391 bt2c::CStringView description() const noexcept
393 return this->_constComponentClass().description();
396 bt2c::CStringView help() const noexcept
398 return this->_constComponentClass().help();
402 ConstComponentClass _constComponentClass() const noexcept
404 return ConstComponentClass {
405 bt_component_class_sink_as_component_class_const(this->libObjPtr())};
409 template <typename LibObjT>
410 CommonComponentClass<LibObjT>::CommonComponentClass(
411 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept :
412 _ThisBorrowedObject {bt_component_class_sink_as_component_class_const(other.libObjPtr())}
416 template <typename LibObjT>
417 CommonComponentClass<LibObjT>::CommonComponentClass(
418 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept :
419 _ThisBorrowedObject {bt_component_class_sink_as_component_class(other.libObjPtr())}
423 template <typename LibObjT>
424 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
425 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept
427 BorrowedObject<LibObjT>::operator=(
428 ConstComponentClass {bt_component_class_sink_as_component_class_const(other.libObjPtr())});
432 template <typename LibObjT>
433 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
434 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept
436 BorrowedObject<LibObjT>::operator=(
437 ComponentClass {bt_component_class_sink_as_component_class(other.libObjPtr())});
441 using SinkComponentClass = CommonSinkComponentClass<bt_component_class_sink>;
442 using ConstSinkComponentClass = CommonSinkComponentClass<const bt_component_class_sink>;
444 } /* namespace bt2 */
446 #endif /* BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP */