============================================================================== A minimal cross-platform loader for .dll/.so files. */
| 29 | A minimal cross-platform loader for .dll/.so files. |
| 30 | */ |
| 31 | struct DynamicLibrary |
| 32 | { |
| 33 | DynamicLibrary() = default; |
| 34 | |
| 35 | /// Attempts to load a library with the given name or path. |
| 36 | DynamicLibrary (std::string_view library); |
| 37 | |
| 38 | DynamicLibrary (const DynamicLibrary&) = delete; |
| 39 | DynamicLibrary& operator= (const DynamicLibrary&) = delete; |
| 40 | DynamicLibrary (DynamicLibrary&&); |
| 41 | DynamicLibrary& operator= (DynamicLibrary&&); |
| 42 | |
| 43 | /// On destruction, this object releases the library that was loaded |
| 44 | ~DynamicLibrary(); |
| 45 | |
| 46 | /// Returns a pointer to the function with this name, or nullptr if not found. |
| 47 | void* findFunction (std::string_view functionName); |
| 48 | |
| 49 | /// Returns true if the library was successfully loaded |
| 50 | operator bool() const noexcept { return handle != nullptr; } |
| 51 | |
| 52 | /// Releases any handle that this object is holding |
| 53 | void close(); |
| 54 | |
| 55 | /// platform-specific handle. Will be nullptr if not loaded |
| 56 | void* handle = nullptr; |
| 57 | }; |
| 58 | |
| 59 | |
| 60 |
no outgoing calls