wbc
PluginLoader.hpp
Go to the documentation of this file.
1#ifndef PLUGIN_LOADER_HPP
2#define PLUGIN_LOADER_HPP
3
4#include <string>
5#include <stdexcept>
6#include <map>
7#include <dlfcn.h>
8
9namespace wbc {
10
12public:
13 typedef std::map<std::string, void*> PluginMap;
14
15 static void loadPlugin(const std::string& name){
16 void *handle = dlopen(std::string(name).c_str(), RTLD_NOW);
17 if(!handle)
18 throw std::runtime_error("Failed to load plugin " + name);
19 getPluginMap()->insert(std::make_pair(name, handle));
20 }
21
22 static void unloadPlugin(const std::string& name){
23 PluginMap::iterator it = getPluginMap()->find(name);
24 if(it == getPluginMap()->end())
25 throw std::runtime_error("Failed to unload plugin " + name + ". Is the plugin loaded?");
26 dlclose(it->second);
27 plugin_map->erase(name);
28 }
29
31 if(!plugin_map)
32 plugin_map = new PluginMap;
33 return plugin_map;
34 }
35private:
36 static PluginMap* plugin_map;
37};
38
39}
40
41#endif
Definition PluginLoader.hpp:11
std::map< std::string, void * > PluginMap
Definition PluginLoader.hpp:13
static void loadPlugin(const std::string &name)
Definition PluginLoader.hpp:15
static void unloadPlugin(const std::string &name)
Definition PluginLoader.hpp:22
static PluginMap * getPluginMap()
Definition PluginLoader.hpp:30
Definition ContactsAccelerationConstraint.cpp:3