OpenWalnut
1.5.0dev
|
This class loads shared libraries and provides function pointers. More...
#include <WSharedLib.h>
Classes | |
struct | data |
Simple class holding an opened library. More... | |
Public Member Functions | |
WSharedLib (boost::filesystem::path lib) | |
Constructor. More... | |
WSharedLib (const WSharedLib &rhs) | |
Copies this instance by increasing the reference counter of the loaded library by 1. More... | |
virtual | ~WSharedLib () |
Destructor. More... | |
WSharedLib & | operator= (const WSharedLib &rhs) |
Copy assignment for shared libraries. More... | |
template<typename FuncType > | |
void | fetchFunction (const std::string &name, FuncType &func) const |
Search for a function in the shared library. More... | |
bool | existsFunction (const std::string &name) const |
Check whether the function exists. More... | |
template<typename PtrType > | |
void | fetchVariable (const std::string &name, PtrType &variable) const |
Search for an variable in the shared library. More... | |
std::string | getLibraryName () |
Returns the filename of the library without path. More... | |
Static Public Member Functions | |
static std::string | getSystemPrefix () |
Returns the prefix used for libraries on the system. More... | |
static std::string | getSystemSuffix () |
Returns the suffix for libraries used on the system. More... | |
static std::string | getSystemLibPath () |
Returns the default path for libraries on the current system. More... | |
Private Types | |
typedef void(* | func_ptr_type) (void) |
neutral function pointer type More... | |
Private Member Functions | |
func_ptr_type | findFunction (const std::string &name) const |
Find the specified function pointer in the library. More... | |
void * | findVariable (const std::string &name) const |
Find the specified symbol in the library. More... | |
Private Attributes | |
data * | m_data |
internal data More... | |
boost::filesystem::path | m_libPath |
path to lib More... | |
Friends | |
void | swap (WSharedLib &lhs, WSharedLib &rhs) |
Swap to shared libraries. More... | |
This class loads shared libraries and provides function pointers.
This is especially useful for dynamic loading of shared libraries during runtime. This works on Windows, Linux and Mac OS and is based on the openbug shared_lib implementation by Christian Heine heine. @inf ormat ik.u ni-le ipzi g.de
Definition at line 44 of file WSharedLib.h.
|
private |
neutral function pointer type
Definition at line 155 of file WSharedLib.h.
|
explicit |
Constructor.
Loads the specified library.
lib | the library to load. Can be a DLL,SO or DYLIB (depending on system). This can be an absolut or relative path. Otherwise standard library search directory may be searched. |
WLibraryLoadFailed | if the lib could not be loaded. Maybe because of file not found or link errors. |
Definition at line 267 of file WSharedLib.cpp.
WSharedLib::WSharedLib | ( | const WSharedLib & | rhs | ) |
Copies this instance by increasing the reference counter of the loaded library by 1.
rhs | the other Lib. |
Definition at line 273 of file WSharedLib.cpp.
|
virtual |
Destructor.
Decreases the reference counter and unloads the library if the reference count drops to zero.
Definition at line 279 of file WSharedLib.cpp.
References m_data.
bool WSharedLib::existsFunction | ( | const std::string & | name | ) | const |
Check whether the function exists.
name | the name of the function |
Definition at line 306 of file WSharedLib.cpp.
References WSharedLib::data::existsFunction(), and m_data.
void WSharedLib::fetchFunction | ( | const std::string & | name, |
FuncType & | func | ||
) | const |
Search for a function in the shared library.
FuncType | a function type |
name | the name of the function |
func | will be set to the function pointer |
WLibraryFetchFailed | if the symbol was not found |
Definition at line 186 of file WSharedLib.h.
References findFunction().
void WSharedLib::fetchVariable | ( | const std::string & | name, |
PtrType & | variable | ||
) | const |
Search for an variable in the shared library.
PtrType | a pointer type |
name | the name of the variable |
variable | will be set to the variable pointer |
WLibraryFetchFailed | if the symbol was not found |
Definition at line 192 of file WSharedLib.h.
References findVariable().
|
private |
Find the specified function pointer in the library.
name | the symbol to search |
Definition at line 296 of file WSharedLib.cpp.
References WSharedLib::data::findFunction(), and m_data.
Referenced by fetchFunction().
|
private |
Find the specified symbol in the library.
name | the symbol to search |
Definition at line 301 of file WSharedLib.cpp.
References WSharedLib::data::findVariable(), and m_data.
Referenced by fetchVariable().
std::string WSharedLib::getLibraryName | ( | ) |
Returns the filename of the library without path.
Definition at line 326 of file WSharedLib.cpp.
References m_libPath.
|
static |
Returns the default path for libraries on the current system.
This is the directory where to search for .so,.dll or .dylib files. On Unix, this will be "../lib", on Windows ".".
Definition at line 321 of file WSharedLib.cpp.
|
static |
Returns the prefix used for libraries on the system.
On Unix this mostly is "lib".
Definition at line 311 of file WSharedLib.cpp.
Referenced by WModuleLoader::getModulePrefix().
|
static |
Returns the suffix for libraries used on the system.
On Unix this mostly is "so", Windows uses "dll" and Mac something like "dylib".
Definition at line 316 of file WSharedLib.cpp.
Referenced by WModuleLoader::load().
WSharedLib & WSharedLib::operator= | ( | const WSharedLib & | rhs | ) |
Copy assignment for shared libraries.
rhs | the one to assign |
Definition at line 284 of file WSharedLib.cpp.
References swap.
|
friend |
Swap to shared libraries.
lhs | the one |
rhs | the other |
Definition at line 291 of file WSharedLib.cpp.
Referenced by operator=().
|
private |
internal data
Definition at line 179 of file WSharedLib.h.
Referenced by existsFunction(), findFunction(), findVariable(), and ~WSharedLib().
|
private |