PLaSK library

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
plask::DynamicLibrary Struct Reference

Hold opened shared library. More...

`#include <plask/utils/dynlib/loader.hpp>`

Collaboration diagram for plask::DynamicLibrary:
[legend]

## 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

## Detailed Description

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.

## Member Typedef Documentation

## ◆ handle_t

typedef void* plask::DynamicLibrary::handle_t

Definition at line 41 of file loader.hpp.

## Member Enumeration Documentation

## ◆ Flags

enum plask::DynamicLibrary::Flags

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.

## Constructor & Destructor Documentation

## ◆ DynamicLibrary() [1/4]

plask::DynamicLibrary::DynamicLibrary | ( | const std::string & | filename,
|  | unsigned | flags
| ) |  |
| explicit

Open library from file with given name `filename`.

Parameters

  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.

## ◆ DynamicLibrary() [2/4]

plask::DynamicLibrary::DynamicLibrary | ( |  | ) |

Don't open any library.

You can call open later.

Definition at line 32 of file loader.cpp.

## ◆ DynamicLibrary() [3/4]

plask::DynamicLibrary::DynamicLibrary | ( | const DynamicLibrary & |  | ) |
| delete

Coping of library is not allowed.

## ◆ DynamicLibrary() [4/4]

plask::DynamicLibrary::DynamicLibrary | ( | DynamicLibrary && | to_move | ) |
| noexcept

Move library ownership from `to_move` to this.

Parameters

  to_move | source of moving library ownership

Definition at line 34 of file loader.cpp.

## ◆ ~DynamicLibrary()

plask::DynamicLibrary::~DynamicLibrary | ( |  | ) |

Dispose library.

Definition at line 41 of file loader.cpp.

## Member Function Documentation

## ◆ close()

void plask::DynamicLibrary::close | ( |  | ) |

Close opened library.

Definition at line 98 of file loader.cpp.

## ◆ getHandle()

handle_t plask::DynamicLibrary::getHandle | ( |  | ) | const
| inline

Get system handler to the loaded library.

In windows it can be casted to HINSTANCE (defined in windows.h).

Returns
  the system handler

Definition at line 58 of file loader.hpp.

## ◆ getSymbol() [1/2]

void * plask::DynamicLibrary::getSymbol | ( | const std::string & | symbol_name | ) | const

Get symbol from library.

Throw exception if library is not opened.

Parameters

  symbol_name | name of symbol to get

Returns
  symbol with given name, or `nullptr` if there is no symbol with given name

Definition at line 112 of file loader.cpp.

## ◆ getSymbol() [2/2]

template<typename SymbolType >

SymbolType plask::DynamicLibrary::getSymbol | ( | const std::string & | symbol_name | ) | const
| inline

Get symbol from library and cast it to given type.

Throw exception if library is not opened.

Parameters

  symbol_name | name of symbol to get

Returns
  symbol with given name casted to given type, or `nullptr` if there is no symbol with given name

Template Parameters

  SymbolType | required type to which symbol will be casted

Definition at line 151 of file loader.hpp.

## ◆ getSystemHandler()

handle_t plask::DynamicLibrary::getSystemHandler | ( |  | ) | const
| inline

Get system handle.

Type of result is system specyfic (DynamicLibrary::handle_t).

Returns
  system handle

Definition at line 194 of file loader.hpp.

## ◆ isOpen()

bool plask::DynamicLibrary::isOpen | ( |  | ) | const
| inline

Check if library is already open.

Returns
  `true` only if library is already open

Definition at line 186 of file loader.hpp.

## ◆ open()

void plask::DynamicLibrary::open | ( | const std::string & | filename,
|  | unsigned | flags
| ) |  |

Open library from file with given name `filename`.

Close already opened library wrapped by this if any.

Parameters

  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.

## ◆ operator<()

bool plask::DynamicLibrary::operator< | ( | const DynamicLibrary & | other | ) | const
| inline

Compare operator, defined to allow store dynamic libriaries in standard containers which require this.

Definition at line 207 of file loader.hpp.

## ◆ operator=() [1/2]

DynamicLibrary & plask::DynamicLibrary::operator= | ( | const DynamicLibrary & |  | ) |
| delete

Coping of library is not allowed.

## ◆ operator=() [2/2]

DynamicLibrary & plask::DynamicLibrary::operator= | ( | DynamicLibrary && | to_move | ) |
| inline noexcept

Move library ownership from `to_move` to this.

Same as: `swap(to_move);`

Parameters

  to_move | source of moving library ownership

Returns
  *this

Definition at line 98 of file loader.hpp.

## ◆ operator==()

bool plask::DynamicLibrary::operator== | ( | const DynamicLibrary & | other | ) | const
| inline

Compare operator, defined to allow store dynamic libriaries in standard containers which require this.

Definition at line 218 of file loader.hpp.

## ◆ operator[]()

void * plask::DynamicLibrary::operator[] | ( | const std::string & | symbol_name | ) | const
| inline

Same as getSymbol(const std::string &symbol_name)

Definition at line 156 of file loader.hpp.

## ◆ release()

DynamicLibrary::handle_t plask::DynamicLibrary::release | ( |  | ) |

Release ownership over holded system library handle.

This does not close the library.

Returns
  system library handle which ownership has been released (on windows it can be casted to HINSTANCE)

Definition at line 131 of file loader.cpp.

## ◆ requireSymbol() [1/2]

void * plask::DynamicLibrary::requireSymbol | ( | const std::string & | symbol_name | ) | const

Get symbol from library.

Throw exception if library is not opened or if there is no symbol with given name.

Parameters

  symbol_name | name of symbol to get

Returns
  symbol with given name

Definition at line 124 of file loader.cpp.

## ◆ requireSymbol() [2/2]

template<typename SymbolType >

SymbolType plask::DynamicLibrary::requireSymbol | ( | const std::string & | symbol_name | ) | const
| 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.

Parameters

  symbol_name | name of symbol to get

Returns
  symbol with given name, casted to given type

Template Parameters

  SymbolType | required type to which symbol will be casted

Definition at line 178 of file loader.hpp.

## ◆ swap()

void plask::DynamicLibrary::swap | ( | DynamicLibrary & | to_swap | ) |
| inline noexcept

Swap library ownerships between this and to_swap.

Parameters

  to_swap | library to swap with

Definition at line 107 of file loader.hpp.

## Member Data Documentation

## ◆ DEFAULT_EXTENSION

constexpr const char * plask::DynamicLibrary::DEFAULT_EXTENSION
| static constexpr

Initial value:
=
".so"

Definition at line 60 of file loader.hpp.

The documentation for this struct was generated from the following files:

- plask/utils/dynlib/loader.hpp
- plask/utils/dynlib/loader.cpp