|
Safir SDK Core
|
This class provides a simple wrapper around dynamic loading functionality of the operating system. More...
#include <Safir/Utilities/DynamicLibraryLoader.h>
Public Member Functions | |
| DynamicLibraryLoader () | |
| Constructor. More... | |
| ~DynamicLibraryLoader () | |
| Destructor. More... | |
| void | Load (const std::string &libraryName, const bool unloadOnDestruction, const bool global=false) |
| Load a library. More... | |
| void | Unload () |
| Unload the library. More... | |
| template<class T > | |
| T * | GetFunction (const std::string &functionName) |
| Find a function in the library. More... | |
This class provides a simple wrapper around dynamic loading functionality of the operating system.
E.g. dlopen/dlsym of *nix and LoadLibrary/GetProcAddress of Win32.
| Safir::Utilities::DynamicLibraryLoader::DynamicLibraryLoader | ( | ) |
Constructor.
| Safir::Utilities::DynamicLibraryLoader::~DynamicLibraryLoader | ( | ) |
Destructor.
| T* Safir::Utilities::DynamicLibraryLoader::GetFunction | ( | const std::string & | functionName | ) |
Find a function in the library.
Attempt to load the specified function and return it as a function pointer with the specified signature. The return type is a raw function pointer rather than a boost::function object since otherwise things get very messy if you have to specify calling convention. But it easy to put the result into a boost function object. For example: boost::function<double(int,int)> func = lib.GetFunction<double(int,int)>("myfunc") And with specified calling convention on ms visual c++: boost::function<double(int,int)> func = lib.GetFunction<double __stdcall (int,int)>("myfunc") And with specified calling convention on gcc: boost::function<double(int,int)> func = lib.GetFunction<double __attribute__(stdcall) (int,int)>("myfunc")
| [in] | functionName | Name of the function to load |
| std::logic_error | If function cannot be found. |
| void Safir::Utilities::DynamicLibraryLoader::Load | ( | const std::string & | libraryName, |
| const bool | unloadOnDestruction, | ||
| const bool | global = false |
||
| ) |
Load a library.
Attempt to load the specified library dynamically.
| [in] | libraryName | The name of the library to load. On linux "lib" and ".so" are added to the beginning and end of the name, and on windows ".dll" is appended. |
| [in] | unloadOnDestruction | If this is true the library will be unloaded when the object is destroyed. This will invalidate any function pointers. |
| [in] | global | Use RTLD_GLOBAL flag when loading on *nix. |
| std::logic_error | If library cannot be found or cannot be not loaded. |
| void Safir::Utilities::DynamicLibraryLoader::Unload | ( | ) |
Unload the library.