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>;
57 Source = BT_COMPONENT_CLASS_TYPE_SOURCE,
58 Filter = BT_COMPONENT_CLASS_TYPE_FILTER,
59 Sink = BT_COMPONENT_CLASS_TYPE_SINK,
62 explicit CommonComponentClass(const LibObjPtr libObjPtr) noexcept :
63 _ThisBorrowedObject {libObjPtr}
67 template <typename OtherLibObjT>
68 CommonComponentClass(const CommonComponentClass<OtherLibObjT> compCls) noexcept :
69 _ThisBorrowedObject {compCls}
73 template <typename OtherLibObjT>
74 CommonComponentClass operator=(const CommonComponentClass<OtherLibObjT> compCls) noexcept
76 _ThisBorrowedObject::operator=(compCls);
80 /* Not `explicit` to make them behave like copy constructors */
82 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
84 const CommonSourceComponentClass<bt_component_class_source> other) noexcept;
86 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
88 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
90 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
91 CommonComponentClass(const CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
94 operator=(CommonSourceComponentClass<const bt_component_class_source> other) noexcept;
96 operator=(CommonSourceComponentClass<bt_component_class_source> other) noexcept;
98 operator=(CommonFilterComponentClass<const bt_component_class_filter> other) noexcept;
100 operator=(CommonFilterComponentClass<bt_component_class_filter> other) noexcept;
102 operator=(CommonSinkComponentClass<const bt_component_class_sink> other) noexcept;
104 operator=(CommonSinkComponentClass<bt_component_class_sink> other) noexcept;
106 bool isSource() const noexcept
108 return static_cast<bool>(bt_component_class_is_source(this->libObjPtr()));
111 bool isFilter() const noexcept
113 return static_cast<bool>(bt_component_class_is_filter(this->libObjPtr()));
116 bool isSink() const noexcept
118 return static_cast<bool>(bt_component_class_is_sink(this->libObjPtr()));
121 bt2c::CStringView name() const noexcept
123 return bt_component_class_get_name(this->libObjPtr());
126 bt2c::CStringView description() const noexcept
128 return bt_component_class_get_description(this->libObjPtr());
131 bt2c::CStringView help() const noexcept
133 return bt_component_class_get_help(this->libObjPtr());
137 using ComponentClass = CommonComponentClass<bt_component_class>;
138 using ConstComponentClass = CommonComponentClass<const bt_component_class>;
142 struct SourceComponentClassRefFuncs final
144 static void get(const bt_component_class_source * const libObjPtr) noexcept
146 bt_component_class_source_get_ref(libObjPtr);
149 static void put(const bt_component_class_source * const libObjPtr) noexcept
151 bt_component_class_source_put_ref(libObjPtr);
155 } /* namespace internal */
157 template <typename LibObjT>
158 class CommonSourceComponentClass final : public BorrowedObject<LibObjT>
161 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
164 using typename _ThisBorrowedObject::LibObjPtr;
166 SharedObject<CommonSourceComponentClass, LibObjT, internal::SourceComponentClassRefFuncs>;
168 CommonSourceComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
172 template <typename OtherLibObjT>
173 CommonSourceComponentClass(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept :
174 _ThisBorrowedObject {compCls}
178 template <typename OtherLibObjT>
179 CommonSourceComponentClass
180 operator=(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept
182 _ThisBorrowedObject::operator=(compCls);
186 template <typename UserComponentT>
187 static CommonSourceComponentClass<LibObjT>::Shared create()
189 return CommonSourceComponentClass::Shared::createWithoutRef(
190 internal::createSourceCompCls<UserComponentT>());
193 bt2c::CStringView name() const noexcept
195 return this->_constComponentClass().name();
198 bt2c::CStringView description() const noexcept
200 return this->_constComponentClass().description();
203 bt2c::CStringView help() const noexcept
205 return this->_constComponentClass().help();
209 ConstComponentClass _constComponentClass() const noexcept
211 return ConstComponentClass {
212 bt_component_class_source_as_component_class_const(this->libObjPtr())};
216 template <typename LibObjT>
217 CommonComponentClass<LibObjT>::CommonComponentClass(
218 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept :
219 _ThisBorrowedObject {bt_component_class_source_as_component_class_const(other.libObjPtr())}
223 template <typename LibObjT>
224 CommonComponentClass<LibObjT>::CommonComponentClass(
225 const CommonSourceComponentClass<bt_component_class_source> other) noexcept :
226 _ThisBorrowedObject {bt_component_class_source_as_component_class(other.libObjPtr())}
230 template <typename LibObjT>
231 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
232 const CommonSourceComponentClass<const bt_component_class_source> other) noexcept
234 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
235 bt_component_class_source_as_component_class_const(other.libObjPtr())});
239 template <typename LibObjT>
240 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
241 const CommonSourceComponentClass<bt_component_class_source> other) noexcept
243 BorrowedObject<LibObjT>::operator=(
244 ComponentClass {bt_component_class_source_as_component_class(other.libObjPtr())});
248 using SourceComponentClass = CommonSourceComponentClass<bt_component_class_source>;
249 using ConstSourceComponentClass = CommonSourceComponentClass<const bt_component_class_source>;
253 struct FilterComponentClassRefFuncs final
255 static void get(const bt_component_class_filter * const libObjPtr) noexcept
257 bt_component_class_filter_get_ref(libObjPtr);
260 static void put(const bt_component_class_filter * const libObjPtr) noexcept
262 bt_component_class_filter_put_ref(libObjPtr);
266 } /* namespace internal */
268 template <typename LibObjT>
269 class CommonFilterComponentClass final : public BorrowedObject<LibObjT>
272 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
275 using typename _ThisBorrowedObject::LibObjPtr;
277 SharedObject<CommonFilterComponentClass, LibObjT, internal::FilterComponentClassRefFuncs>;
279 CommonFilterComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
283 template <typename OtherLibObjT>
284 CommonFilterComponentClass(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept :
285 _ThisBorrowedObject {compCls}
289 template <typename OtherLibObjT>
290 CommonFilterComponentClass
291 operator=(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept
293 _ThisBorrowedObject::operator=(compCls);
297 template <typename UserComponentT>
298 static CommonFilterComponentClass<LibObjT>::Shared create()
300 return CommonFilterComponentClass::Shared::createWithoutRef(
301 internal::createFilterCompCls<UserComponentT>());
304 bt2c::CStringView name() const noexcept
306 return this->_constComponentClass().name();
309 bt2c::CStringView description() const noexcept
311 return this->_constComponentClass().description();
314 bt2c::CStringView help() const noexcept
316 return this->_constComponentClass().help();
320 ConstComponentClass _constComponentClass() const noexcept
322 return ConstComponentClass {
323 bt_component_class_filter_as_component_class_const(this->libObjPtr())};
327 template <typename LibObjT>
328 CommonComponentClass<LibObjT>::CommonComponentClass(
329 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept :
330 _ThisBorrowedObject {bt_component_class_filter_as_component_class_const(other.libObjPtr())}
334 template <typename LibObjT>
335 CommonComponentClass<LibObjT>::CommonComponentClass(
336 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept :
337 _ThisBorrowedObject {bt_component_class_filter_as_component_class(other.libObjPtr())}
341 template <typename LibObjT>
342 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
343 const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept
345 BorrowedObject<LibObjT>::operator=(ConstComponentClass {
346 bt_component_class_filter_as_component_class_const(other.libObjPtr())});
350 template <typename LibObjT>
351 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
352 const CommonFilterComponentClass<bt_component_class_filter> other) noexcept
354 BorrowedObject<LibObjT>::operator=(
355 ComponentClass {bt_component_class_filter_as_component_class(other.libObjPtr())});
359 using FilterComponentClass = CommonFilterComponentClass<bt_component_class_filter>;
360 using ConstFilterComponentClass = CommonFilterComponentClass<const bt_component_class_filter>;
364 struct SinkComponentClassRefFuncs final
366 static void get(const bt_component_class_sink * const libObjPtr) noexcept
368 bt_component_class_sink_get_ref(libObjPtr);
371 static void put(const bt_component_class_sink * const libObjPtr) noexcept
373 bt_component_class_sink_put_ref(libObjPtr);
377 } /* namespace internal */
379 template <typename LibObjT>
380 class CommonSinkComponentClass final : public BorrowedObject<LibObjT>
383 using _ThisBorrowedObject = BorrowedObject<LibObjT>;
386 using typename _ThisBorrowedObject::LibObjPtr;
388 SharedObject<CommonSinkComponentClass, LibObjT, internal::SinkComponentClassRefFuncs>;
390 CommonSinkComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
394 template <typename OtherLibObjT>
395 CommonSinkComponentClass(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept :
396 _ThisBorrowedObject {compCls}
400 template <typename OtherLibObjT>
401 CommonSinkComponentClass
402 operator=(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept
404 _ThisBorrowedObject::operator=(compCls);
408 template <typename UserComponentT>
409 static CommonSinkComponentClass<LibObjT>::Shared create()
411 return CommonSinkComponentClass::Shared::createWithoutRef(
412 internal::createSinkCompCls<UserComponentT>());
415 bt2c::CStringView name() const noexcept
417 return this->_constComponentClass().name();
420 bt2c::CStringView description() const noexcept
422 return this->_constComponentClass().description();
425 bt2c::CStringView help() const noexcept
427 return this->_constComponentClass().help();
431 ConstComponentClass _constComponentClass() const noexcept
433 return ConstComponentClass {
434 bt_component_class_sink_as_component_class_const(this->libObjPtr())};
438 template <typename LibObjT>
439 CommonComponentClass<LibObjT>::CommonComponentClass(
440 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept :
441 _ThisBorrowedObject {bt_component_class_sink_as_component_class_const(other.libObjPtr())}
445 template <typename LibObjT>
446 CommonComponentClass<LibObjT>::CommonComponentClass(
447 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept :
448 _ThisBorrowedObject {bt_component_class_sink_as_component_class(other.libObjPtr())}
452 template <typename LibObjT>
453 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
454 const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept
456 BorrowedObject<LibObjT>::operator=(
457 ConstComponentClass {bt_component_class_sink_as_component_class_const(other.libObjPtr())});
461 template <typename LibObjT>
462 CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=(
463 const CommonSinkComponentClass<bt_component_class_sink> other) noexcept
465 BorrowedObject<LibObjT>::operator=(
466 ComponentClass {bt_component_class_sink_as_component_class(other.libObjPtr())});
470 using SinkComponentClass = CommonSinkComponentClass<bt_component_class_sink>;
471 using ConstSinkComponentClass = CommonSinkComponentClass<const bt_component_class_sink>;
473 } /* namespace bt2 */
475 #endif /* BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP */