1#ifndef SDL3PP_PROPERTIES_H_
2#define SDL3PP_PROPERTIES_H_
4#include <SDL3/SDL_properties.h>
5#include "SDL3pp_callbackWrapper.h"
6#include "SDL3pp_error.h"
7#include "SDL3pp_strings.h"
68 constexpr explicit operator bool()
const {
return !!
value; }
85 SDL_PROPERTY_TYPE_INVALID;
88 SDL_PROPERTY_TYPE_POINTER;
91 SDL_PROPERTY_TYPE_STRING;
94 SDL_PROPERTY_TYPE_NUMBER;
99 SDL_PROPERTY_TYPE_BOOLEAN;
139 std::function<void(
PropertiesID props,
const char* name)>;
220 : m_resource(resource)
259 std::swap(m_resource, other.m_resource);
283 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
756 return {
CheckError(SDL_GetGlobalProperties())};
847 SDL_UnlockProperties(props);
888 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
925 SDL_SetPointerPropertyWithCleanup(props,
929 Wrapper::Wrap(std::move(cleanup)));
939 m_resource, std::move(name), value, cleanup, userdata);
947 m_resource, std::move(name), value, cleanup);
975 CheckError(SDL_SetPointerProperty(props, name, value));
1005 CheckError(SDL_SetStringProperty(props, name, value));
1031 CheckError(SDL_SetNumberProperty(props, name, value));
1057 CheckError(SDL_SetFloatProperty(props, name, value));
1083 CheckError(SDL_SetBooleanProperty(props, name, value));
1106 return SDL_HasProperty(props, name);
1129 return SDL_GetPropertyType(props, name);
1170 void* default_value)
1172 return SDL_GetPointerProperty(props, name, default_value);
1176 void* default_value)
1207 return SDL_GetStringProperty(props, name, default_value);
1214 m_resource, std::move(name), std::move(default_value));
1241 return SDL_GetNumberProperty(props, name, default_value);
1272 float default_value)
1274 return SDL_GetFloatProperty(props, name, default_value);
1306 return SDL_GetBooleanProperty(props, name, default_value);
1354 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1376 [](
void* userdata,
PropertiesID props,
const char* name) {
1432 SDL_DestroyProperties(props);
SDL properties ID.
Definition: SDL3pp_properties.h:202
constexpr Properties(const Properties &other)=delete
Copy constructor.
constexpr Properties & operator=(const Properties &other) noexcept=default
Assignment operator.
constexpr Properties & operator=(Properties &&other) noexcept
Assignment operator.
Definition: SDL3pp_properties.h:257
~Properties()
Destructor.
Definition: SDL3pp_properties.h:254
constexpr Properties(const PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:219
constexpr PropertiesID release() noexcept
Retrieves underlying PropertiesID and clear this.
Definition: SDL3pp_properties.h:272
constexpr auto operator<=>(const Properties &other) const noexcept=default
Comparison.
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition: SDL3pp_properties.h:228
constexpr Properties(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_properties.h:207
constexpr PropertiesID get() const noexcept
Retrieves underlying PropertiesID.
Definition: SDL3pp_properties.h:269
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
constexpr PropertyType PROPERTY_TYPE_BOOLEAN
BOOLEAN.
Definition: SDL3pp_properties.h:98
void UnlockProperties(PropertiesParam props)
Unlock a group of properties.
Definition: SDL3pp_properties.h:845
static Properties Create()
Create a group of properties.
Definition: SDL3pp_properties.h:778
Sint64 GetNumberProperty(StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1244
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:190
Sint64 GetNumberProperty(PropertiesParam props, StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1237
void SetBooleanProperty(PropertiesParam props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1079
void LockProperties(PropertiesParam props)
Lock a group of properties.
Definition: SDL3pp_properties.h:827
SDL_PropertyType PropertyType
SDL property type.
Definition: SDL3pp_properties.h:82
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1060
void Lock()
Lock a group of properties.
Definition: SDL3pp_properties.h:832
void SetPointerPropertyWithCleanup(StringParam name, void *value, CleanupPropertyCallback cleanup, void *userdata)
Set a pointer property in a group of properties with a cleanup function that is called when the prope...
Definition: SDL3pp_properties.h:932
float GetFloatProperty(StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1277
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1034
void Unlock()
Unlock a group of properties.
Definition: SDL3pp_properties.h:850
Uint64 CountProperties(PropertiesParam props)
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1402
const char * GetStringProperty(StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1210
bool HasProperty(PropertiesParam props, StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1104
float GetFloatProperty(PropertiesParam props, StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1270
void ClearProperty(PropertiesParam props, StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1325
bool GetBooleanProperty(StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition: SDL3pp_properties.h:1309
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1008
std::function< void(PropertiesID props, const char *name)> EnumeratePropertiesCB
A callback used to enumerate all the properties in a group of properties.
Definition: SDL3pp_properties.h:139
void Copy(PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:801
Uint64 GetCount()
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1409
void * GetPointerProperty(PropertiesParam props, StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1168
PropertyType GetPropertyType(PropertiesParam props, StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1127
bool HasProperty(StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1109
void * GetPointerProperty(StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1175
void SetPointerPropertyWithCleanup(PropertiesParam props, StringParam name, void *value, CleanupPropertyCallback cleanup, void *userdata)
Set a pointer property in a group of properties with a cleanup function that is called when the prope...
Definition: SDL3pp_properties.h:881
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1086
void CopyProperties(PropertiesParam src, PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:796
Properties CreateProperties()
Create a group of properties.
Definition: SDL3pp_properties.h:773
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition: SDL3pp_properties.h:93
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition: SDL3pp_properties.h:87
void SetPointerProperty(PropertiesParam props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:971
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:164
const char * GetStringProperty(PropertiesParam props, StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1203
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition: SDL3pp_properties.h:84
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition: SDL3pp_properties.h:96
void Enumerate(EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1383
void SetNumberProperty(PropertiesParam props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1027
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition: SDL3pp_properties.h:90
PropertyType GetPropertyType(StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1132
void SetFloatProperty(PropertiesParam props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1053
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:978
void Destroy()
Destroy a group of properties.
Definition: SDL3pp_properties.h:1435
void SetStringProperty(PropertiesParam props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1001
void(SDLCALL *)(void *userdata, PropertiesID props, const char *name) EnumeratePropertiesCallback
A callback used to enumerate all the properties in a group of properties.
Definition: SDL3pp_properties.h:120
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition: SDL3pp_properties.h:45
bool GetBooleanProperty(PropertiesParam props, StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition: SDL3pp_properties.h:1302
void ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1330
void EnumerateProperties(PropertiesParam props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1350
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition: SDL3pp_properties.h:1430
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition: SDL3pp_properties.h:754
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:371
::Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:356
Main include header for the SDL3pp library.
Definition: SDL3pp_callbackWrapper.h:20
Safely wrap Properties for non owning parameters.
Definition: SDL3pp_properties.h:52
constexpr PropertiesParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_properties.h:62
constexpr auto operator<=>(const PropertiesParam &other) const =default
Comparison.
constexpr PropertiesParam(PropertiesID value)
Constructs from PropertiesID.
Definition: SDL3pp_properties.h:56
PropertiesID value
parameter's PropertiesID
Definition: SDL3pp_properties.h:53
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:708
PropertiesRef(const PropertiesRef &other) noexcept
Copy constructor.
Definition: SDL3pp_properties.h:736
PropertiesRef(PropertiesParam resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:718
~PropertiesRef()
Destructor.
Definition: SDL3pp_properties.h:742
PropertiesRef(PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:730