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"
8#include "SDL3pp_version.h"
69 constexpr explicit operator bool()
const {
return !!
value; }
89 SDL_PROPERTY_TYPE_INVALID;
92 SDL_PROPERTY_TYPE_POINTER;
95 SDL_PROPERTY_TYPE_STRING;
98 SDL_PROPERTY_TYPE_NUMBER;
103 SDL_PROPERTY_TYPE_BOOLEAN;
143 std::function<void(
PropertiesID props,
const char* name)>;
224 : m_resource(resource)
265 std::swap(m_resource, other.m_resource);
289 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
806 : m_lock(other.m_lock)
829 std::swap(m_lock, other.m_lock);
834 constexpr operator bool()
const {
return bool(m_lock); }
854#if SDL_VERSION_ATLEAST(3, 4, 0)
893 return {
CheckError(SDL_GetGlobalProperties())};
974 : m_lock(std::move(resource))
992 SDL_UnlockProperties(props);
1003 if (!m_lock)
return;
1044 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
1081 SDL_SetPointerPropertyWithCleanup(props,
1085 Wrapper::Wrap(std::move(cleanup)));
1095 m_resource, std::move(name), value, cleanup, userdata);
1103 m_resource, std::move(name), value, cleanup);
1131 CheckError(SDL_SetPointerProperty(props, name, value));
1161 CheckError(SDL_SetStringProperty(props, name, value));
1187 CheckError(SDL_SetNumberProperty(props, name, value));
1213 CheckError(SDL_SetFloatProperty(props, name, value));
1239 CheckError(SDL_SetBooleanProperty(props, name, value));
1262 return SDL_HasProperty(props, name);
1285 return SDL_GetPropertyType(props, name);
1326 void* default_value)
1328 return SDL_GetPointerProperty(props, name, default_value);
1332 void* default_value)
1363 return SDL_GetStringProperty(props, name, default_value);
1370 m_resource, std::move(name), std::move(default_value));
1397 return SDL_GetNumberProperty(props, name, default_value);
1428 float default_value)
1430 return SDL_GetFloatProperty(props, name, default_value);
1462 return SDL_GetBooleanProperty(props, name, default_value);
1510 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1532 [](
void* userdata,
PropertiesID props,
const char* name) {
1588 SDL_DestroyProperties(props);
Lock a group of properties.
Definition: SDL3pp_properties.h:773
~PropertiesLock()
Unlock a group of properties.
Definition: SDL3pp_properties.h:822
PropertiesLock(const PropertiesLock &other)=delete
Copy constructor.
PropertiesRef get()
Get the reference to locked resource.
Definition: SDL3pp_properties.h:848
void release()
Releases the lock without unlocking.
Definition: SDL3pp_properties.h:851
PropertiesLock & operator=(PropertiesLock &&other) noexcept
Assignment operator.
Definition: SDL3pp_properties.h:827
constexpr PropertiesLock(PropertiesLock &&other) noexcept
Move constructor.
Definition: SDL3pp_properties.h:805
An ID that represents a properties set.
Definition: SDL3pp_properties.h:206
constexpr Properties & operator=(const Properties &other) noexcept=default
Assignment operator.
constexpr Properties(const Properties &other) noexcept=default
Copy constructor.
constexpr Properties & operator=(Properties &&other) noexcept
Assignment operator.
Definition: SDL3pp_properties.h:263
~Properties()
Destructor.
Definition: SDL3pp_properties.h:260
constexpr Properties(const PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:223
constexpr PropertiesID release() noexcept
Retrieves underlying PropertiesID and clear this.
Definition: SDL3pp_properties.h:278
constexpr auto operator<=>(const Properties &other) const noexcept=default
Comparison.
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition: SDL3pp_properties.h:234
constexpr Properties(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_properties.h:211
constexpr PropertiesID get() const noexcept
Retrieves underlying PropertiesID.
Definition: SDL3pp_properties.h:275
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition: SDL3pp_assert.h:383
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:102
void UnlockProperties(PropertiesParam props)
Unlock a group of properties.
Definition: SDL3pp_properties.h:990
PropertiesLock(PropertiesRef resource)
Lock a group of properties.
Definition: SDL3pp_properties.h:973
static Properties Create()
Create a group of properties.
Definition: SDL3pp_properties.h:915
Sint64 GetNumberProperty(StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1400
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:194
Sint64 GetNumberProperty(PropertiesParam props, StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1393
void SetBooleanProperty(PropertiesParam props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1235
void LockProperties(PropertiesParam props)
Lock a group of properties.
Definition: SDL3pp_properties.h:966
SDL_PropertyType PropertyType
SDL property type.
Definition: SDL3pp_properties.h:86
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1216
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:1088
float GetFloatProperty(StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1433
PropertiesLock Lock()
Lock a group of properties.
Definition: SDL3pp_properties.h:971
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1190
Uint64 CountProperties(PropertiesParam props)
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1558
void Unlock(PropertiesLock &&lock)
Unlock a group of properties.
Definition: SDL3pp_properties.h:995
const char * GetStringProperty(StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1366
bool HasProperty(PropertiesParam props, StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1260
float GetFloatProperty(PropertiesParam props, StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1426
void ClearProperty(PropertiesParam props, StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1481
bool GetBooleanProperty(StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition: SDL3pp_properties.h:1465
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1164
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:143
void Copy(PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:940
Uint64 GetCount()
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1565
void * GetPointerProperty(PropertiesParam props, StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1324
PropertyType GetPropertyType(PropertiesParam props, StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1283
bool HasProperty(StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1265
void * GetPointerProperty(StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1331
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:1037
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1242
void CopyProperties(PropertiesParam src, PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:935
Properties CreateProperties()
Create a group of properties.
Definition: SDL3pp_properties.h:910
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition: SDL3pp_properties.h:97
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition: SDL3pp_properties.h:91
auto PROP_NAME_STRING
A generic property for naming things.
Definition: SDL3pp_properties.h:878
void SetPointerProperty(PropertiesParam props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:1127
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:168
const char * GetStringProperty(PropertiesParam props, StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1359
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition: SDL3pp_properties.h:88
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition: SDL3pp_properties.h:100
void Enumerate(EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1539
void SetNumberProperty(PropertiesParam props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1183
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition: SDL3pp_properties.h:94
PropertyType GetPropertyType(StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1288
void SetFloatProperty(PropertiesParam props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1209
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:1134
void Destroy()
Destroy a group of properties.
Definition: SDL3pp_properties.h:1591
void SetStringProperty(PropertiesParam props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1157
void reset()
Unlock 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:124
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition: SDL3pp_properties.h:46
bool GetBooleanProperty(PropertiesParam props, StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition: SDL3pp_properties.h:1458
void ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1486
void EnumerateProperties(PropertiesParam props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1506
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition: SDL3pp_properties.h:1586
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition: SDL3pp_properties.h:891
::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:53
constexpr auto operator<=>(const PropertiesParam &other) const =default
Comparison.
constexpr PropertiesParam(PropertiesID value)
Constructs from PropertiesID.
Definition: SDL3pp_properties.h:57
constexpr PropertiesParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_properties.h:63
PropertiesID value
parameter's PropertiesID
Definition: SDL3pp_properties.h:54
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716
PropertiesRef(PropertiesParam resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:726
constexpr PropertiesRef(const PropertiesRef &other) noexcept=default
Copy constructor.
~PropertiesRef()
Destructor.
Definition: SDL3pp_properties.h:747
PropertiesRef(PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:738