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
41
42// Forward decl
43struct SharedObjectBase;
44
45// Forward decl
46struct SharedObject;
47
49using SharedObjectRaw = SDL_SharedObject*;
50
57
63struct SharedObjectBase : ResourceBaseT<SharedObjectRaw>
64{
66
79 void Unload();
80
107};
108
121{
122 using SharedObjectBase::SharedObjectBase;
123
131 constexpr explicit SharedObject(SharedObjectRaw resource) noexcept
132 : SharedObjectBase(resource)
133 {
134 }
135
137 constexpr SharedObject(SharedObject&& other) noexcept
138 : SharedObject(other.release())
139 {
140 }
141
157
159 ~SharedObject() { SDL_UnloadObject(get()); }
160
162 constexpr SharedObject& operator=(SharedObject&& other) noexcept
163 {
164 swap(*this, other);
165 return *this;
166 }
167};
168
184{
185 return SharedObject(sofile);
186}
187
189 : SharedObject(SDL_LoadObject(sofile))
190{
191}
192
220{
221 return SDL_LoadFunction(handle, name);
222}
223
228
243inline void UnloadObject(SharedObjectRaw handle) { SDL_UnloadObject(handle); }
244
246
248
249} // namespace SDL
250
251#endif /* SDL3PP_LOADSO_H_ */
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
void Unload()
Unload a shared object from memory.
Definition SDL3pp_loadso.h:245
SharedObject LoadObject(StringParam sofile)
Dynamically load a shared object.
Definition SDL3pp_loadso.h:183
void UnloadObject(SharedObjectRaw handle)
Unload a shared object from memory.
Definition SDL3pp_loadso.h:243
SDL_SharedObject * SharedObjectRaw
Alias to raw representation for SharedObject.
Definition SDL3pp_loadso.h:49
FunctionPointer LoadFunction(SharedObjectRef handle, StringParam name)
Look up the address of the named function in a shared object.
Definition SDL3pp_loadso.h:219
ResourceRefT< SharedObjectBase > SharedObjectRef
Reference for SharedObject.
Definition SDL3pp_loadso.h:56
FunctionPointer LoadFunction(StringParam name)
Look up the address of the named function in a shared object.
Definition SDL3pp_loadso.h:224
void(SDLCALL *)() FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:6254
Main include header for the SDL3pp library.
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to SharedObject.
Definition SDL3pp_loadso.h:64
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque datatype that represents a loaded shared object.
Definition SDL3pp_loadso.h:121
constexpr SharedObject(SharedObjectRaw resource) noexcept
Constructs from raw SharedObject.
Definition SDL3pp_loadso.h:131
~SharedObject()
Destructor.
Definition SDL3pp_loadso.h:159
constexpr SharedObject & operator=(SharedObject &&other) noexcept
Assignment operator.
Definition SDL3pp_loadso.h:162
constexpr SharedObject(SharedObject &&other) noexcept
Move constructor.
Definition SDL3pp_loadso.h:137