SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_loadso.h
1#ifndef SDL3PP_LOADSO_H_
2#define SDL3PP_LOADSO_H_
3
4#include <SDL3/SDL_loadso.h>
5#include "SDL3pp_stdinc.h"
6
7namespace SDL {
8
42
43// Forward decl
44struct SharedObject;
45
47using SharedObjectRaw = SDL_SharedObject*;
48
55
67struct SharedObject : ResourceBase<SharedObjectRaw>
68{
70
78 constexpr explicit SharedObject(SharedObjectRaw resource) noexcept
79 : ResourceBase(resource)
80 {
81 }
82
84 constexpr SharedObject(const SharedObject& other) = delete;
85
87 constexpr SharedObject(SharedObject&& other) noexcept
88 : SharedObject(other.release())
89 {
90 }
91
92 constexpr SharedObject(const SharedObjectRef& other) = delete;
93
94 constexpr SharedObject(SharedObjectRef&& other) = delete;
95
111
113 ~SharedObject() { SDL_UnloadObject(get()); }
114
116 constexpr SharedObject& operator=(SharedObject&& other) noexcept
117 {
118 swap(*this, other);
119 return *this;
120 }
121
123 SharedObject& operator=(const SharedObject& other) = delete;
124
137 void Unload();
138
166};
167
183{
184 return SharedObject(std::move(sofile));
185}
186
188 : SharedObject(SDL_LoadObject(sofile))
189{
190}
191
219{
220 return SDL_LoadFunction(handle, name);
221}
222
224{
225 return SDL::LoadFunction(get(), std::move(name));
226}
227
242inline void UnloadObject(SharedObjectRaw handle) { SDL_UnloadObject(handle); }
243
245
247
248} // namespace SDL
249
250#endif /* SDL3PP_LOADSO_H_ */
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
FunctionPointer LoadFunction(StringParam name)
Look up the address of the named function in a shared object.
Definition SDL3pp_loadso.h:223
SharedObject LoadObject(StringParam sofile)
Dynamically load a shared object.
Definition SDL3pp_loadso.h:182
void UnloadObject(SharedObjectRaw handle)
Unload a shared object from memory.
Definition SDL3pp_loadso.h:242
SDL_SharedObject * SharedObjectRaw
Alias to raw representation for SharedObject.
Definition SDL3pp_loadso.h:47
void Unload()
Unload a shared object from memory.
Definition SDL3pp_loadso.h:244
FunctionPointer LoadFunction(SharedObjectRef handle, StringParam name)
Look up the address of the named function in a shared object.
Definition SDL3pp_loadso.h:218
ResourceRef< SharedObject > SharedObjectRef
Reference for SharedObject.
Definition SDL3pp_loadso.h:54
void(SDLCALL *)() FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:6249
Main include header for the SDL3pp library.
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
An opaque datatype that represents a loaded shared object.
Definition SDL3pp_loadso.h:68
SharedObject & operator=(const SharedObject &other)=delete
Assignment operator.
constexpr SharedObject(SharedObjectRaw resource) noexcept
Constructs from raw SharedObject.
Definition SDL3pp_loadso.h:78
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr SharedObject(const SharedObject &other)=delete
Copy constructor.
~SharedObject()
Destructor.
Definition SDL3pp_loadso.h:113
constexpr SharedObject & operator=(SharedObject &&other) noexcept
Assignment operator.
Definition SDL3pp_loadso.h:116
constexpr SharedObject(SharedObject &&other) noexcept
Move constructor.
Definition SDL3pp_loadso.h:87