From 0e832e27f8f03412fec8a969270369f0d6ad64f0 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 8 Mar 2018 08:37:44 +0100 Subject: [PATCH] QskMetaFunction::parameterTypes fixed --- src/common/QskMetaFunction.cpp | 31 ++++++++++--------- src/common/QskMetaFunction.h | 4 +-- src/common/QskMetaInvokable.cpp | 53 +++++++++++++++++++++++++++------ src/common/QskMetaInvokable.h | 4 +++ src/common/QskMetaMethod.cpp | 2 +- 5 files changed, 68 insertions(+), 26 deletions(-) diff --git a/src/common/QskMetaFunction.cpp b/src/common/QskMetaFunction.cpp index 8676cbb1..bf40bece 100644 --- a/src/common/QskMetaFunction.cpp +++ b/src/common/QskMetaFunction.cpp @@ -151,20 +151,23 @@ bool QskMetaFunction::operator==( const QskMetaFunction& other ) const return false; } -size_t QskMetaFunction::parameterCount() const +int QskMetaFunction::returnType() const { - if ( auto types = parameterTypes() ) - { - 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 + return QMetaType::Void; // TODO ... } +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 { @@ -224,12 +227,12 @@ void QskMetaFunction::invoke( return; } - const auto argc = parameterCount(); + const auto argc = parameterCount() + 1; // return value + arguments auto types = static_cast< int* >( malloc( argc * sizeof( int ) ) ); 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; const int* parameterTypes = m_functionCall->parameterTypes(); @@ -243,7 +246,7 @@ void QskMetaFunction::invoke( } 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() ) diff --git a/src/common/QskMetaFunction.h b/src/common/QskMetaFunction.h index 61ed9297..89815feb 100644 --- a/src/common/QskMetaFunction.h +++ b/src/common/QskMetaFunction.h @@ -75,10 +75,10 @@ public: explicit operator bool() const; - const int* parameterTypes() const; + int returnType() const; - // including the return type ! size_t parameterCount() const; + const int* parameterTypes() const; void invoke( QObject*, void* args[], Qt::ConnectionType = Qt::AutoConnection ); diff --git a/src/common/QskMetaInvokable.cpp b/src/common/QskMetaInvokable.cpp index 17baf20f..42990b45 100644 --- a/src/common/QskMetaInvokable.cpp +++ b/src/common/QskMetaInvokable.cpp @@ -185,16 +185,14 @@ QVector< int > QskMetaInvokable::parameterTypes() const { case MetaMethod: { - const auto& d = m_methodData; - if ( m_methodData.metaObject ) - { -#if 1 - // should be doable without QMetaMethod. TODO ... - const auto method = d.metaObject->method( d.methodIndex ); -#endif - const int paramCount = method.parameterCount(); + // should be doable without QMetaMethod. TODO ... + const auto method = QskMetaInvokable::method(); + const int paramCount = method.parameterCount(); + if ( paramCount > 0 ) + { paramTypes.reserve( paramCount ); + for ( int i = 0; i < paramCount; i++ ) paramTypes += method.parameterType( i ); } @@ -203,7 +201,7 @@ QVector< int > QskMetaInvokable::parameterTypes() const } case MetaFunction: { - auto types = Function( m_functionData.functionCall ).parameterTypes(); + auto types = function().parameterTypes(); if ( types ) { while ( *types ) @@ -218,6 +216,43 @@ QVector< int > QskMetaInvokable::parameterTypes() const 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[], Qt::ConnectionType connectionType ) diff --git a/src/common/QskMetaInvokable.h b/src/common/QskMetaInvokable.h index 2208e4e8..be373317 100644 --- a/src/common/QskMetaInvokable.h +++ b/src/common/QskMetaInvokable.h @@ -54,12 +54,16 @@ public: bool isNull() const; QVector< int > parameterTypes() const; + int returnType() const; void invoke( QObject*, void* args[], Qt::ConnectionType = Qt::AutoConnection ); void reset(); + QMetaMethod method() const; + QskMetaFunction function() const; + private: struct FunctionData { diff --git a/src/common/QskMetaMethod.cpp b/src/common/QskMetaMethod.cpp index f550070c..745a5ef0 100644 --- a/src/common/QskMetaMethod.cpp +++ b/src/common/QskMetaMethod.cpp @@ -176,7 +176,7 @@ QMetaMethod QskMetaMethod::method( } else if ( methodName[0] == slotIndicator ) { - auto signature = QMetaObject::normalizedSignature( methodName + 1 ); + auto signature = QMetaObject::normalizedSignature( methodName + 1 ); index = metaObject->indexOfSlot( signature ); } else