Message info
 
To:kde-commits@kde.org From:Bernhard Beschow Subject:[marble] src/lib: const\'ify plugin templates Date:Sun, 18 Mar 2012 16:09:09 +0100 (CET)
 

Git commit fee747330a6ee05b145f40406e545857f62c1e17 by Bernhard Beschow.
Committed on 18/03/2012 at 14:26.
Pushed by beschow into branch 'master'.

const'ify plugin templates

M +31 -12 src/lib/PluginManager.cpp

http://commits.kde.org/marble/fee747330a6ee05b145f40406e545857f62c1e17

diff --git a/src/lib/PluginManager.cpp b/src/lib/PluginManager.cpp
index b3a6a7f..730dce6 100644
--- a/src/lib/PluginManager.cpp
+++ b/src/lib/PluginManager.cpp
@@ -43,9 +43,9 @@ class PluginManagerPrivate
void loadPlugins();

bool m_pluginsLoaded;
- QList<RenderPlugin *> m_renderPluginTemplates;
- QList<NetworkPlugin *> m_networkPluginTemplates;
- QList<PositionProviderPlugin *> m_positionProviderPluginTemplates;
+ QList<const RenderPlugin *> m_renderPluginTemplates;
+ QList<const NetworkPlugin *> m_networkPluginTemplates;
+ QList<const PositionProviderPlugin *> m_positionProviderPluginTemplates;
QList<RunnerPlugin *> m_runnerPlugins;
};

@@ -65,33 +65,35 @@ PluginManager::~PluginManager()
}

template<class T>
-QList<T*> createPlugins( PluginManagerPrivate* d, const QList<T*> &loaders )
+QList<T*> createPlugins( const QList<const T*> &factories )
{
QList<T*> result;
- d->loadPlugins();
- typename QList<T*>::const_iterator i = loaders.constBegin();
- typename QList<T*>::const_iterator const end = loaders.constEnd();
- for (; i != end; ++i) {
- T* instance = (*i)->newInstance();
+
+ foreach ( const T *factory, factories ) {
+ T *instance = factory->newInstance();
Q_ASSERT( instance && "Plugin returned null when requesting a new instance." );
result.append( instance );
}
+
return result;
}

QList<RenderPlugin *> PluginManager::createRenderPlugins() const
{
- return createPlugins( d, d->m_renderPluginTemplates );
+ d->loadPlugins();
+ return createPlugins( d->m_renderPluginTemplates );
}

QList<NetworkPlugin *> PluginManager::createNetworkPlugins() const
{
- return createPlugins( d, d->m_networkPluginTemplates );
+ d->loadPlugins();
+ return createPlugins( d->m_networkPluginTemplates );
}

QList<PositionProviderPlugin *> PluginManager::createPositionProviderPlugins() const
{
- return createPlugins( d, d->m_positionProviderPluginTemplates );
+ d->loadPlugins();
+ return createPlugins( d->m_positionProviderPluginTemplates );
}

QList<RunnerPlugin *> PluginManager::runnerPlugins() const
@@ -117,6 +119,23 @@ bool appendPlugin( QObject * obj, QPluginLoader* &loader, QList<T*> &plugins )
return false;
}

+/** Append obj to the given plugins list if it inherits both T and U */
+template<class T, class U>
+bool appendPlugin( QObject * obj, QPluginLoader* &loader, QList<const T*> &plugins )
+{
+ if ( qobject_cast<T*>( obj ) && qobject_cast<U*>( obj ) ) {
+ Q_ASSERT( obj->metaObject()->superClass() ); // all our plugins have a super class
+ mDebug() << obj->metaObject()->superClass()->className()
+ << "plugin loaded from" << loader->fileName();
+ T* plugin = qobject_cast<T*>( obj );
+ Q_ASSERT( plugin ); // checked above
+ plugins << plugin;
+ return true;
+ }
+
+ return false;
+}
+
void PluginManagerPrivate::loadPlugins()
{
if (m_pluginsLoaded)