From 6e4421d4b718064c0d4bd33188950b0055a32bbe Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 1 Mar 2018 15:13:55 +0100 Subject: [PATCH] QskMetaFunction::init removed - saves some size in the text segment --- playground/invoker/main.cpp | 72 +++++++++++++++++++++++++++++++++- src/common/QskMetaFunction.cpp | 7 ---- src/common/QskMetaFunction.h | 24 ++++++------ src/common/QskMetaInvokable.h | 2 +- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/playground/invoker/main.cpp b/playground/invoker/main.cpp index 8377cc2a..b6761ef5 100644 --- a/playground/invoker/main.cpp +++ b/playground/invoker/main.cpp @@ -20,6 +20,8 @@ static void debugValue( qreal d, int i ) class MyObject : public QObject { + Q_OBJECT + public: MyObject( QObject* parent = nullptr ): QObject( parent ) @@ -45,31 +47,65 @@ public: { qDebug() << i; } + +Q_SIGNALS: + void done( double, int ); }; +class MyObject2: public MyObject +{ +public: + MyObject2( QObject* parent = nullptr ): + MyObject( parent ) + { + } + + virtual ~MyObject2() + { + } + + virtual void noop() + { + } +}; + +static auto fs = []( int i, double d ) { qDebug() << i << d; }; + int main( int argc, char* argv[] ) { QCoreApplication app( argc, argv ); MyObject object; + MyObject2 object2; Invoker invoker; + invoker.addCallback( QskMetaFunction() ); +#if 1 invoker.addCallback( debugValue ); invoker.addCallback( debugValueI ); invoker.addCallback( &object, &MyObject::print1 ); + invoker.addCallback( &object2, &MyObject2::print1 ); invoker.addCallback( &object, &MyObject::print2 ); invoker.addCallback( &object, &MyObject::print3 ); invoker.addCallback( &object, &MyObject::print4 ); invoker.addCallback( &object, []( double d, int i ) { qDebug() << d << i; } ); - invoker.addCallback( &object, []( int i, double d ) { qDebug() << i << d; } ); + + int num = 111; + auto f = [&num]( int i, double d ) { qDebug() << i << d << (++num); }; + invoker.addCallback( &object, f ); + invoker.addCallback( &object2, f ); + invoker.addCallback( &object, fs ); + invoker.addCallback( &object2, fs ); + invoker.addCallback( &object, []( double d ) { qDebug() << d; } ); invoker.addCallback( []() { qDebug() << "HERE"; } ); - invoker.addCallback( [ = ]( double d, int i ) { qDebug() << d << i; } ); invoker.addCallback( []( int i, double d ) { qDebug() << i << d; } ); invoker.addCallback( []( int i ) { qDebug() << i; } ); invoker.addCallback( []( double d ) { qDebug() << d; } ); +#endif +#if 1 qDebug() << "== Direct Connections"; invoker.invoke( 3.14, 35, Qt::DirectConnection ); @@ -77,7 +113,39 @@ int main( int argc, char* argv[] ) QTimer::singleShot( 0, [&invoker] { invoker.invoke( 0.07, 42, Qt::QueuedConnection ); } ); +#endif QTimer::singleShot( 100, &app, QCoreApplication::quit ); + +#if 0 + QObject::connect( &object2, &MyObject2::done, + &object, &MyObject::print1 ); + + QObject::connect( &object2, &MyObject2::done, debugValue ); + QObject::connect( &object2, &MyObject2::done, debugValueI ); + QObject::connect( &object2, &MyObject2::done, &object, &MyObject::print1 ); + QObject::connect( &object2, &MyObject2::done, &object2, &MyObject2::print1 ); + QObject::connect( &object2, &MyObject2::done, &object, &MyObject::print2 ); + QObject::connect( &object2, &MyObject2::done, &object, &MyObject::print3 ); + QObject::connect( &object2, &MyObject2::done, &object, &MyObject::print4 ); + QObject::connect( &object2, &MyObject2::done, &object, []( double d, int i ) { qDebug() << d << i; } ); + + int num2 = 111; + auto f2 = [&num2]( int i, double d ) { qDebug() << i << d << (++num2); }; + QObject::connect( &object2, &MyObject2::done, &object, f2 ); + QObject::connect( &object2, &MyObject2::done, &object2, f2 ); + QObject::connect( &object2, &MyObject2::done, &object, fs ); + QObject::connect( &object2, &MyObject2::done, &object2, fs ); + + QObject::connect( &object2, &MyObject2::done, &object, []( double d ) { qDebug() << d; } ); + QObject::connect( &object2, &MyObject2::done, []() { qDebug() << "HERE"; } ); + QObject::connect( &object2, &MyObject2::done, []( int i, double d ) { qDebug() << i << d; } ); + QObject::connect( &object2, &MyObject2::done, []( int i ) { qDebug() << i; } ); + QObject::connect( &object2, &MyObject2::done, []( double d ) { qDebug() << d; } ); + +#endif + return app.exec(); } + +#include "main.moc" diff --git a/src/common/QskMetaFunction.cpp b/src/common/QskMetaFunction.cpp index 4077f237..33f37cc8 100644 --- a/src/common/QskMetaFunction.cpp +++ b/src/common/QskMetaFunction.cpp @@ -98,13 +98,6 @@ QskMetaFunction& QskMetaFunction::operator=( const QskMetaFunction& other ) return *this; } -void QskMetaFunction::init( QskMetaInvokable* invokable, - const int* parameterTypes ) -{ - m_invokable = invokable; - m_parameterTypes = parameterTypes; -} - size_t QskMetaFunction::parameterCount() const { if ( m_parameterTypes ) diff --git a/src/common/QskMetaFunction.h b/src/common/QskMetaFunction.h index 4052ddb0..d87b7875 100644 --- a/src/common/QskMetaFunction.h +++ b/src/common/QskMetaFunction.h @@ -82,8 +82,6 @@ protected: friend class QskMetaCallback; QskMetaFunction( QskMetaInvokable*, const int* ); - - void init( QskMetaInvokable*, const int* ); QskMetaInvokable* invokable() const; private: @@ -108,14 +106,14 @@ inline QskMetaFunction::QskMetaFunction( T function ) using Traits = FunctionPointer< T >; - const int Argc = Traits::ArgumentCount; + constexpr int Argc = Traits::ArgumentCount; using Args = typename List_Left< typename Traits::Arguments, Argc >::Value; - auto invokable = QskMetaInvokable::instance( - QskMetaMemberInvokable< T, Args, void >::invoke, - reinterpret_cast< void** >( &function ) ); + m_invokable = QskMetaInvokable::instance( + QskMetaMemberInvokable< T, Args, void >::invoke, + reinterpret_cast< void** >( &function ) ); - init( invokable, ConnectionTypes< typename Traits::Arguments >::types() ); + m_parameterTypes = ConnectionTypes< typename Traits::Arguments >::types(); } template< typename T, QskMetaFunctionTraits::IsFunction< T >* > @@ -125,14 +123,14 @@ inline QskMetaFunction::QskMetaFunction( T function ) using Traits = FunctionPointer< T >; - const int Argc = Traits::ArgumentCount; + constexpr int Argc = Traits::ArgumentCount; using Args = typename List_Left< typename Traits::Arguments, Argc >::Value; - auto invokable = QskMetaInvokable::instance( + m_invokable = QskMetaInvokable::instance( QskMetaFunctionInvokable< T, Args, void >::invoke, reinterpret_cast< void** >( &function ) ); - init( invokable, ConnectionTypes< typename Traits::Arguments >::types() ); + m_parameterTypes = ConnectionTypes< typename Traits::Arguments >::types(); } template< typename T, QskMetaFunctionTraits::IsFunctor< T >* > @@ -142,14 +140,14 @@ inline QskMetaFunction::QskMetaFunction( T functor ) using Traits = FunctionPointer< decltype( &T::operator() ) >; - const int Argc = Traits::ArgumentCount; + constexpr int Argc = Traits::ArgumentCount; using Args = typename List_Left< typename Traits::Arguments, Argc >::Value; - auto invokable = QskMetaInvokable::instance( + m_invokable = QskMetaInvokable::instance( QskMetaFunctorInvokable< T, Argc, Args, void >::invoke, reinterpret_cast< void** >( &functor ) ); - init( invokable, ConnectionTypes< typename Traits::Arguments >::types() ); + m_parameterTypes = ConnectionTypes< typename Traits::Arguments >::types(); } Q_DECLARE_METATYPE( QskMetaFunction ) diff --git a/src/common/QskMetaInvokable.h b/src/common/QskMetaInvokable.h index f6b7543d..c6636516 100644 --- a/src/common/QskMetaInvokable.h +++ b/src/common/QskMetaInvokable.h @@ -30,7 +30,7 @@ public: static QskMetaInvokable* instance( InvokeFunction, void** function ); protected: - explicit QskMetaInvokable( InvokeFunction f ): + explicit inline QskMetaInvokable( InvokeFunction f ): QSlotObjectBase( f ) { }