lfilesystem
0.0.1
C++ filesystem library
|
This class represents a dynamically loaded library. More...
#include <lfilesystem_DynamicLibrary.h>
Classes | |
class | Listener |
This class listens for events to a DynamicLibrary and receives a callback when the library is opened, closed, or reloaded. More... | |
class | Reloader |
This class watches a dynamic library file for changes on disk. More... | |
Public Types | |
using | Handle = void * |
The type of platform-specific handle used for dynamic libraries. More... | |
Public Member Functions | |
DynamicLibrary (const DynamicLibrary &)=delete | |
DynamicLibrary (DynamicLibrary &&other) noexcept | |
~DynamicLibrary () | |
Destructor. More... | |
void | close () |
Closes the shared library, if one is open. More... | |
void * | findFunction (const std::string_view &functionName) noexcept |
Attempts to locate a function within the shared library, and, if found, returns a pointer to the function. More... | |
File | getFile () const |
Attempts to locate the file on disk where the code for the current shared library is actually located. More... | |
Handle | getHandle () const noexcept |
Returns a platform-specific handle to the currently open shared library (if any). More... | |
std::string | getName () const |
Attempts to determine the name of the library, if it is open. More... | |
bool | isOpen () const noexcept |
Returns true if the library is currently open. More... | |
bool | open (const std::string_view &nameOrPath) noexcept |
Attempts to open a new shared library. More... | |
bool | operator!= (const DynamicLibrary &other) const noexcept |
Returns true if this library object does not refer to the same shared library as the other one. More... | |
DynamicLibrary & | operator= (const DynamicLibrary &)=delete |
DynamicLibrary & | operator= (DynamicLibrary &&other) noexcept |
bool | operator== (const DynamicLibrary &other) const noexcept |
Returns true if this library object refers to the same shared library as the other one. More... | |
bool | reload () |
Closes and reloads the library. More... | |
Constructors | |
DynamicLibrary ()=default | |
Creates an unopened library object. More... | |
DynamicLibrary (const std::string_view &nameOrPath) noexcept | |
Creates a library object and attempts to open the specified library. More... | |
This class represents a dynamically loaded library.
On Unixes, this is the equivalent of using dlopen()
, but wrapped in an RAII class that frees the library handle when it is destroyed.
This class can also locate the file on disk that the library was loaded from, and "reload" itself.
All functions of this class are thread-safe; the library handle is stored atomically.
dlopen()
.Definition at line 57 of file lfilesystem_DynamicLibrary.h.
The type of platform-specific handle used for dynamic libraries.
This will be HMODULE
on Windows and void*
everywhere else. This will always be a pointer or pointer-like type.
Definition at line 87 of file lfilesystem_DynamicLibrary.h.
|
default |
Creates an unopened library object.
Call open()
to actually open a library.
|
explicitnoexcept |
Creates a library object and attempts to open the specified library.
limes::files::DynamicLibrary::~DynamicLibrary | ( | ) |
Destructor.
If the library is open when this object is destroyed, the destructor will close the library.
void limes::files::DynamicLibrary::close | ( | ) |
Closes the shared library, if one is open.
This will call libraryClosed()
on all listeners.
getHandle()
after calling this function will return nullptr
.
|
noexcept |
Attempts to locate a function within the shared library, and, if found, returns a pointer to the function.
File limes::files::DynamicLibrary::getFile | ( | ) | const |
Attempts to locate the file on disk where the code for the current shared library is actually located.
If the library isn't open, returns a null file.
|
noexcept |
Returns a platform-specific handle to the currently open shared library (if any).
std::string limes::files::DynamicLibrary::getName | ( | ) | const |
Attempts to determine the name of the library, if it is open.
If the library isn't open, returns an empty string.
|
noexcept |
Returns true if the library is currently open.
This can be called after the constructor, or after calling open(), to check if the library opened correctly.
|
noexcept |
Attempts to open a new shared library.
If one was previously open, calling this will close the old library (even if the new library fails to open).
This will call libraryOpened()
on all listeners.
|
noexcept |
Returns true if this library object does not refer to the same shared library as the other one.
|
noexcept |
Returns true if this library object refers to the same shared library as the other one.
bool limes::files::DynamicLibrary::reload | ( | ) |
Closes and reloads the library.
This locates the file on disk from which the library was loaded, then closes the library and reopens it from this same file.