diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-10-14 10:50:45 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-10-14 10:41:19 +0000 |
commit | d21bf21aed0c346b5666725ba52c4424c360c028 (patch) | |
tree | eac8037b70a2edd9f7c98fb54d4f8fad951f7ff1 | |
parent | 46befdc26215c232047673e895245054f6a3079e (diff) |
Use std::function for onEntry and onExit return types
This allows us to drop the C++14 requirement. As onEntry and onExit are
template functions we don't need to care about (not) using the standard
library for them.
Change-Id: Ie776e04f7e1771914c9f48d2440ef445d87d64c0
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
-rw-r--r-- | examples/scxml/ftpclient/ftpclient.pro | 1 | ||||
-rw-r--r-- | examples/scxml/ftpclient/main.cpp | 6 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachine.cpp | 29 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachine.h | 36 | ||||
-rw-r--r-- | tests/auto/compiled/compiled.pro | 2 | ||||
-rw-r--r-- | tests/auto/compiled/tst_compiled.cpp | 3 | ||||
-rw-r--r-- | tests/auto/statemachine/statemachine.pro | 2 | ||||
-rw-r--r-- | tests/auto/statemachine/tst_statemachine.cpp | 3 |
8 files changed, 27 insertions, 55 deletions
diff --git a/examples/scxml/ftpclient/ftpclient.pro b/examples/scxml/ftpclient/ftpclient.pro index 7aa266e..3ba8adf 100644 --- a/examples/scxml/ftpclient/ftpclient.pro +++ b/examples/scxml/ftpclient/ftpclient.pro @@ -1,6 +1,5 @@ QT = core scxml -CONFIG += c++14 TARGET = ftpclient TEMPLATE = app diff --git a/examples/scxml/ftpclient/main.cpp b/examples/scxml/ftpclient/main.cpp index 3a99bd4..25102d2 100644 --- a/examples/scxml/ftpclient/main.cpp +++ b/examples/scxml/ftpclient/main.cpp @@ -62,7 +62,6 @@ struct Command { int main(int argc, char *argv[]) { -#if defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 if (argc != 3) { qDebug() << "Usage: ftpclient <server> <file>"; return 1; @@ -127,9 +126,4 @@ int main(int argc, char *argv[]) }); return app.exec(); -#else - qDebug() << "The ftpclient example uses the C++14 return type deduction feature and will only " - "work with compilers that support it."; - return 2; -#endif } diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index e6137e0..8cb94ad 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -178,8 +178,8 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") */ /*! - \fn auto QScxmlStateMachine::onEntry(const QObject *receiver, - const char *method) + \fn QScxmlStateMachine::onEntry(const QObject *receiver, + const char *method) Returns a functor that accepts a boolean argument and calls the given \a method on \a receiver using QMetaObject::invokeMethod() if that argument @@ -190,14 +190,10 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is entered. - - onEntry() is only available if the compiler supports return type - deduction for functions. -*/ + */ /*! - \fn auto QScxmlStateMachine::onExit(const QObject *receiver, - const char *method) + \fn QScxmlStateMachine::onExit(const QObject *receiver, const char *method) Returns a functor that accepts a boolean argument and calls the given \a method on \a receiver using QMetaObject::invokeMethod() if that argument @@ -208,10 +204,7 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is left. - - onExit() is only available if the compiler supports return type - deduction for functions. -*/ + */ /*! \fn QScxmlStateMachine::onEntry(Functor functor) @@ -222,9 +215,6 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is entered. - - onEntry() is only available if the compiler supports return type - deduction for functions. */ /*! @@ -236,9 +226,6 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is left. - - onExit() is only available if the compiler supports return type - deduction for functions. */ /*! @@ -252,9 +239,6 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is entered. - - onEntry() is only available if the compiler supports return type - deduction for functions. */ /*! @@ -268,9 +252,6 @@ Q_LOGGING_CATEGORY(scxmlLog, "scxml.statemachine") This is useful to wrap handlers for connectToState() that should only be executed when the state is left. - - onExit() is only available if the compiler supports return type - deduction for functions. */ namespace QScxmlInternal { diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h index 4f813e4..16bd3d0 100644 --- a/src/scxml/qscxmlstatemachine.h +++ b/src/scxml/qscxmlstatemachine.h @@ -52,6 +52,8 @@ #include <QVariantList> #include <QPointer> +#include <functional> + QT_BEGIN_NAMESPACE class QIODevice; class QXmlStreamWriter; @@ -170,22 +172,24 @@ public: #endif #ifdef Q_QDOC - static auto onEntry(const QObject *receiver, const char *method); - static auto onExit(const QObject *receiver, const char *method); + static std::function<void(bool)> onEntry(const QObject *receiver, const char *method); + static std::function<void(bool)> onExit(const QObject *receiver, const char *method); template<typename Functor> - static auto onEntry(Functor functor); + static std::function<void(bool)> onEntry(Functor functor); template<typename Functor> - static auto onExit(Functor functor); + static std::function<void(bool)> onExit(Functor functor); template<typename PointerToMemberFunction> - static auto onEntry(const QObject *receiver, PointerToMemberFunction method); + static std::function<void(bool)> onEntry(const QObject *receiver, + PointerToMemberFunction method); template<typename PointerToMemberFunction> - static auto onExit(const QObject *receiver, PointerToMemberFunction method); -#elif defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 - static auto onEntry(const QObject *receiver, const char *method) + static std::function<void(bool)> onExit(const QObject *receiver, + PointerToMemberFunction method); +#else + static std::function<void(bool)> onEntry(const QObject *receiver, const char *method) { const QPointer<QObject> receiverPointer(const_cast<QObject *>(receiver)); return [receiverPointer, method](bool isEnteringState) { @@ -194,7 +198,7 @@ public: }; } - static auto onExit(const QObject *receiver, const char *method) + static std::function<void(bool)> onExit(const QObject *receiver, const char *method) { const QPointer<QObject> receiverPointer(const_cast<QObject *>(receiver)); return [receiverPointer, method](bool isEnteringState) { @@ -204,7 +208,7 @@ public: } template<typename Functor> - static auto onEntry(Functor functor) + static std::function<void(bool)> onEntry(Functor functor) { return [functor](bool isEnteringState) { if (isEnteringState) @@ -213,7 +217,7 @@ public: } template<typename Functor> - static auto onExit(Functor functor) + static std::function<void(bool)> onExit(Functor functor) { return [functor](bool isEnteringState) { if (!isEnteringState) @@ -222,8 +226,8 @@ public: } template<typename Func1> - static auto onEntry(const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, - Func1 slot) + static std::function<void(bool)> onEntry( + const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, Func1 slot) { typedef typename QtPrivate::FunctionPointer<Func1>::Object Object; const QPointer<Object> receiverPointer(const_cast<Object *>(receiver)); @@ -234,8 +238,8 @@ public: } template<typename Func1> - static auto onExit(const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, - Func1 slot) + static std::function<void(bool)> onExit( + const typename QtPrivate::FunctionPointer<Func1>::Object *receiver, Func1 slot) { typedef typename QtPrivate::FunctionPointer<Func1>::Object Object; const QPointer<Object> receiverPointer(const_cast<Object *>(receiver)); @@ -244,7 +248,7 @@ public: (receiverPointer->*slot)(); }; } -#endif // defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 +#endif // !Q_QDOC QMetaObject::Connection connectToEvent(const QString &scxmlEventSpec, const QObject *receiver, const char *method, diff --git a/tests/auto/compiled/compiled.pro b/tests/auto/compiled/compiled.pro index c13cbf4..713f484 100644 --- a/tests/auto/compiled/compiled.pro +++ b/tests/auto/compiled/compiled.pro @@ -1,5 +1,5 @@ QT = core gui qml testlib scxml -CONFIG += testcase c++14 +CONFIG += testcase TARGET = tst_compiled CONFIG += console diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp index 27e4a80..6ee181d 100644 --- a/tests/auto/compiled/tst_compiled.cpp +++ b/tests/auto/compiled/tst_compiled.cpp @@ -168,15 +168,12 @@ void tst_Compiled::connection() QMetaObject::Connection conB = stateMachine.connectToState("b", &receiverB, SLOT(receive(bool))); QMetaObject::Connection conFinal = stateMachine.connectToState("final", &receiverFinal, SLOT(receive(bool))); -#if defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 - // C++14 available: test for onEntry and onExit typedef QScxmlStateMachine QXSM; QMetaObject::Connection aEntry = stateMachine.connectToState("a", QXSM::onEntry(&receiverA, "enter")); QMetaObject::Connection aExit = stateMachine.connectToState("a", QXSM::onExit(&receiverA, "exit")); QVERIFY(aEntry); QVERIFY(aExit); -#endif QVERIFY(conA); QVERIFY(conA1); diff --git a/tests/auto/statemachine/statemachine.pro b/tests/auto/statemachine/statemachine.pro index 95bf9a8..0e4de1a 100644 --- a/tests/auto/statemachine/statemachine.pro +++ b/tests/auto/statemachine/statemachine.pro @@ -1,5 +1,5 @@ QT = core gui qml testlib scxml-private -CONFIG += testcase c++14 +CONFIG += testcase TARGET = tst_statemachine CONFIG += console diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp index 1cf0518..9c757e7 100644 --- a/tests/auto/statemachine/tst_statemachine.cpp +++ b/tests/auto/statemachine/tst_statemachine.cpp @@ -183,8 +183,6 @@ void tst_StateMachine::connections() }); QVERIFY(final); -#if defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 - // C++14 available, test onEntry and onExit bool a1Entered = false; bool a1Exited = false; bool finalEntered = false; @@ -219,7 +217,6 @@ void tst_StateMachine::connections() finalExited = true; })); QVERIFY(finalExit); -#endif stateMachine->start(); |