27#ifndef SDBUS_CXX_TYPETRAITS_H_
28#define SDBUS_CXX_TYPETRAITS_H_
35#if __cplusplus >= 202002L
39#include <unordered_map>
48 template <
typename... _ValueTypes>
class Struct;
58 template <
typename... _Results>
class Result;
65 using method_callback = std::function<void(
MethodCall msg)>;
66 using async_reply_handler = std::function<void(
MethodReply& reply,
const Error* error)>;
67 using signal_handler = std::function<void(
Signal& signal)>;
68 using message_handler = std::function<void(
Message& msg)>;
69 using property_set_callback = std::function<void(
PropertySetCall& msg)>;
73 using Slot = std::unique_ptr<void, std::function<void(
void*)>>;
76 struct request_slot_t {
explicit request_slot_t() =
default; };
79 struct floating_slot_t {
explicit floating_slot_t() =
default; };
82 struct dont_request_slot_t {
explicit dont_request_slot_t() =
default; };
83 [[deprecated(
"Replaced by floating_slot")]]
inline constexpr dont_request_slot_t dont_request_slot{};
85 struct adopt_message_t {
explicit adopt_message_t() =
default; };
88 struct adopt_fd_t {
explicit adopt_fd_t() =
default; };
92 struct dont_run_event_loop_thread_t {
explicit dont_run_event_loop_thread_t() =
default; };
95 struct with_future_t {
explicit with_future_t() =
default; };
98 struct dont_expect_reply_t {
explicit dont_expect_reply_t() =
default; };
102 template <
class... _T>
constexpr bool always_false =
false;
105 template <
typename _T,
typename _Enable =
void>
108 static constexpr bool is_valid =
false;
109 static constexpr bool is_trivial_dbus_type =
false;
111 static const std::string str()
115 static_assert(always_false<_T>,
"Unsupported DBus type (template specializations are needed for your custom types)");
120 template <
typename _T>
125 template <
typename _T>
133 static constexpr bool is_valid =
true;
134 static constexpr bool is_trivial_dbus_type =
false;
136 static const std::string str()
145 static constexpr bool is_valid =
true;
146 static constexpr bool is_trivial_dbus_type =
true;
148 static const std::string str()
157 static constexpr bool is_valid =
true;
158 static constexpr bool is_trivial_dbus_type =
true;
160 static const std::string str()
169 static constexpr bool is_valid =
true;
170 static constexpr bool is_trivial_dbus_type =
true;
172 static const std::string str()
181 static constexpr bool is_valid =
true;
182 static constexpr bool is_trivial_dbus_type =
true;
184 static const std::string str()
193 static constexpr bool is_valid =
true;
194 static constexpr bool is_trivial_dbus_type =
true;
196 static const std::string str()
205 static constexpr bool is_valid =
true;
206 static constexpr bool is_trivial_dbus_type =
true;
208 static const std::string str()
217 static constexpr bool is_valid =
true;
218 static constexpr bool is_trivial_dbus_type =
true;
220 static const std::string str()
229 static constexpr bool is_valid =
true;
230 static constexpr bool is_trivial_dbus_type =
true;
232 static const std::string str()
241 static constexpr bool is_valid =
true;
242 static constexpr bool is_trivial_dbus_type =
true;
244 static const std::string str()
253 static constexpr bool is_valid =
true;
254 static constexpr bool is_trivial_dbus_type =
false;
256 static const std::string str()
265 static constexpr bool is_valid =
true;
266 static constexpr bool is_trivial_dbus_type =
false;
268 static const std::string str()
274 template <std::
size_t _N>
277 static constexpr bool is_valid =
true;
278 static constexpr bool is_trivial_dbus_type =
false;
280 static const std::string str()
286 template <std::
size_t _N>
289 static constexpr bool is_valid =
true;
290 static constexpr bool is_trivial_dbus_type =
false;
292 static const std::string str()
301 static constexpr bool is_valid =
true;
302 static constexpr bool is_trivial_dbus_type =
false;
304 static const std::string str()
310 template <
typename... _ValueTypes>
313 static constexpr bool is_valid =
true;
314 static constexpr bool is_trivial_dbus_type =
false;
316 static const std::string str()
318 std::string signature;
320 (signature += ... += signature_of<_ValueTypes>::str());
329 static constexpr bool is_valid =
true;
330 static constexpr bool is_trivial_dbus_type =
false;
332 static const std::string str()
338 template <
typename... Elements>
345 static constexpr bool is_valid =
true;
346 static constexpr bool is_trivial_dbus_type =
false;
348 static const std::string str()
357 static constexpr bool is_valid =
true;
358 static constexpr bool is_trivial_dbus_type =
false;
360 static const std::string str()
369 static constexpr bool is_valid =
true;
370 static constexpr bool is_trivial_dbus_type =
false;
372 static const std::string str()
378 template <
typename _Element,
typename _Allocator>
381 static constexpr bool is_valid =
true;
382 static constexpr bool is_trivial_dbus_type =
false;
384 static const std::string str()
386 return "a" + signature_of<_Element>::str();
390 template <
typename _Element, std::
size_t _Size>
393 static constexpr bool is_valid =
true;
394 static constexpr bool is_trivial_dbus_type =
false;
396 static const std::string str()
398 return "a" + signature_of<_Element>::str();
402#if __cplusplus >= 202002L
403 template <
typename _Element, std::
size_t _Extent>
406 static constexpr bool is_valid =
true;
407 static constexpr bool is_trivial_dbus_type =
false;
409 static const std::string str()
411 return "a" + signature_of<_Element>::str();
416 template <
typename _Enum>
417 struct signature_of<_Enum, typename std::enable_if_t<std::is_enum_v<_Enum>>>
422 template <
typename _Key,
typename _Value,
typename _Compare,
typename _Allocator>
425 static constexpr bool is_valid =
true;
426 static constexpr bool is_trivial_dbus_type =
false;
428 static const std::string str()
430 return "a{" + signature_of<_Key>::str() + signature_of<_Value>::str() +
"}";
434 template <
typename _Key,
typename _Value,
typename _Hash,
typename _KeyEqual,
typename _Allocator>
435 struct signature_of<std::unordered_map<_Key, _Value, _Hash, _KeyEqual, _Allocator>>
437 static constexpr bool is_valid =
true;
438 static constexpr bool is_trivial_dbus_type =
false;
440 static const std::string str()
442 return "a{" + signature_of<_Key>::str() + signature_of<_Value>::str() +
"}";
448 template <
typename _Type>
453 template <
typename _Type>
458 template <
typename _Type>
463 template <
typename _ReturnType,
typename... _Args>
466 typedef _ReturnType result_type;
467 typedef std::tuple<_Args...> arguments_type;
468 typedef std::tuple<std::decay_t<_Args>...> decayed_arguments_type;
470 typedef _ReturnType function_type(_Args...);
472 static constexpr std::size_t arity =
sizeof...(_Args);
489 template <
size_t _Idx>
492 typedef std::tuple_element_t<_Idx, std::tuple<_Args...>> type;
495 template <
size_t _Idx>
496 using arg_t =
typename arg<_Idx>::type;
499 template <
typename _ReturnType,
typename... _Args>
503 static constexpr bool is_async =
false;
504 static constexpr bool has_error_param =
false;
507 template <
typename... _Args>
511 static constexpr bool has_error_param =
true;
514 template <
typename... _Args,
typename... _Results>
518 static constexpr bool is_async =
true;
519 using async_result_t =
Result<_Results...>;
522 template <
typename... _Args,
typename... _Results>
526 static constexpr bool is_async =
true;
527 using async_result_t =
Result<_Results...>;
530 template <
typename _ReturnType,
typename... _Args>
535 template <
typename _ClassType,
typename _ReturnType,
typename... _Args>
539 typedef _ClassType& owner_type;
542 template <
typename _ClassType,
typename _ReturnType,
typename... _Args>
546 typedef const _ClassType& owner_type;
549 template <
typename _ClassType,
typename _ReturnType,
typename... _Args>
553 typedef volatile _ClassType& owner_type;
556 template <
typename _ClassType,
typename _ReturnType,
typename... _Args>
560 typedef const volatile _ClassType& owner_type;
563 template <
typename FunctionType>
568 template <
class _Function>
571 template <
class _Function>
574 template <
typename _FunctionType>
577 template <
typename _FunctionType,
size_t _Idx>
580 template <
typename _FunctionType>
583 template <
typename _FunctionType>
586 template <
typename _Function>
592 template <
typename _Function>
593 using tuple_of_function_input_arg_types_t =
typename tuple_of_function_input_arg_types<_Function>::type;
595 template <
typename _Function>
601 template <
typename _Function>
602 using tuple_of_function_output_arg_types_t =
typename tuple_of_function_output_arg_types<_Function>::type;
604 template <
typename _Type>
607 static const std::string str()
613 template <
typename... _Types>
616 static const std::string str()
618 std::string signature;
619 (void)(signature += ... +=
signature_of<std::decay_t<_Types>>::str());
624 template <
typename _Function>
627 static const std::string str()
633 template <
typename _Function>
636 static const std::string str()
645 typedef std::tuple<_Args...> type;
658 template <
typename... _Args>
659 using future_return_t =
typename future_return<_Args...>::type;
664 template <
class _Function,
class _Tuple,
typename... _Args, std::size_t... _I>
665 constexpr decltype(
auto) apply_impl( _Function&& f
668 , std::index_sequence<_I...> )
670 return std::forward<_Function>(f)(std::move(r), std::get<_I>(std::forward<_Tuple>(t))...);
673 template <
class _Function,
class _Tuple, std::size_t... _I>
674 constexpr decltype(
auto) apply_impl( _Function&& f
677 , std::index_sequence<_I...> )
679 return std::forward<_Function>(f)(e, std::get<_I>(std::forward<_Tuple>(t))...);
684 template <
class _Function,
class _Tuple, std::size_t... _I>
685 constexpr decltype(
auto) apply_impl( _Function&& f
687 , std::index_sequence<_I...> )
689 if constexpr (!std::is_void_v<function_result_t<_Function>>)
690 return std::forward<_Function>(f)(std::get<_I>(std::forward<_Tuple>(t))...);
692 return std::forward<_Function>(f)(std::get<_I>(std::forward<_Tuple>(t))...), std::tuple<>{};
698 template <
class _Function,
class _Tuple>
699 constexpr decltype(
auto) apply(_Function&& f, _Tuple&& t)
701 return detail::apply_impl( std::forward<_Function>(f)
702 , std::forward<_Tuple>(t)
703 , std::make_index_sequence<std::tuple_size<std::decay_t<_Tuple>>::value>{} );
708 template <
class _Function,
class _Tuple,
typename... _Args>
709 constexpr decltype(
auto) apply(_Function&& f,
Result<_Args...>&& r, _Tuple&& t)
711 return detail::apply_impl( std::forward<_Function>(f)
713 , std::forward<_Tuple>(t)
714 , std::make_index_sequence<std::tuple_size<std::decay_t<_Tuple>>::value>{} );
719 template <
class _Function,
class _Tuple>
720 constexpr decltype(
auto) apply(_Function&& f,
const Error* e, _Tuple&& t)
722 return detail::apply_impl( std::forward<_Function>(f)
724 , std::forward<_Tuple>(t)
725 , std::make_index_sequence<std::tuple_size<std::decay_t<_Tuple>>::value>{} );
Definition MethodResult.h:50
Definition TypeTraits.h:88
Definition TypeTraits.h:85
Definition TypeTraits.h:606
Definition TypeTraits.h:98
Definition TypeTraits.h:82
Definition TypeTraits.h:92
Definition TypeTraits.h:79
Definition TypeTraits.h:491
Definition TypeTraits.h:465
Definition TypeTraits.h:451
Definition TypeTraits.h:644
Definition TypeTraits.h:76
Definition TypeTraits.h:635
Definition TypeTraits.h:107
Definition TypeTraits.h:597
Definition TypeTraits.h:95