libkdepim
pluginloader.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __KPIM_SHARED_PLUGINLOADER_H__
00023 #define __KPIM_SHARED_PLUGINLOADER_H__
00024
00025 #include <pluginloaderbase.h>
00026
00027 namespace KPIM {
00028
00078 template< typename T, typename T_config >
00079 class KDE_EXPORT PluginLoader : public PluginLoaderBase {
00080 protected:
00081 PluginLoader() : PluginLoaderBase() {}
00082
00083 private:
00084 static PluginLoader<T,T_config> * mSelf;
00085
00086 public:
00087 virtual ~PluginLoader() { mSelf = 0; }
00088
00090 static PluginLoader<T,T_config> * instance() {
00091 if ( !mSelf ) {
00092 mSelf = new PluginLoader<T,T_config>();
00093 mSelf->scan();
00094 }
00095 return mSelf;
00096 }
00097
00101 virtual void scan() {
00102 doScan( T_config::path );
00103 }
00104
00108 virtual T * createForName( const QString & type ) const {
00109 void * main_func = mainFunc( type, T_config::mainfunc );
00110 if ( !main_func ) return 0;
00111
00112
00113
00114 return ((T* (*)())( main_func ))();
00115 }
00116 };
00117
00118 template< typename T, typename T_config >
00119 PluginLoader<T,T_config> * PluginLoader<T,T_config>::mSelf = 0;
00120
00121 }
00122
00123 #define KPIM_DEFINE_PLUGIN_LOADER( pl, t, mf, p ) \
00124 namespace { \
00125 struct KDE_EXPORT pl##Config { \
00126 static const char * const mainfunc; \
00127 static const char * const path; \
00128 }; \
00129 const char * const pl##Config::mainfunc = mf; \
00130 const char * const pl##Config::path = p; \
00131 } \
00132 typedef KPIM::PluginLoader< t, pl##Config > pl; \
00133
00134
00135 #endif // __KPIM_SHARED_PLUGINLOADER_H__
|