6#ifndef QSK_META_FUNCTION_H
7#define QSK_META_FUNCTION_H
14namespace QskMetaFunctionTraits
16 using namespace QtPrivate;
18 template<
typename T >
19 using IsMemberFunction =
typename std::enable_if<
20 FunctionPointer< T >::IsPointerToMemberFunction, std::true_type >::type;
22 template<
typename T >
23 using IsFunctorOrStaticFunction =
typename std::enable_if<
24 !FunctionPointer< T >::IsPointerToMemberFunction, std::true_type >::type;
26 template<
typename T >
27 using IsFunctor =
typename std::enable_if<
28 !FunctionPointer< T >::IsPointerToMemberFunction
29 && FunctionPointer< T >::ArgumentCount == -1, std::true_type >::type;
31 template<
typename T >
32 using IsStaticFunction =
typename std::enable_if<
33 !FunctionPointer< T >::IsPointerToMemberFunction
34 && FunctionPointer< T >::ArgumentCount >= 0, std::true_type >::type;
36 template<
typename T, IsMemberFunction< T >* =
nullptr >
37 constexpr inline int argumentCount()
39 using Traits = FunctionPointer< T >;
40 return Traits::ArgumentCount;
43 template<
typename T, IsStaticFunction< T >* =
nullptr >
44 constexpr inline int argumentCount()
46 using Traits = FunctionPointer< T >;
47 return Traits::ArgumentCount;
50 template<
typename T, IsFunctor< T >* =
nullptr >
51 constexpr inline int argumentCount()
53 using Traits = FunctionPointer<
decltype( &T::operator() ) >;
54 return Traits::ArgumentCount;
57 template<
typename T,
size_t i >
58 constexpr typename std::enable_if< i >= argumentCount< T >(),
int >::type argumentType()
60 return QMetaType::UnknownType;
63 template<
typename T,
size_t i, IsMemberFunction< T >* =
nullptr >
64 constexpr typename std::enable_if < i < argumentCount< T >(),
int >::type argumentType()
66 return ConnectionTypes< typename FunctionPointer< T >::Arguments >::types()[ i ];
69 template<
typename T,
size_t i, IsStaticFunction< T >* =
nullptr >
70 constexpr typename std::enable_if < i < argumentCount< T >(),
int >::type argumentType()
72 return ConnectionTypes< typename FunctionPointer< T >::Arguments >::types()[ i ];
75 template<
typename T,
size_t i, IsFunctor< T >* =
nullptr >
76 constexpr typename std::enable_if < i < argumentCount< T >(),
int >::type argumentType()
78 using Traits = FunctionPointer<
decltype( &T::operator() ) >;
79 return ConnectionTypes< typename Traits::Arguments >::types()[ i ];
109 template<
typename T, QskMetaFunctionTraits::IsMemberFunction< T >* =
nullptr >
112 template<
typename T, QskMetaFunctionTraits::IsFunctor< T >* =
nullptr >
115 template<
typename T, QskMetaFunctionTraits::IsStaticFunction< T >* =
nullptr >
126 explicit operator bool()
const;
128 int returnType()
const;
130 size_t parameterCount()
const;
131 const int* parameterTypes()
const;
133 void invoke( QObject*,
void* args[],
134 Qt::ConnectionType = Qt::AutoConnection );
136 Type functionType()
const;
149inline bool QskMetaFunction::operator!=(
const QskMetaFunction& other )
const
151 return !( *
this == other );
154inline QskMetaFunction::operator bool()
const
159inline bool QskMetaFunction::isNull()
const
161 return m_functionCall ==
nullptr;
166 return m_functionCall;
169#include "QskMetaFunction.hpp"
171inline const int* QskMetaFunction::parameterTypes()
const
173 return m_functionCall ? m_functionCall->parameterTypes() :
nullptr;
176template<
typename T, QskMetaFunctionTraits::IsMemberFunction< T >* >
177inline QskMetaFunction::QskMetaFunction( T function )
179 using namespace QtPrivate;
180 using namespace QskMetaFunctionCall;
182 using Traits = FunctionPointer< T >;
184 constexpr int Argc = Traits::ArgumentCount;
185 using Args =
typename List_Left< typename Traits::Arguments, Argc >::Value;
188 m_functionCall->setParameterTypes(
189 ConnectionTypes< typename Traits::Arguments >::types() );
192template<
typename T, QskMetaFunctionTraits::IsFunctor< T >* >
193inline QskMetaFunction::QskMetaFunction( T functor )
195 using namespace QtPrivate;
196 using namespace QskMetaFunctionCall;
198 using Traits = FunctionPointer<
decltype( &T::operator() ) >;
200 constexpr int Argc = Traits::ArgumentCount;
201 using Args =
typename List_Left< typename Traits::Arguments, Argc >::Value;
204 m_functionCall->setParameterTypes(
205 ConnectionTypes< typename Traits::Arguments >::types() );
208template<
typename T, QskMetaFunctionTraits::IsStaticFunction< T >* >
209inline QskMetaFunction::QskMetaFunction( T function )
211 using namespace QtPrivate;
212 using namespace QskMetaFunctionCall;
214 using Traits = FunctionPointer< T >;
216 constexpr int Argc = Traits::ArgumentCount;
217 using Args =
typename List_Left< typename Traits::Arguments, Argc >::Value;
220 m_functionCall->setParameterTypes(
221 ConnectionTypes< typename Traits::Arguments >::types() );