This commit is contained in:
Uwe Rathmann 2018-03-02 07:07:19 +01:00
parent 3970b11330
commit 2dbb48d8bb
5 changed files with 92 additions and 3 deletions

View File

@ -8,9 +8,14 @@
#include <QDebug>
#include <QTimer>
static void debugNone()
static void debugNone1()
{
qDebug() << "None";
qDebug() << "None 1";
}
static void debugNone2()
{
qDebug() << "None 2";
}
static void debugValueI( int i )
@ -95,7 +100,8 @@ int main( int argc, char* argv[] )
#if 1
invoker.addCallback( QskMetaFunction() );
invoker.addCallback( debugNone );
invoker.addCallback( debugNone1 );
invoker.addCallback( debugNone2 );
invoker.addCallback( debugValue );
invoker.addCallback( debugValueI );
invoker.addCallback( debugValueD );

View File

@ -33,6 +33,13 @@ QskMetaFunction::QskMetaFunction():
{
}
QskMetaFunction::QskMetaFunction( void(*function)() ):
m_invokable( QskMetaInvokable::instance(
QskMetaFunctionInvokable0::invoke, nullptr,
reinterpret_cast< void** >( &function ) ) )
{
}
QskMetaFunction::QskMetaFunction( QskMetaInvokable* invokable ):
m_invokable( invokable )
{

View File

@ -26,6 +26,11 @@ namespace QskMetaFunctionTraits
template< typename T >
using IsFunction = typename std::enable_if< !FunctionPointer< T >::IsPointerToMemberFunction
&& FunctionPointer< T >::ArgumentCount >= 0, std::true_type >::type;
template< typename T >
using IsFunction0 = typename std::enable_if< !FunctionPointer< T >::IsPointerToMemberFunction
&& FunctionPointer< T >::ArgumentCount == 0, std::true_type >::type;
}
class QSK_EXPORT QskMetaFunction
@ -54,6 +59,8 @@ public:
QskMetaFunction( const QskMetaFunction& );
QskMetaFunction( QskMetaFunction&& );
QskMetaFunction( void(*function)() );
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
QskMetaFunction( T );

View File

@ -19,6 +19,16 @@ namespace
"Bad cast: QskMetaInvokable does not match" );
}
static inline void qskCallFunction( void (*function)(),
void** args, const int* types )
{
if ( types == nullptr || args == nullptr )
{
function();
return;
}
}
QskMetaInvokable* QskMetaInvokable::instance(
InvokeFunction invoke, const int* parameterTypes, void** functor )
{
@ -59,3 +69,47 @@ int QskMetaInvokable::refCount() const
auto that = const_cast< QskMetaInvokable* >( this );
return reinterpret_cast< SlotObject* >( that )->ref.load();
}
QskMetaFunctionInvokable0::QskMetaFunctionInvokable0( Function function ):
QskMetaInvokable( &invoke, nullptr ),
m_function( function )
{
}
void QskMetaFunctionInvokable0::invoke(int which, QtPrivate::QSlotObjectBase* invokable,
QObject*, void** args, bool* )
{
switch ( which )
{
case Find:
{
*reinterpret_cast< void** >( args[0] ) = nullptr;
break;
}
case Create:
{
*reinterpret_cast< void** >( args[0] ) =
new Invokable( *reinterpret_cast< Function* >( args[1] ) );
break;
}
case Destroy:
{
delete static_cast< Invokable* >( invokable );
break;
}
case Call:
{
auto invokable01 = static_cast< Invokable* >( invokable );
qskCallFunction( invokable01->m_function,
args, invokable01->parameterTypes() );
break;
}
case TypeInfo:
{
*reinterpret_cast< int* >( args ) = 1; // QskMetaFunction::Function
break;
}
}
}

View File

@ -47,6 +47,21 @@ private:
const int* m_parameterTypes; // static array !
};
class QSK_EXPORT QskMetaFunctionInvokable0 : public QskMetaInvokable
{
using Function = void(*)();
using Invokable = QskMetaFunctionInvokable0;
public:
explicit QskMetaFunctionInvokable0( Function function );
static void invoke(int which, QtPrivate::QSlotObjectBase*,
QObject* object, void** args, bool* );
private:
Function m_function;
};
template< typename Function, typename Args, typename R >
class QskMetaFunctionInvokable : public QskMetaInvokable
{