This commit is contained in:
parent
3970b11330
commit
2dbb48d8bb
|
@ -8,9 +8,14 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
static void debugNone()
|
static void debugNone1()
|
||||||
{
|
{
|
||||||
qDebug() << "None";
|
qDebug() << "None 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void debugNone2()
|
||||||
|
{
|
||||||
|
qDebug() << "None 2";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void debugValueI( int i )
|
static void debugValueI( int i )
|
||||||
|
@ -95,7 +100,8 @@ int main( int argc, char* argv[] )
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
invoker.addCallback( QskMetaFunction() );
|
invoker.addCallback( QskMetaFunction() );
|
||||||
invoker.addCallback( debugNone );
|
invoker.addCallback( debugNone1 );
|
||||||
|
invoker.addCallback( debugNone2 );
|
||||||
invoker.addCallback( debugValue );
|
invoker.addCallback( debugValue );
|
||||||
invoker.addCallback( debugValueI );
|
invoker.addCallback( debugValueI );
|
||||||
invoker.addCallback( debugValueD );
|
invoker.addCallback( debugValueD );
|
||||||
|
|
|
@ -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 ):
|
QskMetaFunction::QskMetaFunction( QskMetaInvokable* invokable ):
|
||||||
m_invokable( invokable )
|
m_invokable( invokable )
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,11 @@ namespace QskMetaFunctionTraits
|
||||||
template< typename T >
|
template< typename T >
|
||||||
using IsFunction = typename std::enable_if< !FunctionPointer< T >::IsPointerToMemberFunction
|
using IsFunction = typename std::enable_if< !FunctionPointer< T >::IsPointerToMemberFunction
|
||||||
&& FunctionPointer< T >::ArgumentCount >= 0, std::true_type >::type;
|
&& 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
|
class QSK_EXPORT QskMetaFunction
|
||||||
|
@ -54,6 +59,8 @@ public:
|
||||||
QskMetaFunction( const QskMetaFunction& );
|
QskMetaFunction( const QskMetaFunction& );
|
||||||
QskMetaFunction( QskMetaFunction&& );
|
QskMetaFunction( QskMetaFunction&& );
|
||||||
|
|
||||||
|
QskMetaFunction( void(*function)() );
|
||||||
|
|
||||||
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
|
template< typename T, QskMetaFunctionTraits::IsMemberFunction< T >* = nullptr >
|
||||||
QskMetaFunction( T );
|
QskMetaFunction( T );
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,16 @@ namespace
|
||||||
"Bad cast: QskMetaInvokable does not match" );
|
"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(
|
QskMetaInvokable* QskMetaInvokable::instance(
|
||||||
InvokeFunction invoke, const int* parameterTypes, void** functor )
|
InvokeFunction invoke, const int* parameterTypes, void** functor )
|
||||||
{
|
{
|
||||||
|
@ -59,3 +69,47 @@ int QskMetaInvokable::refCount() const
|
||||||
auto that = const_cast< QskMetaInvokable* >( this );
|
auto that = const_cast< QskMetaInvokable* >( this );
|
||||||
return reinterpret_cast< SlotObject* >( that )->ref.load();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,21 @@ private:
|
||||||
const int* m_parameterTypes; // static array !
|
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 >
|
template< typename Function, typename Args, typename R >
|
||||||
class QskMetaFunctionInvokable : public QskMetaInvokable
|
class QskMetaFunctionInvokable : public QskMetaInvokable
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue