libcommonc++  0.7
PluginLoader.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_PluginLoader_hxx
24 #define __ccxx_PluginLoader_hxx
25 
27 
28 namespace ccxx {
29 
31 
39 {
40  public:
41 
48  PluginLoader(const String& path = String::null);
49 
51  ~PluginLoader();
52 
57  inline void setPath(const String& path)
58  { _module.setPath(path); }
59 
61  inline String getPath() const
62  { return(_module.getPath()); }
63 
71  void load()
72  { _module.open(); }
73 
78  inline void unload()
79  { _module.close(); }
80 
82  inline bool isLoaded() const
83  { return(_module.isOpen()); }
84 
92  String getName();
93 
101  String getVersion();
102 
110  String getAuthor();
111 
119  String getClassName();
120 
128  String getBuildDate();
129 
138  template<class T> T* newInstance()
139  {
140  Plugin *p = NULL;
141  try
142  {
143  p = _newInstance();
144  }
145  catch(...) { }
146 
147  if(! p)
148  return(NULL);
149 
150  T* plugin = NULL;
151  plugin = dynamic_cast<T *>(p);
152  if(! plugin)
153  delete p;
154 
155  return plugin;
156  }
157 
158  private:
159 
160  String _fetchString(const char* symbol);
161  Plugin* _newInstance();
162 
163  LoadableModule _module;
164 
166 };
167 
168 } // namespace ccxx
169 
170 #endif // __ccxx_PluginLoader_hxx
void load()
Load the plugin.
Definition: PluginLoader.h++:71
T * newInstance()
Construct a new instance of a plugin of type T, where T is a subclass of Plugin.
Definition: PluginLoader.h++:138
bool isLoaded() const
Determine if the plugin is loaded.
Definition: PluginLoader.h++:82
void setPath(const String &path)
Set the plugin file path.
Definition: PluginLoader.h++:57
A convenience class for loading Plugin objects.
Definition: PluginLoader.h++:38
A class representing a dynamically loaded plugin.
Definition: Plugin.h++:40
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
static const String null
The null string.
Definition: String.h++:1128
String getPath() const
Get the plugin file path.
Definition: PluginLoader.h++:61
Definition: AllocationMap.c++:25
An encapsulation of a dynamically loadable module, such as a shared library or object file on UNIX sy...
Definition: LoadableModule.h++:41
void unload()
Unload the plugin.
Definition: PluginLoader.h++:78