GG: PluginInterface.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

PluginInterface.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3 Copyright (C) 2003-2008 T. Zachary Laine
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1
8 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA
19
20 If you do not wish to comply with the terms of the LGPL please
21 contact the author as other terms are available for a fee.
22
23 Zach Laine
24 whatwasthataddress@gmail.com */
25
30 #ifndef _GG_PluginInterface_h_
31 #define _GG_PluginInterface_h_
32
33 #include <GG/GUI.h>
34
35 #if defined(__APPLE__) && defined(__MACH__)
36 # include "../libltdl/ltdl.h"
37 #else
38 # include <GG/ltdl.h>
39 #endif
40
41 #include <string>
42
43
44 namespace GG {
45
58 class GG_API PluginInterface
59 {
60 private:
61 struct ConvertibleToBoolDummy {int _;};
62
63 public:
65 typedef const char* (*PluginNameFn)();
68 typedef const char* (*DefaultFontNameFn)();
70 typedef unsigned int (*DefaultFontSizeFn)();
72 typedef boost::shared_ptr<StyleFactory> (*GetStyleFactoryFn)();
73
75 PluginInterface();
76
80 PluginInterface(const std::string& lib_name);
81
82 ~PluginInterface();
83
84
86
91 operator int ConvertibleToBoolDummy::* () const;
93
95
97 bool Load(const std::string& lib_name);
98
99 PluginNameFn PluginName;
100 DefaultFontNameFn DefaultFontName;
101 DefaultFontSizeFn DefaultFontSize;
102 GetStyleFactoryFn GetStyleFactory;
103
104
105 private:
106 lt_dlhandle m_handle;
107 boost::archive::xml_oarchive* m_out_archive;
108 boost::archive::xml_iarchive* m_in_archive;
109 };
110
117 class GG_API PluginManager
118 {
119 public:
121
124 boost::shared_ptr<PluginInterface> GetPlugin(const std::string& name);
125
129 void FreePlugin(const std::string& name);
131
135 static void InitDynamicLoader();
136
138 static void AddSearchDirectory(const std::string& dir);
139
143 static void CleanupDynamicLoader();
144
145 private:
146 PluginManager();
147
148 std::map<std::string, boost::shared_ptr<PluginInterface> > m_plugins;
149
150 static bool s_lt_dl_initialized;
151
152 friend GG_API PluginManager& GetPluginManager();
153 };
154
156 GG_API PluginManager& GetPluginManager();
157
158 } // namespace GG
159
160 #endif