From 8b2f133822a22379cbbaa33fe600c30b95dc0044 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 5 Jan 2016 01:06:50 +0100 Subject: QFactoryLoader: generalize qLoadPlugin() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use perfect forwarding for the additional argument. - Provide a variadic template version - Deprecate qLoadPlugin1() — there's no reason for a different name — and fix all callers in qtbase. - Provide non-variadic overloads for up to three additional args (QPlatformIntegration rolled its own function because it needs three args). Change-Id: I72fb2dd9a021de704cbf5e4b6ea31c80447fb3b1 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/corelib/plugin/qfactoryloader_p.h | 61 ++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h index ee07084180..a4690c3f03 100644 --- a/src/corelib/plugin/qfactoryloader_p.h +++ b/src/corelib/plugin/qfactoryloader_p.h @@ -85,6 +85,23 @@ public: QObject *instance(int index) const; }; +#ifdef Q_COMPILER_VARIADIC_TEMPLATES + +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(args)...)) + return result; + } + return nullptr; +} + +#else + template PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key) { @@ -98,21 +115,57 @@ template return 0; } -template -PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, - const Parameter1 ¶meter1) + P1 &&p1) { const int index = loader->indexOf(key); if (index != -1) { QObject *factoryObject = loader->instance(index); if (FactoryInterface *factory = qobject_cast(factoryObject)) - if (PluginInterface *result = factory->create(key, parameter1)) + if (PluginInterface *result = factory->create(key, std::forward(p1))) return result; } return 0; } +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, + const QString &key, + P1 &&p1, P2 &&p2) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(p1), std::forward(p2))) + return result; + } + return 0; +} + +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, + const QString &key, + P1 &&p1, P2 &&p2, P3 &&p3) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(p1), std::forward(p2), std::forward(p3))) + return result; + } + return 0; +} + +#endif + +template +Q_DECL_DEPRECATED PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg) +{ return qLoadPlugin(loader, key, std::forward(arg)); } + QT_END_NAMESPACE #endif // QT_NO_QOBJECT -- cgit v1.2.3