VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
SharedLibrary.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <filesystem>
5
6namespace VoltMod
7{
8
9/** A shared library the host opened, closed at scope end. Move-only: two owners would close it twice. */
11{
12public:
13 SharedLibrary() = default;
15
18
19 SharedLibrary(const SharedLibrary&) = delete;
21
22 /** Load @p path. The error carries the operating system's own message. */
23 static Result<SharedLibrary> Open(const std::filesystem::path& path);
24
25 /** The address @p name exports, or an error naming it. */
26 Result<void*> Symbol(const char* name) const;
27
28private:
29 explicit SharedLibrary(void* handle) : _handle(handle) {}
30 void Close();
31
32 void* _handle = nullptr;
33};
34
35} // namespace VoltMod
static Result< SharedLibrary > Open(const std::filesystem::path &path)
Result< void * > Symbol(const char *name) const
SharedLibrary(const SharedLibrary &)=delete
SharedLibrary & operator=(const SharedLibrary &)=delete
SharedLibrary & operator=(SharedLibrary &&other) noexcept
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< T, Error > Result
Definition Result.hpp:64