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_resource.h"
8#include "SDL3pp_strings.h"
9#include "SDL3pp_version.h"
66 SDL_PROPERTY_TYPE_INVALID;
69 SDL_PROPERTY_TYPE_POINTER;
72 SDL_PROPERTY_TYPE_STRING;
75 SDL_PROPERTY_TYPE_NUMBER;
80 SDL_PROPERTY_TYPE_BOOLEAN;
122 std::function<void(
PropertiesID props,
const char* name)>;
610 using PropertiesBase::PropertiesBase;
714 : m_lock(std::move(other.m_lock))
734 std::swap(m_lock, other.m_lock);
739 constexpr operator bool()
const {
return bool(m_lock); }
759#if SDL_VERSION_ATLEAST(3, 4, 0)
800 return {
CheckError(SDL_GetGlobalProperties())};
900 SDL_UnlockProperties(props);
906 std::move(lock).reset();
952 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
989 SDL_SetPointerPropertyWithCleanup(props,
993 Wrapper::Wrap(std::move(cleanup)));
1003 get(), std::move(name), value, cleanup, userdata);
1012 get(), std::move(name), value, std::move(cleanup));
1040 CheckError(SDL_SetPointerProperty(props, name, value));
1070 CheckError(SDL_SetStringProperty(props, name, value));
1097 CheckError(SDL_SetNumberProperty(props, name, value));
1121 CheckError(SDL_SetFloatProperty(props, name, value));
1147 CheckError(SDL_SetBooleanProperty(props, name, value));
1170 return SDL_HasProperty(props, name);
1193 return SDL_GetPropertyType(props, name);
1233 void* default_value)
1235 return SDL_GetPointerProperty(props, name, default_value);
1239 void* default_value)
1269 return SDL_GetStringProperty(props, name, default_value);
1276 get(), std::move(name), std::move(default_value));
1303 return SDL_GetNumberProperty(props, name, default_value);
1334 float default_value)
1336 return SDL_GetFloatProperty(props, name, default_value);
1340 float default_value)
1369 return SDL_GetBooleanProperty(props, name, default_value);
1418 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1440 [](
void* userdata,
PropertiesID props,
const char* name) {
1493 SDL_DestroyProperties(props);
Lock a group of properties.
Definition SDL3pp_properties.h:681
~PropertiesLock()
Unlock a group of properties.
Definition SDL3pp_properties.h:727
PropertiesLock(const PropertiesLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition SDL3pp_properties.h:756
PropertiesRef resource() const
Get the reference to locked resource.
Definition SDL3pp_properties.h:753
PropertiesLock(PropertiesLock &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:713
PropertiesLock & operator=(PropertiesLock &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:732
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: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:199
constexpr PropertyType PROPERTY_TYPE_BOOLEAN
BOOLEAN.
Definition SDL3pp_properties.h:79
PropertiesLock(PropertiesRef resource)
Lock a group of properties.
Definition SDL3pp_properties.h:881
void ClearProperty(PropertiesRef props, StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1389
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:171
Uint64 CountProperties(PropertiesRef props)
Returns the number of properties this has.
Definition SDL3pp_properties.h:1466
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1100
bool HasProperty(StringParam name)
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1173
bool GetBooleanProperty(PropertiesRef props, StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1365
const char * GetStringProperty(StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1272
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:146
constexpr const char * PROP_NAME_STRING
A generic property for naming things.
Definition SDL3pp_properties.h:783
void LockProperties(PropertiesRef props)
Lock a group of properties.
Definition SDL3pp_properties.h:874
const char * GetStringProperty(PropertiesRef props, StringParam name, StringParam default_value)
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1265
void EnumerateProperties(PropertiesRef props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1414
void * GetPointerProperty(PropertiesRef props, StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1231
void SetPointerPropertyWithCleanup(PropertiesRef 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:945
void SetFloatProperty(PropertiesRef props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1119
PropertiesLock Lock()
Lock a group of properties.
Definition SDL3pp_properties.h:879
bool GetBooleanProperty(StringParam name, bool default_value)
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1372
void SetBooleanProperty(PropertiesRef props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1143
Properties()
Create a group of properties.
Definition SDL3pp_properties.h:820
void Enumerate(EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1447
Properties CreateProperties()
Create a group of properties.
Definition SDL3pp_properties.h:818
void SetNumberProperty(PropertiesRef props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1093
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition SDL3pp_properties.h:74
void CopyProperties(PropertiesRef src, PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:843
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition SDL3pp_properties.h:68
void SetStringProperty(PropertiesRef props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1066
bool HasProperty(PropertiesRef props, StringParam name)
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1168
PropertyType GetPropertyType(PropertiesRef props, StringParam name)
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1191
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:121
void ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1394
float GetFloatProperty(PropertiesRef props, StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1332
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition SDL3pp_properties.h:65
void * GetPointerProperty(StringParam name, void *default_value)
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1238
void UnlockProperties(PropertiesRef props)
Unlock a group of properties.
Definition SDL3pp_properties.h:898
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition SDL3pp_properties.h:77
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition SDL3pp_properties.h:71
Uint64 GetCount()
Returns the number of properties this has.
Definition SDL3pp_properties.h:1473
void Destroy()
Destroy a group of properties.
Definition SDL3pp_properties.h:1496
float GetFloatProperty(StringParam name, float default_value)
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1339
void Copy(PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:848
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition SDL3pp_properties.h:46
void SetPointerProperty(PropertiesRef props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1036
PropertyType GetPropertyType(StringParam name)
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1196
void reset()
Unlock a group of properties.
Definition SDL3pp_properties.h:909
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1150
SDL_PropertyType PropertyType
SDL property type.
Definition SDL3pp_properties.h:63
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1124
void Unlock(PropertiesLock &&lock)
Unlock a group of properties.
Definition SDL3pp_properties.h:903
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:996
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1043
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:99
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1073
Sint64 GetNumberProperty(StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1306
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition SDL3pp_properties.h:1491
Sint64 GetNumberProperty(PropertiesRef props, StringParam name, Sint64 default_value)
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1299
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition SDL3pp_properties.h:798
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
Main include header for the SDL3pp library.
Definition SDL3pp_callbackWrapper.h:20
Base class to Properties.
Definition SDL3pp_properties.h:179
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An ID that represents a properties set.
Definition SDL3pp_properties.h:609
constexpr Properties & operator=(Properties &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:651
~Properties()
Destructor.
Definition SDL3pp_properties.h:648
constexpr Properties(PropertiesID resource) noexcept
Constructs from raw Properties.
Definition SDL3pp_properties.h:619
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:625
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93