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