QskMetaFunction::parameterTypes fixed

This commit is contained in:
Uwe Rathmann 2018-03-08 08:37:44 +01:00
parent 6c9d78c532
commit 0e832e27f8
5 changed files with 68 additions and 26 deletions

View File

@ -151,20 +151,23 @@ bool QskMetaFunction::operator==( const QskMetaFunction& other ) const
return false; return false;
} }
size_t QskMetaFunction::parameterCount() const int QskMetaFunction::returnType() const
{ {
if ( auto types = parameterTypes() ) return QMetaType::Void; // TODO ...
{
for ( int i = 1;; i++ )
{
if ( types[ i ] == QMetaType::UnknownType )
return i + 1; // including the return type
}
}
return 1; // we always have a return type
} }
size_t QskMetaFunction::parameterCount() const
{
int count = 0;
if ( auto types = parameterTypes() )
{
while ( types[ count ] != QMetaType::UnknownType )
count++;
}
return count;
}
QskMetaFunction::Type QskMetaFunction::functionType() const QskMetaFunction::Type QskMetaFunction::functionType() const
{ {
@ -224,12 +227,12 @@ void QskMetaFunction::invoke(
return; return;
} }
const auto argc = parameterCount(); const auto argc = parameterCount() + 1; // return value + arguments
auto types = static_cast< int* >( malloc( argc * sizeof( int ) ) ); auto types = static_cast< int* >( malloc( argc * sizeof( int ) ) );
auto arguments = static_cast< void** >( malloc( argc * sizeof( void* ) ) ); auto arguments = static_cast< void** >( malloc( argc * sizeof( void* ) ) );
types[0] = QMetaType::UnknownType; // a return type is not possible types[0] = QMetaType::UnknownType;
arguments[0] = nullptr; arguments[0] = nullptr;
const int* parameterTypes = m_functionCall->parameterTypes(); const int* parameterTypes = m_functionCall->parameterTypes();
@ -243,7 +246,7 @@ void QskMetaFunction::invoke(
} }
types[i] = parameterTypes[i - 1]; types[i] = parameterTypes[i - 1];
arguments[i] = QMetaType::create( parameterTypes[i - 1], argv[i] ); arguments[i] = QMetaType::create( types[i], argv[i] );
} }
if ( receiver.isNull() ) if ( receiver.isNull() )

View File

@ -75,10 +75,10 @@ public:
explicit operator bool() const; explicit operator bool() const;
const int* parameterTypes() const; int returnType() const;
// including the return type !
size_t parameterCount() const; size_t parameterCount() const;
const int* parameterTypes() const;
void invoke( QObject*, void* args[], void invoke( QObject*, void* args[],
Qt::ConnectionType = Qt::AutoConnection ); Qt::ConnectionType = Qt::AutoConnection );

View File

@ -185,16 +185,14 @@ QVector< int > QskMetaInvokable::parameterTypes() const
{ {
case MetaMethod: case MetaMethod:
{ {
const auto& d = m_methodData; // should be doable without QMetaMethod. TODO ...
if ( m_methodData.metaObject ) const auto method = QskMetaInvokable::method();
{
#if 1
// should be doable without QMetaMethod. TODO ...
const auto method = d.metaObject->method( d.methodIndex );
#endif
const int paramCount = method.parameterCount();
const int paramCount = method.parameterCount();
if ( paramCount > 0 )
{
paramTypes.reserve( paramCount ); paramTypes.reserve( paramCount );
for ( int i = 0; i < paramCount; i++ ) for ( int i = 0; i < paramCount; i++ )
paramTypes += method.parameterType( i ); paramTypes += method.parameterType( i );
} }
@ -203,7 +201,7 @@ QVector< int > QskMetaInvokable::parameterTypes() const
} }
case MetaFunction: case MetaFunction:
{ {
auto types = Function( m_functionData.functionCall ).parameterTypes(); auto types = function().parameterTypes();
if ( types ) if ( types )
{ {
while ( *types ) while ( *types )
@ -218,6 +216,43 @@ QVector< int > QskMetaInvokable::parameterTypes() const
return paramTypes; return paramTypes;
} }
int QskMetaInvokable::returnType() const
{
switch( m_type )
{
case MetaMethod:
{
return method().returnType();
}
case MetaFunction:
{
return function().returnType();
}
default:
{
return QMetaType::Void;
}
}
}
QMetaMethod QskMetaInvokable::method() const
{
if ( m_type == MetaMethod )
return m_methodData.metaObject->method( m_methodData.methodIndex );
return QMetaMethod();
}
QskMetaFunction QskMetaInvokable::function() const
{
if ( m_type == MetaFunction && m_functionData.functionCall )
{
Function function( m_functionData.functionCall );
return *static_cast< QskMetaFunction* >( &function );
}
return QskMetaFunction();
}
void QskMetaInvokable::invoke( QObject* object, void* args[], void QskMetaInvokable::invoke( QObject* object, void* args[],
Qt::ConnectionType connectionType ) Qt::ConnectionType connectionType )

View File

@ -54,12 +54,16 @@ public:
bool isNull() const; bool isNull() const;
QVector< int > parameterTypes() const; QVector< int > parameterTypes() const;
int returnType() const;
void invoke( QObject*, void* args[], void invoke( QObject*, void* args[],
Qt::ConnectionType = Qt::AutoConnection ); Qt::ConnectionType = Qt::AutoConnection );
void reset(); void reset();
QMetaMethod method() const;
QskMetaFunction function() const;
private: private:
struct FunctionData struct FunctionData
{ {

View File

@ -176,7 +176,7 @@ QMetaMethod QskMetaMethod::method(
} }
else if ( methodName[0] == slotIndicator ) else if ( methodName[0] == slotIndicator )
{ {
auto signature = QMetaObject::normalizedSignature( methodName + 1 ); auto signature = QMetaObject::normalizedSignature( methodName + 1 );
index = metaObject->indexOfSlot( signature ); index = metaObject->indexOfSlot( signature );
} }
else else