GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::SharedLibrary Class Reference

Library of dynamically loaded symbols. More...

#include <GREM/core/system/SharedLibrary.hpp>

Classes

struct  Error
 Exception type for errors that may arise from a SharedLibrary. More...

Public Member Functions

 SharedLibrary () noexcept=default
 Construct a closed shared library.
 SharedLibrary (const Filesystem &filesystem, CStringView filepath)
 Construct a shared library opened from a file.
 operator bool () const noexcept
 Check if the shared library is currently open.
bool is_open () const noexcept
 Check if the shared library is currently open.
void close ()
 Close the shared library if it is currently open, invalidating all current pointers to its symbols from this program.
void open (const Filesystem &filesystem, CStringView filepath)
 Open the shared library from a file.
template<typename T>
T & getSymbol (CStringView name)
 Get a reference to the symbol with a specific name in the library.

Static Public Member Functions

static CStringView getLibraryFilenameExtension ()
 Get the proper filename extension for shared libraries on the current platform.

Detailed Description

Library of dynamically loaded symbols.

On Windows, this corresponds to a Dynamically Linked Library (.dll file). On Linux, this corresponds to a Dynamic Shared Object (.so file). On Apple platforms, this corresponds to a Dynamic Library (.dylib file). On other platforms, shared libraries are unsupported, and attempting to open one always fails.

Constructor & Destructor Documentation

◆ SharedLibrary() [1/2]

grem::SharedLibrary::SharedLibrary ( )
defaultnoexcept

Construct a closed shared library.

◆ SharedLibrary() [2/2]

grem::SharedLibrary::SharedLibrary ( const Filesystem & filesystem,
CStringView filepath )
inlineexplicit

Construct a shared library opened from a file.

Parameters
filesystemfilesystem to load the file from.
filepathinput filepath of the shared library file to open.
Exceptions
File::Erroron failure to locate the file.
SharedLibrary::Erroron failure to open the library.
std::bad_allocon allocation failure.

Member Function Documentation

◆ getLibraryFilenameExtension()

CStringView grem::SharedLibrary::getLibraryFilenameExtension ( )
staticnodiscard

Get the proper filename extension for shared libraries on the current platform.

Returns
the filename extension for shared libraries on the current platform without a leading dot, or an empty string if the current platform does not support shared libraries.

◆ operator bool()

grem::SharedLibrary::operator bool ( ) const
inlineexplicitnoexcept

Check if the shared library is currently open.

Returns
true if the library is open, false otherwise.

◆ is_open()

bool grem::SharedLibrary::is_open ( ) const
inlinenodiscardnoexcept

Check if the shared library is currently open.

Returns
true if the library is open, false otherwise.

◆ close()

void grem::SharedLibrary::close ( )

Close the shared library if it is currently open, invalidating all current pointers to its symbols from this program.

Exceptions
SharedLibrary::Erroron failure to close the library.
std::bad_allocon allocation failure.

◆ open()

void grem::SharedLibrary::open ( const Filesystem & filesystem,
CStringView filepath )

Open the shared library from a file.

Parameters
filesystemfilesystem to load the file from.
filepathinput filepath of the shared library file to open.
Exceptions
File::Erroron failure to locate the file.
SharedLibrary::Erroron failure to open the library.
std::bad_allocon allocation failure.

◆ getSymbol()

template<typename T>
T & grem::SharedLibrary::getSymbol ( CStringView name)
inline

Get a reference to the symbol with a specific name in the library.

Template Parameters
Ttype of the symbol to get. Must exactly match the type of the specified symbol in the library.
Parameters
nameexact, potentially mangled, name of the symbol to search for.
Returns
a reference to the requested symbol.
Exceptions
SharedLibrary::Erroron failure to find or retrieve the symbol address.
std::bad_allocon allocation failure.

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