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 "component-class-dev.hpp"
16 #include "shared-object.hpp"
21 struct ComponentClassRefFuncs final
23 static void get(const bt_component_class * const libObjPtr) noexcept
25 bt_component_class_get_ref(libObjPtr);
28 static void put(const bt_component_class * const libObjPtr) noexcept
30 bt_component_class_put_ref(libObjPtr);
34 } /* namespace internal */
36 template <typename LibObjT>
37 class CommonSourceComponentClass;
39 template <typename LibObjT>
40 class CommonFilterComponentClass;
42 template <typename LibObjT>
43 class CommonSinkComponentClass;
45 template <typename LibObjT>
46 class CommonComponentClass : public BorrowedObject<LibObjT>
49 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
52 using typename _ThisBorrowedObject::LibObjPtr;
53 using Shared = SharedObject<CommonComponentClass, LibObjT, internal::ComponentClassRefFuncs>;
55 explicit CommonComponentClass(const LibObjPtr libObjPtr) noexcept :
56 _ThisBorrowedObject {libObjPtr}
60 template <typename OtherLibObjT>
61 CommonComponentClass(const CommonComponentClass<OtherLibObjT> compCls) noexcept :
62 _ThisBorrowedObject {compCls}
66 template <typename OtherLibObjT>
67 CommonComponentClass operator=(const CommonComponentClass<OtherLibObjT> compCls) noexcept
69 _ThisBorrowedObject::operator=(compCls);
73 /* Not `explicit` to make them behave like copy constructors */
75 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
77 const CommonSourceComponentClass<bt_component_class_source> other) noexcept;
79 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
81 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
83 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
84 CommonComponentClass(const CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
87 operator=(CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
89 operator=(CommonSourceComponentClass<bt_component_class_source> other) noexcept;
91 operator=(CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
93 operator=(CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
95 operator=(CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
97 operator=(CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
99 bool isSource() const noexcept
101 return static_cast<bool>(bt_component_class_is_source(this->libObjPtr()));
104 bool isFilter() const noexcept
106 return static_cast<bool>(bt_component_class_is_filter(this->libObjPtr()));
109 bool isSink() const noexcept
111 return static_cast<bool>(bt_component_class_is_sink(this->libObjPtr()));
114 bt2c::CStringView name() const noexcept
116 return bt_component_class_get_name(this->libObjPtr());
119 bt2c::CStringView description() const noexcept
121 return bt_component_class_get_description(this->libObjPtr());
124 bt2c::CStringView help() const noexcept
126 return bt_component_class_get_help(this->libObjPtr());
130 using ComponentClass = CommonComponentClass<bt_component_class>;
131 using ConstComponentClass = CommonComponentClass<const bt_component_class>;
135 struct SourceComponentClassRefFuncs final
137 static void get(const bt_component_class_source * const libObjPtr) noexcept
139 bt_component_class_source_get_ref(libObjPtr);
142 static void put(const bt_component_class_source * const libObjPtr) noexcept
144 bt_component_class_source_put_ref(libObjPtr);
148 } /* namespace internal */
150 template <typename LibObjT>
151 class CommonSourceComponentClass final : public BorrowedObject<LibObjT>
154 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
157 using typename _ThisBorrowedObject::LibObjPtr;
159 SharedObject<CommonSourceComponentClass, LibObjT, internal::SourceComponentClassRefFuncs>;
161 CommonSourceComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
165 template <typename OtherLibObjT>
166 CommonSourceComponentClass(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept :
167 _ThisBorrowedObject {compCls}
171 template <typename OtherLibObjT>
172 CommonSourceComponentClass
173 operator=(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept
175 _ThisBorrowedObject::operator=(compCls);
179 template <typename UserComponentT>
180 static CommonSourceComponentClass<LibObjT>::Shared create()
182 return CommonSourceComponentClass::Shared::createWithoutRef(
183 internal::createSourceCompCls<UserComponentT>());
186 bt2c::CStringView name() const noexcept
188 return this->_constComponentClass().name();
191 bt2c::CStringView description() const noexcept
193 return this->_constComponentClass().description();
196 bt2c::CStringView help() const noexcept
198 return this->_constComponentClass().help();
202 ConstComponentClass _constComponentClass() const noexcept
204 return ConstComponentClass {
205 bt_component_class_source_as_component_class_const(this->libObjPtr())};
209 template <typename LibObjT>
210 CommonComponentClass<LibObjT>::CommonComponentClass(
211 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept :
212 _ThisBorrowedObject {bt_component_class_source_as_component_class_const(other.libObjPtr())}
216 template <typename LibObjT>
217 CommonComponentClass<LibObjT>::CommonComponentClass(
218 const CommonSourceComponentClass<bt_component_class_source> other) noexcept :
219 _ThisBorrowedObject {bt_component_class_source_as_component_class(other.libObjPtr())}
223 template <typename LibObjT>
224 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
225 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept
227 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
228 bt_component_class_source_as_component_class_const(other.libObjPtr())});
232 template <typename LibObjT>
233 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
234 const CommonSourceComponentClass<bt_component_class_source> other) noexcept
236 BorrowedObject<LibObjT>::operator=(
237 ComponentClass {bt_component_class_source_as_component_class(other.libObjPtr())});
241 using SourceComponentClass = CommonSourceComponentClass<bt_component_class_source>;
242 using ConstSourceComponentClass = CommonSourceComponentClass<const bt_component_class_source>;
246 struct FilterComponentClassRefFuncs final
248 static void get(const bt_component_class_filter * const libObjPtr) noexcept
250 bt_component_class_filter_get_ref(libObjPtr);
253 static void put(const bt_component_class_filter * const libObjPtr) noexcept
255 bt_component_class_filter_put_ref(libObjPtr);
259 } /* namespace internal */
261 template <typename LibObjT>
262 class CommonFilterComponentClass final : public BorrowedObject<LibObjT>
265 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
268 using typename _ThisBorrowedObject::LibObjPtr;
270 SharedObject<CommonFilterComponentClass, LibObjT, internal::FilterComponentClassRefFuncs>;
272 CommonFilterComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
276 template <typename OtherLibObjT>
277 CommonFilterComponentClass(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept :
278 _ThisBorrowedObject {compCls}
282 template <typename OtherLibObjT>
283 CommonFilterComponentClass
284 operator=(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept
286 _ThisBorrowedObject::operator=(compCls);
290 template <typename UserComponentT>
291 static CommonFilterComponentClass<LibObjT>::Shared create()
293 return CommonFilterComponentClass::Shared::createWithoutRef(
294 internal::createFilterCompCls<UserComponentT>());
297 bt2c::CStringView name() const noexcept
299 return this->_constComponentClass().name();
302 bt2c::CStringView description() const noexcept
304 return this->_constComponentClass().description();
307 bt2c::CStringView help() const noexcept
309 return this->_constComponentClass().help();
313 ConstComponentClass _constComponentClass() const noexcept
315 return ConstComponentClass {
316 bt_component_class_filter_as_component_class_const(this->libObjPtr())};
320 template <typename LibObjT>
321 CommonComponentClass<LibObjT>::CommonComponentClass(
322 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept :
323 _ThisBorrowedObject {bt_component_class_filter_as_component_class_const(other.libObjPtr())}
327 template <typename LibObjT>
328 CommonComponentClass<LibObjT>::CommonComponentClass(
329 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept :
330 _ThisBorrowedObject {bt_component_class_filter_as_component_class(other.libObjPtr())}
334 template <typename LibObjT>
335 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
336 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept
338 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
339 bt_component_class_filter_as_component_class_const(other.libObjPtr())});
343 template <typename LibObjT>
344 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
345 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept
347 BorrowedObject<LibObjT>::operator=(
348 ComponentClass {bt_component_class_filter_as_component_class(other.libObjPtr())});
352 using FilterComponentClass = CommonFilterComponentClass<bt_component_class_filter>;
353 using ConstFilterComponentClass = CommonFilterComponentClass<const bt_component_class_filter>;
357 struct SinkComponentClassRefFuncs final
359 static void get(const bt_component_class_sink * const libObjPtr) noexcept
361 bt_component_class_sink_get_ref(libObjPtr);
364 static void put(const bt_component_class_sink * const libObjPtr) noexcept
366 bt_component_class_sink_put_ref(libObjPtr);
370 } /* namespace internal */
372 template <typename LibObjT>
373 class CommonSinkComponentClass final : public BorrowedObject<LibObjT>
376 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
379 using typename _ThisBorrowedObject::LibObjPtr;
381 SharedObject<CommonSinkComponentClass, LibObjT, internal::SinkComponentClassRefFuncs>;
383 CommonSinkComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
387 template <typename OtherLibObjT>
388 CommonSinkComponentClass(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept :
389 _ThisBorrowedObject {compCls}
393 template <typename OtherLibObjT>
394 CommonSinkComponentClass
395 operator=(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept
397 _ThisBorrowedObject::operator=(compCls);
401 template <typename UserComponentT>
402 static CommonSinkComponentClass<LibObjT>::Shared create()
404 return CommonSinkComponentClass::Shared::createWithoutRef(
405 internal::createSinkCompCls<UserComponentT>());
408 bt2c::CStringView name() const noexcept
410 return this->_constComponentClass().name();
413 bt2c::CStringView description() const noexcept
415 return this->_constComponentClass().description();
418 bt2c::CStringView help() const noexcept
420 return this->_constComponentClass().help();
424 ConstComponentClass _constComponentClass() const noexcept
426 return ConstComponentClass {
427 bt_component_class_sink_as_component_class_const(this->libObjPtr())};
431 template <typename LibObjT>
432 CommonComponentClass<LibObjT>::CommonComponentClass(
433 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept :
434 _ThisBorrowedObject {bt_component_class_sink_as_component_class_const(other.libObjPtr())}
438 template <typename LibObjT>
439 CommonComponentClass<LibObjT>::CommonComponentClass(
440 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept :
441 _ThisBorrowedObject {bt_component_class_sink_as_component_class(other.libObjPtr())}
445 template <typename LibObjT>
446 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
447 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept
449 BorrowedObject<LibObjT>::operator=(
450 ConstComponentClass {bt_component_class_sink_as_component_class_const(other.libObjPtr())});
454 template <typename LibObjT>
455 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
456 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept
458 BorrowedObject<LibObjT>::operator=(
459 ComponentClass {bt_component_class_sink_as_component_class(other.libObjPtr())});
463 using SinkComponentClass = CommonSinkComponentClass<bt_component_class_sink>;
464 using ConstSinkComponentClass = CommonSinkComponentClass<const bt_component_class_sink>;
466 } /* namespace bt2 */
468 #endif /* BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP */