Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::core::SharedLibrary Class Reference

A shared library opened at run time (.so, .dylib or .dll), closed when destroyed. More...

#include <aegis2d/core/shared_library.hpp>

Public Member Functions

 SharedLibrary (const std::filesystem::path &path)
 Opens a library, with every symbol resolved now.
 
 ~SharedLibrary ()
 Closes the library.
 
 SharedLibrary (const SharedLibrary &)=delete
 
SharedLibrary & operator= (const SharedLibrary &)=delete
 
 SharedLibrary (SharedLibrary &&other) noexcept
 Takes the library over; other no longer holds one.
 
SharedLibrary & operator= (SharedLibrary &&other) noexcept
 Closes the library held, then takes other's over.
 
void * symbol (const std::string &name) const noexcept
 Address of an exported symbol.
 
template<typename Function >
Function * function (const std::string &name) const noexcept
 An exported function, with its type.
 
const std::filesystem::path & path () const noexcept
 Path the library was opened from.
 

Detailed Description

A shared library opened at run time (.so, .dylib or .dll), closed when destroyed.

Opens any library and finds its functions by name. Its functions and data are unusable once it is closed, so keep it alive as long as anything from it is used.

Constructor & Destructor Documentation

◆ SharedLibrary() [1/3]

aegis2d::core::SharedLibrary::SharedLibrary ( const std::filesystem::path &  path)
explicit

Opens a library, with every symbol resolved now.

On Windows, the DLLs it needs are also looked for in its own folder.

Parameters
pathPath of the library file.
Exceptions
LibraryErrorif the system cannot open it, with the system's reason.

◆ ~SharedLibrary()

aegis2d::core::SharedLibrary::~SharedLibrary ( )

Closes the library.

◆ SharedLibrary() [2/3]

aegis2d::core::SharedLibrary::SharedLibrary ( const SharedLibrary &  )
delete

◆ SharedLibrary() [3/3]

aegis2d::core::SharedLibrary::SharedLibrary ( SharedLibrary &&  other)
noexcept

Takes the library over; other no longer holds one.

Parameters
otherLibrary to take over.

Member Function Documentation

◆ function()

template<typename Function >
Function * aegis2d::core::SharedLibrary::function ( const std::string &  name) const
inlinenoexcept

An exported function, with its type.

Template Parameters
FunctionType of the function, e.g. int(int).
Parameters
nameName of the function, as exported.
Returns
A pointer to it, or null when the library does not export it.

◆ operator=() [1/2]

SharedLibrary & aegis2d::core::SharedLibrary::operator= ( const SharedLibrary &  )
delete

◆ operator=() [2/2]

SharedLibrary & aegis2d::core::SharedLibrary::operator= ( SharedLibrary &&  other)
noexcept

Closes the library held, then takes other's over.

Parameters
otherLibrary to take over.
Returns
This library.

◆ path()

const std::filesystem::path & aegis2d::core::SharedLibrary::path ( ) const
inlinenoexcept

Path the library was opened from.

Returns
The path given to the constructor.

◆ symbol()

void * aegis2d::core::SharedLibrary::symbol ( const std::string &  name) const
noexcept

Address of an exported symbol.

Parameters
nameName of the symbol, as exported (C names are not mangled).
Returns
Its address, or null when the library does not export it.

The documentation for this class was generated from the following file: