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; }
86 SDL_PROPERTY_TYPE_INVALID;
89 SDL_PROPERTY_TYPE_POINTER;
92 SDL_PROPERTY_TYPE_STRING;
95 SDL_PROPERTY_TYPE_NUMBER;
100 SDL_PROPERTY_TYPE_BOOLEAN;
140 std::function<void(
PropertiesID props,
const char* name)>;
221 : m_resource(resource)
260 std::swap(m_resource, other.m_resource);
284 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
748#if SDL_VERSION_ATLEAST(3, 3, 6)
787 return {
CheckError(SDL_GetGlobalProperties())};
880 SDL_UnlockProperties(props);
921 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
958 SDL_SetPointerPropertyWithCleanup(props,
962 Wrapper::Wrap(std::move(cleanup)));
972 m_resource, std::move(name), value, cleanup, userdata);
980 m_resource, std::move(name), value, cleanup);
1008 CheckError(SDL_SetPointerProperty(props, name, value));
1038 CheckError(SDL_SetStringProperty(props, name, value));
1064 CheckError(SDL_SetNumberProperty(props, name, value));
1090 CheckError(SDL_SetFloatProperty(props, name, value));
1116 CheckError(SDL_SetBooleanProperty(props, name, value));
1139 return SDL_HasProperty(props, name);
1162 return SDL_GetPropertyType(props, name);
1203 void* default_value)
1205 return SDL_GetPointerProperty(props, name, default_value);
1209 void* default_value)
1240 return SDL_GetStringProperty(props, name, default_value);
1247 m_resource, std::move(name), std::move(default_value));
1274 return SDL_GetNumberProperty(props, name, default_value);
1305 float default_value)
1307 return SDL_GetFloatProperty(props, name, default_value);
1339 return SDL_GetBooleanProperty(props, name, default_value);
1387 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1409 [](
void* userdata,
PropertiesID props,
const char* name) {
1465 SDL_DestroyProperties(props);
An ID that represents a properties set.
Definition: SDL3pp_properties.h:203
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:258
~Properties()
Destructor.
Definition: SDL3pp_properties.h:255
constexpr Properties(const PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:220
constexpr PropertiesID release() noexcept
Retrieves underlying PropertiesID and clear this.
Definition: SDL3pp_properties.h:273
constexpr auto operator<=>(const Properties &other) const noexcept=default
Comparison.
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition: SDL3pp_properties.h:229
constexpr Properties(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_properties.h:208
constexpr PropertiesID get() const noexcept
Retrieves underlying PropertiesID.
Definition: SDL3pp_properties.h:270
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:99
void UnlockProperties(PropertiesParam props)
Unlock a group of properties.
Definition: SDL3pp_properties.h:878
static Properties Create()
Create a group of properties.
Definition: SDL3pp_properties.h:809
Sint64 GetNumberProperty(StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1277
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:191
Sint64 GetNumberProperty(PropertiesParam props, StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition: SDL3pp_properties.h:1270
void SetBooleanProperty(PropertiesParam props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1112
void LockProperties(PropertiesParam props)
Lock a group of properties.
Definition: SDL3pp_properties.h:860
SDL_PropertyType PropertyType
SDL property type.
Definition: SDL3pp_properties.h:83
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1093
void Lock()
Lock a group of properties.
Definition: SDL3pp_properties.h:865
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:965
float GetFloatProperty(StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1310
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1067
void Unlock()
Unlock a group of properties.
Definition: SDL3pp_properties.h:883
Uint64 CountProperties(PropertiesParam props)
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1435
const char * GetStringProperty(StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1243
bool HasProperty(PropertiesParam props, StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1137
float GetFloatProperty(PropertiesParam props, StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition: SDL3pp_properties.h:1303
void ClearProperty(PropertiesParam props, StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1358
bool GetBooleanProperty(StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition: SDL3pp_properties.h:1342
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1041
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:140
void Copy(PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:834
Uint64 GetCount()
Returns the number of properties this has.
Definition: SDL3pp_properties.h:1442
void * GetPointerProperty(PropertiesParam props, StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1201
PropertyType GetPropertyType(PropertiesParam props, StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1160
bool HasProperty(StringParam name)
Return whether a property exists in a group of properties.
Definition: SDL3pp_properties.h:1142
void * GetPointerProperty(StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition: SDL3pp_properties.h:1208
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:914
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition: SDL3pp_properties.h:1119
void CopyProperties(PropertiesParam src, PropertiesParam dst)
Copy a group of properties.
Definition: SDL3pp_properties.h:829
Properties CreateProperties()
Create a group of properties.
Definition: SDL3pp_properties.h:804
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition: SDL3pp_properties.h:94
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition: SDL3pp_properties.h:88
auto PROP_NAME_STRING
A generic property for naming things.
Definition: SDL3pp_properties.h:772
void SetPointerProperty(PropertiesParam props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:1004
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition: SDL3pp_properties.h:165
const char * GetStringProperty(PropertiesParam props, StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition: SDL3pp_properties.h:1236
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition: SDL3pp_properties.h:85
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition: SDL3pp_properties.h:97
void Enumerate(EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1416
void SetNumberProperty(PropertiesParam props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition: SDL3pp_properties.h:1060
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition: SDL3pp_properties.h:91
PropertyType GetPropertyType(StringParam name)
Get the type of a property in a group of properties.
Definition: SDL3pp_properties.h:1165
void SetFloatProperty(PropertiesParam props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition: SDL3pp_properties.h:1086
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition: SDL3pp_properties.h:1011
void Destroy()
Destroy a group of properties.
Definition: SDL3pp_properties.h:1468
void SetStringProperty(PropertiesParam props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition: SDL3pp_properties.h:1034
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:121
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:1335
void ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition: SDL3pp_properties.h:1363
void EnumerateProperties(PropertiesParam props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition: SDL3pp_properties.h:1383
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition: SDL3pp_properties.h:1463
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition: SDL3pp_properties.h:785
::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 PropertiesParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_properties.h:63
constexpr auto operator<=>(const PropertiesParam &other) const =default
Comparison.
constexpr PropertiesParam(PropertiesID value)
Constructs from PropertiesID.
Definition: SDL3pp_properties.h:57
PropertiesID value
parameter's PropertiesID
Definition: SDL3pp_properties.h:54
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:711
PropertiesRef(const PropertiesRef &other) noexcept
Copy constructor.
Definition: SDL3pp_properties.h:739
PropertiesRef(PropertiesParam resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:721
~PropertiesRef()
Destructor.
Definition: SDL3pp_properties.h:745
PropertiesRef(PropertiesID resource) noexcept
Constructs from PropertiesParam.
Definition: SDL3pp_properties.h:733