PLaSK library
|
Hold opened shared library. More...
#include <plask/utils/dynlib/loader.hpp>
Public Types | |
enum | Flags { DONT_CLOSE = 1 } |
typedef void * | handle_t |
Public Member Functions | |
handle_t | getHandle () const |
Get system handler to the loaded library. | |
DynamicLibrary (const std::string &filename, unsigned flags) | |
Open library from file with given name filename . | |
DynamicLibrary () | |
Don't open any library. | |
DynamicLibrary (const DynamicLibrary &)=delete | |
Coping of library is not allowed. | |
DynamicLibrary & | operator= (const DynamicLibrary &)=delete |
Coping of library is not allowed. | |
DynamicLibrary (DynamicLibrary &&to_move) noexcept | |
Move library ownership from to_move to this. | |
DynamicLibrary & | operator= (DynamicLibrary &&to_move) noexcept |
Move library ownership from to_move to this. | |
void | swap (DynamicLibrary &to_swap) noexcept |
Swap library ownerships between this and to_swap. | |
~DynamicLibrary () | |
Dispose library. | |
void | open (const std::string &filename, unsigned flags) |
Open library from file with given name filename . | |
void | close () |
Close opened library. | |
void * | getSymbol (const std::string &symbol_name) const |
Get symbol from library. | |
template<typename SymbolType > | |
SymbolType | getSymbol (const std::string &symbol_name) const |
Get symbol from library and cast it to given type. | |
void * | operator[] (const std::string &symbol_name) const |
Same as getSymbol(const std::string &symbol_name) | |
void * | requireSymbol (const std::string &symbol_name) const |
Get symbol from library. | |
template<typename SymbolType > | |
SymbolType | requireSymbol (const std::string &symbol_name) const |
Get symbol from library and cast it to given type. | |
bool | isOpen () const |
Check if library is already open. | |
handle_t | getSystemHandler () const |
Get system handle. | |
handle_t | release () |
Release ownership over holded system library handle. | |
bool | operator< (const DynamicLibrary &other) const |
Compare operator, defined to allow store dynamic libriaries in standard containers which require this. | |
bool | operator== (const DynamicLibrary &other) const |
Compare operator, defined to allow store dynamic libriaries in standard containers which require this. | |
Static Public Attributes | |
static constexpr const char * | DEFAULT_EXTENSION |
Hold opened shared library.
Portable, thin wrapper over system handle to library.
Close holded library in destructor.
Definition at line 35 of file loader.hpp.
Definition at line 41 of file loader.hpp.
Enumerator | |
---|---|
DONT_CLOSE | if this flag is set DynamicLibrary will not close the library, but it will be closed on application exit |
Definition at line 37 of file loader.hpp.
Open library from file with given name filename
.
filename | name of file with library to load |
flags | flags which describes configuration of open/close process, one or more (or-ed) flags from DynamicLibrary::Flags set |
Definition at line 27 of file loader.cpp.
plask::DynamicLibrary::DynamicLibrary | ( | ) |
|
delete |
Coping of library is not allowed.
|
noexcept |
Move library ownership from to_move
to this.
to_move | source of moving library ownership |
Definition at line 34 of file loader.cpp.
plask::DynamicLibrary::~DynamicLibrary | ( | ) |
Dispose library.
Definition at line 41 of file loader.cpp.
void plask::DynamicLibrary::close | ( | ) |
Close opened library.
Definition at line 98 of file loader.cpp.
|
inline |
Get system handler to the loaded library.
In windows it can be casted to HINSTANCE (defined in windows.h).
Definition at line 58 of file loader.hpp.
Get symbol from library.
Throw exception if library is not opened.
symbol_name | name of symbol to get |
nullptr
if there is no symbol with given name Definition at line 112 of file loader.cpp.
|
inline |
Get symbol from library and cast it to given type.
Throw exception if library is not opened.
symbol_name | name of symbol to get |
nullptr
if there is no symbol with given name SymbolType | required type to which symbol will be casted |
Definition at line 151 of file loader.hpp.
|
inline |
Get system handle.
Type of result is system specyfic (DynamicLibrary::handle_t).
Definition at line 194 of file loader.hpp.
|
inline |
Check if library is already open.
true
only if library is already open Definition at line 186 of file loader.hpp.
Open library from file with given name filename
.
Close already opened library wrapped by this if any.
filename | name of file with library to load |
flags | flags which describe configuration of open/close process, one or more (or-ed) flags from DynamicLibrary::Flags set |
Definition at line 76 of file loader.cpp.
|
inline |
Compare operator, defined to allow store dynamic libriaries in standard containers which require this.
Definition at line 207 of file loader.hpp.
|
delete |
Coping of library is not allowed.
|
inlinenoexcept |
Move library ownership from to_move
to this.
Same as: swap(to_move);
to_move | source of moving library ownership |
Definition at line 98 of file loader.hpp.
|
inline |
Compare operator, defined to allow store dynamic libriaries in standard containers which require this.
Definition at line 218 of file loader.hpp.
Same as getSymbol(const std::string &symbol_name)
Definition at line 156 of file loader.hpp.
DynamicLibrary::handle_t plask::DynamicLibrary::release | ( | ) |
Release ownership over holded system library handle.
This does not close the library.
Definition at line 131 of file loader.cpp.
Get symbol from library.
Throw exception if library is not opened or if there is no symbol with given name.
symbol_name | name of symbol to get |
Definition at line 124 of file loader.cpp.
|
inline |
Get symbol from library and cast it to given type.
Throw exception if library is not opened or if there is no symbol with given name.
symbol_name | name of symbol to get |
SymbolType | required type to which symbol will be casted |
Definition at line 178 of file loader.hpp.
|
inlinenoexcept |
Swap library ownerships between this and to_swap.
to_swap | library to swap with |
Definition at line 107 of file loader.hpp.
Definition at line 60 of file loader.hpp.