charon-core  0.3.1
AbstractPluginLoader.cpp
Go to the documentation of this file.
1 /* This file is part of Charon.
2 
3  Charon is free software: you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Charon is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public License
14  along with Charon. If not, see <http://www.gnu.org/licenses/>.
15  */
23 
25  std::vector<std::string>& plpaths,
26  std::string& lSuffix,
28  pluginName(StringTool::toLowerCase(n)),
29  create(NULL),
30  destroy(NULL),
31  pluginPaths(plpaths),
32  libSuffix(lSuffix),
33  _versionCheck(versionCheck)
34 {
35 }
36 
37 const std::string& AbstractPluginLoader::getName() const {
38  return pluginName;
39 }
40 
42  const std::string & name, ParameteredObject::template_type t)
43  throw (PluginException)
44 {
45  if (create) {
46  return create(name, t);
47  } else {
48  throw PluginException("Plugin \"" + pluginName + "\" is not loaded.",
49  pluginName, PluginException::PLUGIN_NOT_LOADED);
50  }
51 }
52 
54  throw (PluginException) {
55 
56  if (destroy) {
57  destroy(toDestroy);
58  } else {
59  throw PluginException("Plugin \"" + pluginName + "\" is not loaded.",
60  pluginName, PluginException::PLUGIN_NOT_LOADED);
61  }
62 }
63 
65 }
66 
68  const std::string & pl, ErrorCode e) :
69  runtime_error(n), _nameOfPlugin(pl), _err(e) {
70 }
71 
73  return _nameOfPlugin;
74 }
75 
78  return _err;
79 }
80 
82 }
virtual ParameteredObject * createInstance(const std::string &name, ParameteredObject::template_type t=ParameteredObject::TYPE_DOUBLE)
Creates an instance of the loaded plugin and returns a pointer to it.
forstatement_DECLDIR void destroy(ParameteredObject *b)
Deletes an instance of the plugin.
virtual ~AbstractPluginLoader()
Default Destructor.
const std::string & getPluginName() const
Get Plugin Name.
template_type
Integer which represents a template type.
Base class for serializable objects.
ErrorCode getErrorCode() const
Plugin Exception Error Code.
Declares an abstract base class for a plugin loader.
forstatement_DECLDIR ParameteredObject * create(const std::string &name, ParameteredObject::template_type)
Creates an instance of the plugin.
virtual void destroyInstance(ParameteredObject *p)
Deletes an instance of the loaded plugin.
std::string pluginName
The name of the Plugin (without prefix "lib" and without extension)
virtual const std::string & getName() const
Get the name of the plugin.
AbstractPluginLoader(const std::string &name, std::vector< std::string > &plpaths, std::string &lSuffix, PluginManagerInterface::PluginVersionCheckLevel versionCheck=PluginManagerInterface::PluginVersionIgnore)
Default constructor.
PluginVersionCheckLevel
info how to handle version information
std::string charon_core_DLL_PUBLIC toLowerCase(std::string s)
Convert a string to lowercase.
Definition: StringTool.cpp:55
PluginException(const std::string &message, const std::string &pluginName="", ErrorCode err=OTHER)
Constructor.