2
This file is part of the Grantlee template system.
4
Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2 of the Licence, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#ifndef GRANTLEE_PLUGINPOINTER_H
22
#define GRANTLEE_PLUGINPOINTER_H
24
#include <QtCore/QSharedPointer>
25
#include <QtCore/QPluginLoader>
30
void _deleter( QPluginLoader *loader )
37
@brief A smart pointer for handling plugins.
39
@author Stephen Kelly <steveire@gmail.com>
41
template <typename PluginType>
52
// This allows returning 0 from a function returning a PluginType*
53
PluginPointer( _Dummy* )
59
PluginPointer( const QString &fileName )
60
: m_object( 0 ), m_plugin( 0 )
62
m_pluginLoader = QSharedPointer<QPluginLoader>( new QPluginLoader( fileName ), _deleter );
64
m_object = m_pluginLoader->instance();
68
m_plugin = qobject_cast<PluginType*>( m_object );
71
QString errorString() {
72
return m_pluginLoader->errorString();
79
PluginType* operator->() {
84
return m_plugin ? true : false;
87
PluginType* data() const {
94
QSharedPointer<QPluginLoader> m_pluginLoader;