OpenWalnut 1.3.1
|
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. | |
WSharedLib (const WSharedLib &rhs) | |
Copies this instance by increasing the reference counter of the loaded library by 1. | |
virtual | ~WSharedLib () |
Destructor. | |
WSharedLib & | operator= (const WSharedLib &rhs) |
Copy assignment for shared libraries. | |
template<typename FuncType > | |
void | fetchFunction (const std::string &name, FuncType &func) const |
Search for a function in the shared library. | |
template<typename PtrType > | |
void | fetchVariable (const std::string &name, PtrType &variable) const |
Search for an variable in the shared library. | |
Static Public Member Functions | |
static std::string | getSystemPrefix () |
Returns the prefix used for libraries on the system. | |
static std::string | getSystemSuffix () |
Returns the suffix for libraries used on the system. | |
static std::string | getSystemLibPath () |
Returns the default path for libraries on the current system. | |
Private Types | |
typedef void(* | func_ptr_type )(void) |
neutral function pointer type | |
Private Member Functions | |
func_ptr_type | findFunction (const std::string &name) const |
Find the specified function pointer in the library. | |
void * | findVariable (const std::string &name) const |
Find the specified symbol in the library. | |
Private Attributes | |
data * | m_data |
internal data | |
Friends | |
void | swap (WSharedLib &lhs, WSharedLib &rhs) |
Swap to shared libraries. |
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@informatik.uni-leipzig.de>. For more details, see http://www.informatik.uni-leipzig.de/~hg/openbug .
Definition at line 44 of file WSharedLib.h.
typedef void(* WSharedLib::func_ptr_type)(void) [private] |
neutral function pointer type
Definition at line 139 of file WSharedLib.h.
WSharedLib::WSharedLib | ( | boost::filesystem::path | lib | ) | [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 241 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 246 of file WSharedLib.cpp.
WSharedLib::~WSharedLib | ( | ) | [virtual] |
Destructor.
Decreases the reference counter and unloads the library if the reference count drops to zero.
Definition at line 251 of file WSharedLib.cpp.
References 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 167 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 173 of file WSharedLib.h.
References findVariable().
WSharedLib::func_ptr_type WSharedLib::findFunction | ( | const std::string & | name | ) | const [private] |
Find the specified function pointer in the library.
name | the symbol to search |
Definition at line 268 of file WSharedLib.cpp.
References WSharedLib::data::findFunction(), and m_data.
Referenced by fetchFunction().
void * WSharedLib::findVariable | ( | const std::string & | name | ) | const [private] |
Find the specified symbol in the library.
name | the symbol to search |
Definition at line 273 of file WSharedLib.cpp.
References WSharedLib::data::findVariable(), and m_data.
Referenced by fetchVariable().
std::string WSharedLib::getSystemLibPath | ( | ) | [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 288 of file WSharedLib.cpp.
std::string WSharedLib::getSystemPrefix | ( | ) | [static] |
Returns the prefix used for libraries on the system.
On Unix this mostly is "lib".
Definition at line 278 of file WSharedLib.cpp.
Referenced by WModuleLoader::getModulePrefix().
std::string WSharedLib::getSystemSuffix | ( | ) | [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 283 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 256 of file WSharedLib.cpp.
References swap.
void swap | ( | WSharedLib & | lhs, |
WSharedLib & | rhs | ||
) | [friend] |
Swap to shared libraries.
lhs | the one |
rhs | the other |
Definition at line 263 of file WSharedLib.cpp.
Referenced by operator=().
data* WSharedLib::m_data [private] |
internal data
Definition at line 160 of file WSharedLib.h.
Referenced by findFunction(), findVariable(), and ~WSharedLib().