PluginInterface.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #ifndef _GG_PluginInterface_h_
00031 #define _GG_PluginInterface_h_
00032
00033 #include <GG/GUI.h>
00034
00035 #if defined(__APPLE__) && defined(__MACH__)
00036 # include "../libltdl/ltdl.h"
00037 #else
00038 # include <GG/ltdl.h>
00039 #endif
00040
00041 #include <string>
00042
00043
00044 namespace boost { namespace archive {
00045 class xml_oarchive;
00046 class xml_iarchive;
00047 } }
00048
00049 namespace GG {
00050
00067 class GG_API PluginInterface
00068 {
00069 private:
00070 struct ConvertibleToBoolDummy {int _;};
00071
00072 public:
00074 typedef const char* (*PluginNameFn)();
00077 typedef const char* (*DefaultFontNameFn)();
00079 typedef unsigned int (*DefaultFontSizeFn)();
00081 typedef boost::shared_ptr<StyleFactory> (*GetStyleFactoryFn)();
00082
00084 typedef GUI::SaveWndFn SaveWndFn;
00086 typedef GUI::LoadWndFn LoadWndFn;
00087
00089 PluginInterface();
00090
00094 PluginInterface(const std::string& lib_name);
00095
00096 ~PluginInterface();
00097
00098
00100
00105 operator int ConvertibleToBoolDummy::* () const;
00107
00109
00111 bool Load(const std::string& lib_name);
00112
00113 PluginNameFn PluginName;
00114 DefaultFontNameFn DefaultFontName;
00115 DefaultFontSizeFn DefaultFontSize;
00116 GetStyleFactoryFn GetStyleFactory;
00117 SaveWndFn SaveWnd;
00118 LoadWndFn LoadWnd;
00119
00124 template <class T>
00125 void LoadWndT(T*& wnd, const std::string& name, boost::archive::xml_iarchive& ar);
00127
00128 private:
00129 lt_dlhandle m_handle;
00130 boost::archive::xml_oarchive* m_out_archive;
00131 boost::archive::xml_iarchive* m_in_archive;
00132 };
00133
00140 class GG_API PluginManager
00141 {
00142 public:
00144
00147 boost::shared_ptr<PluginInterface> GetPlugin(const std::string& name);
00148
00152 void FreePlugin(const std::string& name);
00154
00158 static void InitDynamicLoader();
00159
00161 static void AddSearchDirectory(const std::string& dir);
00162
00166 static void CleanupDynamicLoader();
00167
00168 private:
00169 PluginManager();
00170
00171 std::map<std::string, boost::shared_ptr<PluginInterface> > m_plugins;
00172
00173 static bool s_lt_dl_initialized;
00174
00175 friend GG_API PluginManager& GetPluginManager();
00176 };
00177
00179 GG_API PluginManager& GetPluginManager();
00180
00181
00182 template <class T>
00183 void PluginInterface::LoadWndT(T*& wnd, const std::string& name, boost::archive::xml_iarchive& ar)
00184 {
00185 Wnd* wnd_as_base = wnd;
00186 LoadWnd(wnd_as_base, name, ar);
00187 wnd = dynamic_cast<T*>(wnd_as_base);
00188 assert(wnd);
00189 }
00190
00191 }
00192
00193 #endif // _GG_PluginInterface_h_