wbc
PluginLoader.hpp
Go to the documentation of this file.
1#ifndef WBC_CORE_PLUGIN_LOADER_HPP
2#define WBC_CORE_PLUGIN_LOADER_HPP
3
4#include <string>
5#include <stdexcept>
6#include <map>
7#include <dlfcn.h>
8
9namespace wbc {
10
15public:
16 typedef std::map<std::string, void*> PluginMap;
17
18 static bool loadPlugin(const std::string& name){
19 void *handle = dlopen(std::string(name).c_str(), RTLD_NOW);
20 if(!handle)
21 return false;
22 getPluginMap()->insert(std::make_pair(name, handle));
23 return true;
24 }
25
26 static bool unloadPlugin(const std::string& name){
27 PluginMap::iterator it = getPluginMap()->find(name);
28 if(it == getPluginMap()->end())
29 return false;
30 dlclose(it->second);
31 plugin_map->erase(name);
32 return true;
33 }
34
36 if(!plugin_map)
37 plugin_map = new PluginMap;
38 return plugin_map;
39 }
40private:
41 static PluginMap* plugin_map;
42};
43
44}
45
46#endif // WBC_CORE_PLUGIN_LOADER_HPP
Helper class to load the robot model, solver and scene plugins.
Definition PluginLoader.hpp:14
static bool loadPlugin(const std::string &name)
Definition PluginLoader.hpp:18
static bool unloadPlugin(const std::string &name)
Definition PluginLoader.hpp:26
std::map< std::string, void * > PluginMap
Definition PluginLoader.hpp:16
static PluginMap * getPluginMap()
Definition PluginLoader.hpp:35
Definition ContactsAccelerationConstraint.cpp:3