Commit | Line | Data |
---|---|---|
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 | ||
18 | namespace bt2 { | |
19 | namespace internal { | |
20 | ||
21 | struct 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 | ||
36 | template <typename LibObjT> | |
37 | class CommonSourceComponentClass; | |
38 | ||
39 | template <typename LibObjT> | |
40 | class CommonFilterComponentClass; | |
41 | ||
42 | template <typename LibObjT> | |
43 | class CommonSinkComponentClass; | |
44 | ||
45 | template <typename LibObjT> | |
46 | class CommonComponentClass : public BorrowedObject<LibObjT> | |
47 | { | |
48 | private: | |
49 | using _ThisBorrowedObject = BorrowedObject<LibObjT>; | |
50 | ||
51 | public: | |
52 | using typename _ThisBorrowedObject::LibObjPtr; | |
53 | using Shared = SharedObject<CommonComponentClass, LibObjT, internal::ComponentClassRefFuncs>; | |
54 | ||
55 | explicit CommonComponentClass(const LibObjPtr libObjPtr) noexcept : | |
56 | _ThisBorrowedObject {libObjPtr} | |
57 | { | |
58 | } | |
59 | ||
60 | template <typename OtherLibObjT> | |
61 | CommonComponentClass(const CommonComponentClass<OtherLibObjT> compCls) noexcept : | |
62 | _ThisBorrowedObject {compCls} | |
63 | { | |
64 | } | |
65 | ||
66 | template <typename OtherLibObjT> | |
67 | CommonComponentClass operator=(const CommonComponentClass<OtherLibObjT> compCls) noexcept | |
68 | { | |
69 | _ThisBorrowedObject::operator=(compCls); | |
70 | return *this; | |
71 | } | |
72 | ||
73 | /* Not `explicit` to make them behave like copy constructors */ | |
74 | CommonComponentClass( | |
75 | const CommonSourceComponentClass<const bt_component_class_source> other) noexcept; | |
76 | CommonComponentClass( | |
77 | const CommonSourceComponentClass<bt_component_class_source> other) noexcept; | |
78 | CommonComponentClass( | |
79 | const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept; | |
80 | CommonComponentClass( | |
81 | const CommonFilterComponentClass<bt_component_class_filter> other) noexcept; | |
82 | CommonComponentClass( | |
83 | const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept; | |
84 | CommonComponentClass(const CommonSinkComponentClass<bt_component_class_sink> other) noexcept; | |
85 | ||
86 | CommonComponentClass | |
87 | operator=(CommonSourceComponentClass<const bt_component_class_source> other) noexcept; | |
88 | CommonComponentClass | |
89 | operator=(CommonSourceComponentClass<bt_component_class_source> other) noexcept; | |
90 | CommonComponentClass | |
91 | operator=(CommonFilterComponentClass<const bt_component_class_filter> other) noexcept; | |
92 | CommonComponentClass | |
93 | operator=(CommonFilterComponentClass<bt_component_class_filter> other) noexcept; | |
94 | CommonComponentClass | |
95 | operator=(CommonSinkComponentClass<const bt_component_class_sink> other) noexcept; | |
96 | CommonComponentClass | |
97 | operator=(CommonSinkComponentClass<bt_component_class_sink> other) noexcept; | |
98 | ||
99 | bool isSource() const noexcept | |
100 | { | |
101 | return static_cast<bool>(bt_component_class_is_source(this->libObjPtr())); | |
102 | } | |
103 | ||
104 | bool isFilter() const noexcept | |
105 | { | |
106 | return static_cast<bool>(bt_component_class_is_filter(this->libObjPtr())); | |
107 | } | |
108 | ||
109 | bool isSink() const noexcept | |
110 | { | |
111 | return static_cast<bool>(bt_component_class_is_sink(this->libObjPtr())); | |
112 | } | |
113 | ||
114 | bt2c::CStringView name() const noexcept | |
115 | { | |
116 | return bt_component_class_get_name(this->libObjPtr()); | |
117 | } | |
118 | ||
119 | bt2c::CStringView description() const noexcept | |
120 | { | |
121 | return bt_component_class_get_description(this->libObjPtr()); | |
122 | } | |
123 | ||
124 | bt2c::CStringView help() const noexcept | |
125 | { | |
126 | return bt_component_class_get_help(this->libObjPtr()); | |
127 | } | |
128 | }; | |
129 | ||
130 | using ComponentClass = CommonComponentClass<bt_component_class>; | |
131 | using ConstComponentClass = CommonComponentClass<const bt_component_class>; | |
132 | ||
133 | namespace internal { | |
134 | ||
135 | struct SourceComponentClassRefFuncs final | |
136 | { | |
137 | static void get(const bt_component_class_source * const libObjPtr) noexcept | |
138 | { | |
139 | bt_component_class_source_get_ref(libObjPtr); | |
140 | } | |
141 | ||
142 | static void put(const bt_component_class_source * const libObjPtr) noexcept | |
143 | { | |
144 | bt_component_class_source_put_ref(libObjPtr); | |
145 | } | |
146 | }; | |
147 | ||
148 | } /* namespace internal */ | |
149 | ||
150 | template <typename LibObjT> | |
151 | class CommonSourceComponentClass final : public BorrowedObject<LibObjT> | |
152 | { | |
153 | private: | |
154 | using _ThisBorrowedObject = BorrowedObject<LibObjT>; | |
155 | ||
156 | public: | |
157 | using typename _ThisBorrowedObject::LibObjPtr; | |
158 | using Shared = | |
159 | SharedObject<CommonSourceComponentClass, LibObjT, internal::SourceComponentClassRefFuncs>; | |
160 | ||
161 | CommonSourceComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} | |
162 | { | |
163 | } | |
164 | ||
165 | template <typename OtherLibObjT> | |
166 | CommonSourceComponentClass(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept : | |
167 | _ThisBorrowedObject {compCls} | |
168 | { | |
169 | } | |
170 | ||
171 | template <typename OtherLibObjT> | |
172 | CommonSourceComponentClass | |
173 | operator=(const CommonSourceComponentClass<OtherLibObjT> compCls) noexcept | |
174 | { | |
175 | _ThisBorrowedObject::operator=(compCls); | |
176 | return *this; | |
177 | } | |
178 | ||
ee137c4e PP |
179 | template <typename UserComponentT> |
180 | static CommonSourceComponentClass<LibObjT>::Shared create() | |
181 | { | |
182 | return CommonSourceComponentClass::Shared::createWithoutRef( | |
183 | internal::createSourceCompCls<UserComponentT>()); | |
184 | } | |
185 | ||
cb036945 SM |
186 | bt2c::CStringView name() const noexcept |
187 | { | |
188 | return this->_constComponentClass().name(); | |
189 | } | |
190 | ||
191 | bt2c::CStringView description() const noexcept | |
192 | { | |
193 | return this->_constComponentClass().description(); | |
194 | } | |
195 | ||
196 | bt2c::CStringView help() const noexcept | |
197 | { | |
198 | return this->_constComponentClass().help(); | |
199 | } | |
200 | ||
201 | private: | |
202 | ConstComponentClass _constComponentClass() const noexcept | |
203 | { | |
204 | return ConstComponentClass { | |
205 | bt_component_class_source_as_component_class_const(this->libObjPtr())}; | |
206 | } | |
207 | }; | |
208 | ||
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())} | |
213 | { | |
214 | } | |
215 | ||
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())} | |
220 | { | |
221 | } | |
222 | ||
223 | template <typename LibObjT> | |
224 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
225 | const CommonSourceComponentClass<const bt_component_class_source> other) noexcept | |
226 | { | |
227 | BorrowedObject<LibObjT>::operator=(ConstComponentClass { | |
228 | bt_component_class_source_as_component_class_const(other.libObjPtr())}); | |
229 | return *this; | |
230 | } | |
231 | ||
232 | template <typename LibObjT> | |
233 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
234 | const CommonSourceComponentClass<bt_component_class_source> other) noexcept | |
235 | { | |
236 | BorrowedObject<LibObjT>::operator=( | |
237 | ComponentClass {bt_component_class_source_as_component_class(other.libObjPtr())}); | |
238 | return *this; | |
239 | } | |
240 | ||
241 | using SourceComponentClass = CommonSourceComponentClass<bt_component_class_source>; | |
242 | using ConstSourceComponentClass = CommonSourceComponentClass<const bt_component_class_source>; | |
243 | ||
244 | namespace internal { | |
245 | ||
246 | struct FilterComponentClassRefFuncs final | |
247 | { | |
248 | static void get(const bt_component_class_filter * const libObjPtr) noexcept | |
249 | { | |
250 | bt_component_class_filter_get_ref(libObjPtr); | |
251 | } | |
252 | ||
253 | static void put(const bt_component_class_filter * const libObjPtr) noexcept | |
254 | { | |
255 | bt_component_class_filter_put_ref(libObjPtr); | |
256 | } | |
257 | }; | |
258 | ||
259 | } /* namespace internal */ | |
260 | ||
261 | template <typename LibObjT> | |
262 | class CommonFilterComponentClass final : public BorrowedObject<LibObjT> | |
263 | { | |
264 | private: | |
265 | using _ThisBorrowedObject = BorrowedObject<LibObjT>; | |
266 | ||
267 | public: | |
268 | using typename _ThisBorrowedObject::LibObjPtr; | |
269 | using Shared = | |
270 | SharedObject<CommonFilterComponentClass, LibObjT, internal::FilterComponentClassRefFuncs>; | |
271 | ||
272 | CommonFilterComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} | |
273 | { | |
274 | } | |
275 | ||
276 | template <typename OtherLibObjT> | |
277 | CommonFilterComponentClass(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept : | |
278 | _ThisBorrowedObject {compCls} | |
279 | { | |
280 | } | |
281 | ||
282 | template <typename OtherLibObjT> | |
283 | CommonFilterComponentClass | |
284 | operator=(const CommonFilterComponentClass<OtherLibObjT> compCls) noexcept | |
285 | { | |
286 | _ThisBorrowedObject::operator=(compCls); | |
287 | return *this; | |
288 | } | |
289 | ||
ee137c4e PP |
290 | template <typename UserComponentT> |
291 | static CommonFilterComponentClass<LibObjT>::Shared create() | |
292 | { | |
293 | return CommonFilterComponentClass::Shared::createWithoutRef( | |
294 | internal::createFilterCompCls<UserComponentT>()); | |
295 | } | |
296 | ||
cb036945 SM |
297 | bt2c::CStringView name() const noexcept |
298 | { | |
299 | return this->_constComponentClass().name(); | |
300 | } | |
301 | ||
302 | bt2c::CStringView description() const noexcept | |
303 | { | |
304 | return this->_constComponentClass().description(); | |
305 | } | |
306 | ||
307 | bt2c::CStringView help() const noexcept | |
308 | { | |
309 | return this->_constComponentClass().help(); | |
310 | } | |
311 | ||
312 | private: | |
313 | ConstComponentClass _constComponentClass() const noexcept | |
314 | { | |
315 | return ConstComponentClass { | |
316 | bt_component_class_filter_as_component_class_const(this->libObjPtr())}; | |
317 | } | |
318 | }; | |
319 | ||
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())} | |
324 | { | |
325 | } | |
326 | ||
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())} | |
331 | { | |
332 | } | |
333 | ||
334 | template <typename LibObjT> | |
335 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
336 | const CommonFilterComponentClass<const bt_component_class_filter> other) noexcept | |
337 | { | |
338 | BorrowedObject<LibObjT>::operator=(ConstComponentClass { | |
339 | bt_component_class_filter_as_component_class_const(other.libObjPtr())}); | |
340 | return *this; | |
341 | } | |
342 | ||
343 | template <typename LibObjT> | |
344 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
345 | const CommonFilterComponentClass<bt_component_class_filter> other) noexcept | |
346 | { | |
347 | BorrowedObject<LibObjT>::operator=( | |
348 | ComponentClass {bt_component_class_filter_as_component_class(other.libObjPtr())}); | |
349 | return *this; | |
350 | } | |
351 | ||
352 | using FilterComponentClass = CommonFilterComponentClass<bt_component_class_filter>; | |
353 | using ConstFilterComponentClass = CommonFilterComponentClass<const bt_component_class_filter>; | |
354 | ||
355 | namespace internal { | |
356 | ||
357 | struct SinkComponentClassRefFuncs final | |
358 | { | |
359 | static void get(const bt_component_class_sink * const libObjPtr) noexcept | |
360 | { | |
361 | bt_component_class_sink_get_ref(libObjPtr); | |
362 | } | |
363 | ||
364 | static void put(const bt_component_class_sink * const libObjPtr) noexcept | |
365 | { | |
366 | bt_component_class_sink_put_ref(libObjPtr); | |
367 | } | |
368 | }; | |
369 | ||
370 | } /* namespace internal */ | |
371 | ||
372 | template <typename LibObjT> | |
373 | class CommonSinkComponentClass final : public BorrowedObject<LibObjT> | |
374 | { | |
375 | private: | |
376 | using _ThisBorrowedObject = BorrowedObject<LibObjT>; | |
377 | ||
378 | public: | |
379 | using typename _ThisBorrowedObject::LibObjPtr; | |
380 | using Shared = | |
381 | SharedObject<CommonSinkComponentClass, LibObjT, internal::SinkComponentClassRefFuncs>; | |
382 | ||
383 | CommonSinkComponentClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} | |
384 | { | |
385 | } | |
386 | ||
387 | template <typename OtherLibObjT> | |
388 | CommonSinkComponentClass(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept : | |
389 | _ThisBorrowedObject {compCls} | |
390 | { | |
391 | } | |
392 | ||
393 | template <typename OtherLibObjT> | |
394 | CommonSinkComponentClass | |
395 | operator=(const CommonSinkComponentClass<OtherLibObjT> compCls) noexcept | |
396 | { | |
397 | _ThisBorrowedObject::operator=(compCls); | |
398 | return *this; | |
399 | } | |
400 | ||
ee137c4e PP |
401 | template <typename UserComponentT> |
402 | static CommonSinkComponentClass<LibObjT>::Shared create() | |
403 | { | |
404 | return CommonSinkComponentClass::Shared::createWithoutRef( | |
405 | internal::createSinkCompCls<UserComponentT>()); | |
406 | } | |
407 | ||
cb036945 SM |
408 | bt2c::CStringView name() const noexcept |
409 | { | |
410 | return this->_constComponentClass().name(); | |
411 | } | |
412 | ||
413 | bt2c::CStringView description() const noexcept | |
414 | { | |
415 | return this->_constComponentClass().description(); | |
416 | } | |
417 | ||
418 | bt2c::CStringView help() const noexcept | |
419 | { | |
420 | return this->_constComponentClass().help(); | |
421 | } | |
422 | ||
423 | private: | |
424 | ConstComponentClass _constComponentClass() const noexcept | |
425 | { | |
426 | return ConstComponentClass { | |
427 | bt_component_class_sink_as_component_class_const(this->libObjPtr())}; | |
428 | } | |
429 | }; | |
430 | ||
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())} | |
435 | { | |
436 | } | |
437 | ||
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())} | |
442 | { | |
443 | } | |
444 | ||
445 | template <typename LibObjT> | |
446 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
447 | const CommonSinkComponentClass<const bt_component_class_sink> other) noexcept | |
448 | { | |
449 | BorrowedObject<LibObjT>::operator=( | |
450 | ConstComponentClass {bt_component_class_sink_as_component_class_const(other.libObjPtr())}); | |
451 | return *this; | |
452 | } | |
453 | ||
454 | template <typename LibObjT> | |
455 | CommonComponentClass<LibObjT> CommonComponentClass<LibObjT>::operator=( | |
456 | const CommonSinkComponentClass<bt_component_class_sink> other) noexcept | |
457 | { | |
458 | BorrowedObject<LibObjT>::operator=( | |
459 | ComponentClass {bt_component_class_sink_as_component_class(other.libObjPtr())}); | |
460 | return *this; | |
461 | } | |
462 | ||
463 | using SinkComponentClass = CommonSinkComponentClass<bt_component_class_sink>; | |
464 | using ConstSinkComponentClass = CommonSinkComponentClass<const bt_component_class_sink>; | |
465 | ||
466 | } /* namespace bt2 */ | |
467 | ||
468 | #endif /* BABELTRACE_CPP_COMMON_BT2_COMPONENT_CLASS_HPP */ |