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
44// Forward decl
45struct SharedObjectBase;
46
47// Forward decl
48struct SharedObjectRef;
49
50// Forward decl
51struct SharedObject;
52
66struct SharedObjectBase : Resource<SDL_SharedObject*>
67{
69
85 : Resource(SDL_LoadObject(sofile))
86 {
87 }
88
116 {
117 return SDL_LoadFunction(get(), name);
118 }
119};
120
130{
132
136 constexpr SharedObjectRef(const SharedObjectRef& other)
137 : SharedObjectBase(other.get())
138 {
139 }
140
145 : SharedObjectBase(other.release())
146 {
147 }
148
152 constexpr ~SharedObjectRef() = default;
153
158 {
159 release(other.release());
160 return *this;
161 }
162
175 void reset(SDL_SharedObject* newResource = {})
176 {
177 SDL_UnloadObject(release(newResource));
178 }
179
192 void Unload() { reset(); }
193};
194
204{
206
210 constexpr explicit SharedObject(SDL_SharedObject* resource = {})
211 : SharedObjectRef(resource)
212 {
213 }
214
215 constexpr SharedObject(const SharedObject& other) = delete;
216
220 constexpr SharedObject(SharedObject&& other) = default;
221
226
231 {
232 reset(other.release());
233 return *this;
234 }
235};
236
238
239} // namespace SDL
240
241#endif /* SDL3PP_LOADSO_H_ */
A SDL managed resource.
Definition SDL3pp_resource.h:17
constexpr SDL_SharedObject * release(SDL_SharedObject * newResource={})
Return contained resource and empties or replace value.
Definition SDL3pp_resource.h:60
constexpr Resource(T resource={})
Constructs the underlying resource.
Definition SDL3pp_resource.h:22
constexpr SDL_SharedObject * get() const
Return contained resource;.
Definition SDL3pp_resource.h:57
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
SDL_FunctionPointer FunctionPointer
A generic function pointer.
Definition SDL3pp_stdinc.h:5484
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
An opaque datatype that represents a loaded shared object.
Definition SDL3pp_loadso.h:67
FunctionPointer LoadFunction(StringParam name)
Look up the address of the named function in a shared object.
Definition SDL3pp_loadso.h:115
SharedObjectBase(StringParam sofile)
Dynamically load a shared object.
Definition SDL3pp_loadso.h:84
Handle to a non owned sharedObject.
Definition SDL3pp_loadso.h:130
constexpr SharedObjectRef(const SharedObjectRef &other)
Copy constructor.
Definition SDL3pp_loadso.h:136
constexpr SharedObjectRef(SharedObjectRef &&other)
Move constructor.
Definition SDL3pp_loadso.h:144
void Unload()
Unload a shared object from memory.
Definition SDL3pp_loadso.h:192
void reset(SDL_SharedObject *newResource={})
Unload a shared object from memory.
Definition SDL3pp_loadso.h:175
SharedObjectRef & operator=(SharedObjectRef other)
Assignment operator.
Definition SDL3pp_loadso.h:157
constexpr ~SharedObjectRef()=default
Default constructor.
Handle to an owned sharedObject.
Definition SDL3pp_loadso.h:204
constexpr SharedObject(SharedObject &&other)=default
Move constructor.
SharedObject & operator=(SharedObject other)
Assignment operator.
Definition SDL3pp_loadso.h:230
~SharedObject()
Frees up resource when object goes out of scope.
Definition SDL3pp_loadso.h:225
constexpr SharedObject(SDL_SharedObject *resource={})
Constructs from the underlying resource.
Definition SDL3pp_loadso.h:210