SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_properties.h
1#ifndef SDL3PP_PROPERTIES_H_
2#define SDL3PP_PROPERTIES_H_
3
4#include <optional>
5#include <variant>
6#include <SDL3/SDL_properties.h>
7#include "SDL3pp_callbackWrapper.h"
8#include "SDL3pp_error.h"
9#include "SDL3pp_resource.h"
10#include "SDL3pp_strings.h"
11#include "SDL3pp_version.h"
12
13namespace SDL {
14
40
41// Forward decl
42struct PropertiesBase;
43
44// Forward decl
45struct Properties;
46
48using PropertiesID = SDL_PropertiesID;
49
56
57// Forward decl
58struct PropertiesLock;
59
65using PropertyType = SDL_PropertyType;
66
68 SDL_PROPERTY_TYPE_INVALID;
69
71 SDL_PROPERTY_TYPE_POINTER;
72
74 SDL_PROPERTY_TYPE_STRING;
75
77 SDL_PROPERTY_TYPE_NUMBER;
78
79constexpr PropertyType PROPERTY_TYPE_FLOAT = SDL_PROPERTY_TYPE_FLOAT;
80
82 SDL_PROPERTY_TYPE_BOOLEAN;
83
84// Forward decl
85struct PropertyProxy;
86
87// Forward decl
89
90// Forward decl
91struct PropertyIterator;
92
94template<class T>
96 std::convertible_to<T, const PropertyProxy&> ||
97 std::convertible_to<T, void*> || std::convertible_to<T, StringParam> ||
98 std::convertible_to<T, Sint64> || std::convertible_to<T, float>;
99
117using EnumeratePropertiesCallback = void(SDLCALL*)(void* userdata,
118 PropertiesID props,
119 const char* name);
120
140 std::function<void(PropertiesID props, const char* name)>;
141
164using CleanupPropertyCallback = void(SDLCALL*)(void* userdata, void* value);
165
189using CleanupPropertyCB = std::function<void(void* value)>;
190
196struct PropertiesBase : ResourceBaseT<PropertiesID>
197{
199
214 void Destroy();
215
223
229 PropertyIterator begin() const;
230
236 std::nullptr_t end() const;
237
245
263 void Copy(PropertiesRef dst);
264
286
296 void Unlock(PropertiesLock&& lock);
297
306 template<PropertyValue V>
307 void Set(StringParam name, V&& value);
308
338 void* value,
340 void* userdata);
341
370 void* value,
371 CleanupPropertyCB cleanup);
372
393 void SetPointerProperty(StringParam name, void* value);
394
412 void SetStringProperty(StringParam name, StringParam value);
413
427 void SetNumberProperty(StringParam name, Sint64 value);
428
442 void SetFloatProperty(StringParam name, float value);
443
457 void SetBooleanProperty(StringParam name, bool value);
458
471 bool HasProperty(StringParam name) const;
472
487
494 PropertyProxy Get(StringParam name) const;
495
526 void* default_value = nullptr) const;
527
548 const char* GetStringProperty(StringParam name,
549 StringParam default_value = "") const;
550
570 Sint64 GetNumberProperty(StringParam name, Sint64 default_value = 0) const;
571
591 float GetFloatProperty(StringParam name, float default_value = 0) const;
592
612 bool GetBooleanProperty(StringParam name, bool default_value = false) const;
613
624 void ClearProperty(StringParam name);
625
640 void Enumerate(EnumeratePropertiesCallback callback, void* userdata) const;
641
655 void Enumerate(EnumeratePropertiesCB callback) const;
656
664 Uint64 GetCount() const;
665};
666
678{
679 using PropertiesBase::PropertiesBase;
680
688 constexpr explicit Properties(PropertiesID resource) noexcept
689 : PropertiesBase(resource)
690 {
691 }
692
694 constexpr Properties(Properties&& other) noexcept
695 : Properties(other.release())
696 {
697 }
698
714 Properties();
715
734 std::initializer_list<
735 std::pair<StringParam,
736 std::variant<StringParam, void*, Sint64, float, bool>>> entries)
737 : Properties()
738 {
739 for (auto& [name, value] : entries) {
740 std::visit(
741 [this, &name](auto& arg) {
742 if constexpr (std::is_convertible_v<decltype(arg),
743 const StringParam&>) {
744 Set(name.c_str(), arg.c_str());
745 } else {
746 Set(name.c_str(), arg);
747 }
748 },
749 value);
750 }
751 }
752
754 ~Properties() { SDL_DestroyProperties(get()); }
755
757 constexpr Properties& operator=(Properties&& other) noexcept
758 {
759 swap(*this, other);
760 return *this;
761 }
762};
763
787{
788 PropertiesRef m_lock;
789
790public:
814
816 PropertiesLock(const PropertiesLock& other) = delete;
817
820 : m_lock(std::move(other.m_lock))
821 {
822 }
823
834
835 PropertiesLock& operator=(const PropertiesLock& other) = delete;
836
839 {
840 std::swap(m_lock, other.m_lock);
841 return *this;
842 }
843
845 constexpr operator bool() const { return bool(m_lock); }
846
856 void reset();
857
859 PropertiesRef resource() const { return m_lock; }
860
862 void release() { m_lock.release(); }
863};
864
867{
868public:
871 : m_props(props)
872 , m_name(name)
873 {
874 }
875
877 bool IsValid() const { return m_props.HasProperty(m_name.c_str()); }
878
881 {
882 return m_props.GetPropertyType(m_name.c_str());
883 }
884
886 const char* GetName() const { return m_name; }
887
889 PropertiesRef GetProperties() const { return m_props; }
890
892 operator void*() const { return m_props.GetPointerProperty(m_name.c_str()); }
893
895 operator const char*() const
896 {
897 return m_props.GetStringProperty(m_name.c_str());
898 }
899
901 template<std::integral T>
902 operator T() const
903 {
904 return T(m_props.GetNumberProperty(m_name.c_str()));
905 }
906
908 operator float() const { return m_props.GetFloatProperty(m_name.c_str()); }
909
911 operator bool() const { return m_props.GetBooleanProperty(m_name.c_str()); }
912
914 template<class T>
915 auto visit(T visitor) const
916 {
917 switch (GetType()) {
918 case SDL_PROPERTY_TYPE_POINTER: return visitor((void*)(*this));
919 case SDL_PROPERTY_TYPE_STRING: return visitor((const char*)(*this));
920 case SDL_PROPERTY_TYPE_NUMBER: return visitor(Sint64(*this));
921 case SDL_PROPERTY_TYPE_FLOAT: return visitor(float(*this));
922 case SDL_PROPERTY_TYPE_BOOLEAN: return visitor(bool(*this));
923 default: return visitor(std::nullopt);
924 }
925 }
926
927private:
928 PropertiesRef m_props;
929
930 StringParam m_name;
931
932 friend class PropertyIterator;
933};
934
937{
939
941 template<PropertyValue V>
943 {
944 GetProperties().Set(GetName(), std::forward<V>(value));
945 return *this;
946 }
947};
948
951{
952public:
954 constexpr PropertyIterator() = default;
955
957 PropertyIterator(PropertiesRef props, size_t index = 0)
958 : m_index(index)
959 {
960 props.Enumerate(
961 [this](auto, const char* key) { m_keys.emplace_back(key); });
962 if (m_index < m_keys.size()) m_proxy = {props, m_keys[m_index]};
963 }
964
965 ~PropertyIterator() = default;
966
968 constexpr bool operator==(std::nullptr_t) const
969 {
970 return m_index >= m_keys.size();
971 }
972
974 constexpr bool operator==(const PropertyIterator& other) const
975 {
976 return m_index == other.m_index;
977 }
978
980 const PropertyProxy& operator*() const { return m_proxy; }
981
983 const PropertyProxy* operator->() const { return &m_proxy; }
984
987 {
988 ++m_index;
989 update();
990 return *this;
991 }
992
995 {
996 auto copy = *this;
997 ++(*this);
998 return copy;
999 }
1000
1003 {
1004 --m_index;
1005 update();
1006 return *this;
1007 }
1008
1011 {
1012 auto copy = *this;
1013 --(*this);
1014 return copy;
1015 }
1016
1017private:
1018 std::vector<std::string> m_keys;
1019 PropertyProxy m_proxy{{}, ""};
1020 size_t m_index = 0;
1021
1022 void update()
1023 {
1024 if (m_index < m_keys.size()) m_proxy.m_name = m_keys[m_index];
1025 }
1026};
1027
1028#if SDL_VERSION_ATLEAST(3, 4, 0)
1029
1052constexpr const char* PROP_NAME_STRING = SDL_PROP_NAME_STRING;
1053
1054#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1055
1068{
1069 return {CheckError(SDL_GetGlobalProperties())};
1070}
1071
1088
1090 : Properties(CheckError(SDL_CreateProperties()))
1091{
1092}
1093
1113{
1114 CheckError(SDL_CopyProperties(src, dst));
1115}
1116
1118{
1119 SDL::CopyProperties(get(), dst);
1120}
1121
1144{
1145 CheckError(SDL_LockProperties(props));
1146}
1147
1149
1151 : m_lock(resource)
1152{
1153 LockProperties(m_lock);
1154}
1155
1168{
1169 SDL_UnlockProperties(props);
1170}
1171
1173{
1174 SDL_assert_paranoid(lock.resource() == *this);
1175 std::move(lock).reset();
1176}
1177
1179{
1180 if (!m_lock) return;
1181 UnlockProperties(m_lock);
1182 m_lock = {};
1183}
1184
1186{
1187 return {*this, name};
1188}
1189
1191{
1192 return {*this, name};
1193}
1194
1195inline PropertyIterator PropertiesBase::begin() const { return {*this}; }
1196
1197inline std::nullptr_t PropertiesBase::end() const { return nullptr; }
1198
1208template<PropertyValue V>
1209inline void SetProperty(PropertiesRef props, StringParam name, V&& value)
1210{
1211 if constexpr (std::is_same_v<V, bool>) {
1212 props.SetBooleanProperty(name, std::forward<V>(value));
1213 } else if constexpr (std::is_integral_v<V>) {
1214 props.SetNumberProperty(name, std::forward<V>(value));
1215 } else {
1216 struct Visitor
1217 {
1218 PropertiesRef props;
1219 StringParam name;
1220
1221 void operator()(std::monostate) { props.ClearProperty(name); }
1222 void operator()(std::nullopt_t) { props.ClearProperty(name); }
1223 void operator()(void* v) { props.SetPointerProperty(name, v); }
1224
1225 void operator()(StringParam v) { props.SetStringProperty(name, v); }
1226 void operator()(const char* v) { props.SetStringProperty(name, v); }
1227
1228 void operator()(Sint64 v) { props.SetNumberProperty(name, v); }
1229 void operator()(float v) { props.SetFloatProperty(name, v); }
1230 void operator()(bool v) { props.SetBooleanProperty(name, v); }
1231
1232 void operator()(const PropertyProxy& prop)
1233 {
1234 prop.visit([this](auto v) { (*this)(v); });
1235 }
1236 };
1237 Visitor{props, name}(std::forward<V>(value));
1238 }
1239}
1240
1241template<PropertyValue V>
1242inline void PropertiesBase::Set(StringParam name, V&& value)
1243{
1244 SDL::SetProperty(get(), name, std::forward<V>(value));
1245}
1246
1277 StringParam name,
1278 void* value,
1280 void* userdata)
1281{
1282 CheckError(
1283 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
1284}
1285
1315 StringParam name,
1316 void* value,
1317 CleanupPropertyCB cleanup)
1318{
1319 using Wrapper = CallbackWrapper<CleanupPropertyCB>;
1320 SDL_SetPointerPropertyWithCleanup(
1321 props, name, value, &Wrapper::CallOnce, Wrapper::Wrap(std::move(cleanup)));
1322}
1323
1325 StringParam name,
1326 void* value,
1328 void* userdata)
1329{
1330 SDL::SetPointerPropertyWithCleanup(get(), name, value, cleanup, userdata);
1331}
1332
1334 StringParam name,
1335 void* value,
1336 CleanupPropertyCB cleanup)
1337{
1338 SDL::SetPointerPropertyWithCleanup(get(), name, value, std::move(cleanup));
1339}
1340
1363 StringParam name,
1364 void* value)
1365{
1366 CheckError(SDL_SetPointerProperty(props, name, value));
1367}
1368
1370{
1371 SDL::SetPointerProperty(get(), name, value);
1372}
1373
1393 StringParam name,
1394 StringParam value)
1395{
1396 CheckError(SDL_SetStringProperty(props, name, value));
1397}
1398
1400 StringParam value)
1401{
1402 SDL::SetStringProperty(get(), name, value);
1403}
1404
1420 StringParam name,
1421 Sint64 value)
1422{
1423 CheckError(SDL_SetNumberProperty(props, name, value));
1424}
1425
1427{
1428 SDL::SetNumberProperty(get(), name, value);
1429}
1430
1445inline void SetFloatProperty(PropertiesRef props, StringParam name, float value)
1446{
1447 CheckError(SDL_SetFloatProperty(props, name, value));
1448}
1449
1450inline void PropertiesBase::SetFloatProperty(StringParam name, float value)
1451{
1452 SDL::SetFloatProperty(get(), name, value);
1453}
1454
1470 StringParam name,
1471 bool value)
1472{
1473 CheckError(SDL_SetBooleanProperty(props, name, value));
1474}
1475
1477{
1478 SDL::SetBooleanProperty(get(), name, value);
1479}
1480
1494inline bool HasProperty(PropertiesRef props, StringParam name)
1495{
1496 return SDL_HasProperty(props, name);
1497}
1498
1500{
1501 return SDL::HasProperty(get(), name);
1502}
1503
1518{
1519 return SDL_GetPropertyType(props, name);
1520}
1521
1523{
1524 return SDL::GetPropertyType(get(), name);
1525}
1526
1535{
1536 return {props, name};
1537}
1538
1540{
1541 return SDL::GetProperty(get(), name);
1542}
1543
1575 StringParam name,
1576 void* default_value = nullptr)
1577{
1578 return SDL_GetPointerProperty(props, name, default_value);
1579}
1580
1582 void* default_value) const
1583{
1584 return SDL::GetPointerProperty(get(), name, default_value);
1585}
1586
1608inline const char* GetStringProperty(PropertiesRef props,
1609 StringParam name,
1610 StringParam default_value = "")
1611{
1612 return SDL_GetStringProperty(props, name, default_value);
1613}
1614
1616 StringParam name,
1617 StringParam default_value) const
1618{
1619 return SDL::GetStringProperty(get(), name, default_value);
1620}
1621
1643 StringParam name,
1644 Sint64 default_value = 0)
1645{
1646 return SDL_GetNumberProperty(props, name, default_value);
1647}
1648
1650 Sint64 default_value) const
1651{
1652 return SDL::GetNumberProperty(get(), name, default_value);
1653}
1654
1676 StringParam name,
1677 float default_value = 0)
1678{
1679 return SDL_GetFloatProperty(props, name, default_value);
1680}
1681
1683 float default_value) const
1684{
1685 return SDL::GetFloatProperty(get(), name, default_value);
1686}
1687
1709 StringParam name,
1710 bool default_value = false)
1711{
1712 return SDL_GetBooleanProperty(props, name, default_value);
1713}
1714
1716 bool default_value) const
1717{
1718 return SDL::GetBooleanProperty(get(), name, default_value);
1719}
1720
1733{
1734 CheckError(SDL_ClearProperty(props, name));
1735}
1736
1738{
1739 SDL::ClearProperty(get(), name);
1740}
1741
1759 void* userdata)
1760{
1761 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1762}
1763
1779 EnumeratePropertiesCB callback)
1780{
1781 return EnumerateProperties(
1782 props,
1783 [](void* userdata, PropertiesID props, const char* name) {
1784 auto& f = *static_cast<const EnumeratePropertiesCB*>(userdata);
1785 f(props, name);
1786 },
1787 &callback);
1788}
1789
1791 void* userdata) const
1792{
1793 SDL::EnumerateProperties(get(), callback, userdata);
1794}
1795
1797{
1798 SDL::EnumerateProperties(get(), std::move(callback));
1799}
1800
1810{
1811 Uint64 count = 0;
1812 EnumerateProperties(props, [&count](auto, const char*) { count++; });
1813 return count;
1814}
1815
1817{
1818 return SDL::CountProperties(get());
1819}
1820
1838{
1839 SDL_DestroyProperties(props);
1840}
1841
1843
1845
1856
1857} // namespace SDL
1858
1859#endif /* SDL3PP_PROPERTIES_H_ */
Lock a group of properties.
Definition SDL3pp_properties.h:787
~PropertiesLock()
Unlock a group of properties.
Definition SDL3pp_properties.h:833
PropertiesLock(const PropertiesLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition SDL3pp_properties.h:862
PropertiesRef resource() const
Get the reference to locked resource.
Definition SDL3pp_properties.h:859
PropertiesLock(PropertiesLock &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:819
PropertiesLock & operator=(PropertiesLock &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:838
Iterator for properties in a Properties set.
Definition SDL3pp_properties.h:951
PropertyIterator operator--(int)
Post-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1010
constexpr PropertyIterator()=default
Default constructor.
PropertyIterator & operator--()
Pre-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1002
constexpr bool operator==(const PropertyIterator &other) const
Comparison operator.
Definition SDL3pp_properties.h:974
PropertyIterator(PropertiesRef props, size_t index=0)
Constructor.
Definition SDL3pp_properties.h:957
const PropertyProxy & operator*() const
Dereference operator to get the current property proxy.
Definition SDL3pp_properties.h:980
PropertyIterator operator++(int)
Post-increment operator to move to the next property.
Definition SDL3pp_properties.h:994
const PropertyProxy * operator->() const
Arrow operator to get a pointer to the current property proxy.
Definition SDL3pp_properties.h:983
PropertyIterator & operator++()
Pre-increment operator to move to the next property.
Definition SDL3pp_properties.h:986
constexpr bool operator==(std::nullptr_t) const
Comparison with nullptr, to check if the iterator is at the end.
Definition SDL3pp_properties.h:968
Represent a property name from a given Properties.
Definition SDL3pp_properties.h:867
PropertiesRef GetProperties() const
Get the property group this proxy belongs to.
Definition SDL3pp_properties.h:889
const char * GetName() const
Get Property name.
Definition SDL3pp_properties.h:886
PropertyProxy(PropertiesRef props, StringParam name)
Constructor.
Definition SDL3pp_properties.h:870
bool IsValid() const
True if the there is a property with this name.
Definition SDL3pp_properties.h:877
PropertyType GetType() const
Get Property type.
Definition SDL3pp_properties.h:880
auto visit(T visitor) const
Call visitor with the correct type based on its GetType().
Definition SDL3pp_properties.h:915
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:58
A value assignable to a property.
Definition SDL3pp_properties.h:95
#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:81
PropertiesLock(PropertiesRef resource)
Lock a group of properties.
Definition SDL3pp_properties.h:1150
Uint64 GetCount() const
Returns the number of properties this has.
Definition SDL3pp_properties.h:1816
void ClearProperty(PropertiesRef props, StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1732
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:189
Uint64 CountProperties(PropertiesRef props)
Returns the number of properties this has.
Definition SDL3pp_properties.h:1809
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1426
bool GetBooleanProperty(StringParam name, bool default_value=false) const
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1715
bool GetBooleanProperty(PropertiesRef props, StringParam name, bool default_value=false)
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1708
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:164
constexpr const char * PROP_NAME_STRING
A generic property for naming things.
Definition SDL3pp_properties.h:1052
void LockProperties(PropertiesRef props)
Lock a group of properties.
Definition SDL3pp_properties.h:1143
void EnumerateProperties(PropertiesRef props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1757
void * GetPointerProperty(StringParam name, void *default_value=nullptr) const
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1581
PropertyProxy GetProperty(PropertiesRef props, StringParam name)
Get a property from a group of properties.
Definition SDL3pp_properties.h:1534
const char * GetStringProperty(PropertiesRef props, StringParam name, StringParam default_value="")
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1608
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:1276
void SetFloatProperty(PropertiesRef props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1445
PropertiesLock Lock()
Lock a group of properties.
Definition SDL3pp_properties.h:1148
void SetBooleanProperty(PropertiesRef props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1469
PropertyProxy operator[](StringParam name) const
Access a property from a group of properties.
Definition SDL3pp_properties.h:1185
Properties()
Create a group of properties.
Definition SDL3pp_properties.h:1089
float GetFloatProperty(PropertiesRef props, StringParam name, float default_value=0)
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1675
PropertyIterator begin() const
Gets an iterator to the first property in a group of properties.
Definition SDL3pp_properties.h:1195
std::nullptr_t end() const
Gets sentinel iterator for a group of properties.
Definition SDL3pp_properties.h:1197
const char * GetStringProperty(StringParam name, StringParam default_value="") const
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1615
PropertyType GetPropertyType(StringParam name) const
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1522
Properties CreateProperties()
Create a group of properties.
Definition SDL3pp_properties.h:1087
void SetNumberProperty(PropertiesRef props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1419
void Set(StringParam name, V &&value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1242
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition SDL3pp_properties.h:76
void CopyProperties(PropertiesRef src, PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:1112
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition SDL3pp_properties.h:70
void SetStringProperty(PropertiesRef props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1392
bool HasProperty(PropertiesRef props, StringParam name)
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1494
Sint64 GetNumberProperty(PropertiesRef props, StringParam name, Sint64 default_value=0)
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1642
PropertyType GetPropertyType(PropertiesRef props, StringParam name)
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1517
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 ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1737
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition SDL3pp_properties.h:67
void UnlockProperties(PropertiesRef props)
Unlock a group of properties.
Definition SDL3pp_properties.h:1167
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition SDL3pp_properties.h:79
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition SDL3pp_properties.h:73
void Destroy()
Destroy a group of properties.
Definition SDL3pp_properties.h:1842
void Copy(PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:1117
float GetFloatProperty(StringParam name, float default_value=0) const
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1682
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition SDL3pp_properties.h:48
Sint64 GetNumberProperty(StringParam name, Sint64 default_value=0) const
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1649
void SetPointerProperty(PropertiesRef props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1362
void SetProperty(PropertiesRef props, StringParam name, V &&value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1209
void Enumerate(EnumeratePropertiesCallback callback, void *userdata) const
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1790
void reset()
Unlock a group of properties.
Definition SDL3pp_properties.h:1178
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1476
SDL_PropertyType PropertyType
SDL property type.
Definition SDL3pp_properties.h:65
void * GetPointerProperty(PropertiesRef props, StringParam name, void *default_value=nullptr)
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1574
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1450
void Unlock(PropertiesLock &&lock)
Unlock a group of properties.
Definition SDL3pp_properties.h:1172
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:1324
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1369
PropertyProxy Get(StringParam name) const
Get a property from a group of properties.
Definition SDL3pp_properties.h:1539
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:117
bool HasProperty(StringParam name) const
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1499
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:55
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1399
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition SDL3pp_properties.h:1837
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition SDL3pp_properties.h:1067
::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
Constants for Properties keys.
Definition SDL3pp_audio.h:3778
Main include header for the SDL3pp library.
Definition SDL3pp_callbackWrapper.h:20
Base class to Properties.
Definition SDL3pp_properties.h:197
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An ID that represents a properties set.
Definition SDL3pp_properties.h:678
constexpr Properties & operator=(Properties &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:757
~Properties()
Destructor.
Definition SDL3pp_properties.h:754
constexpr Properties(PropertiesID resource) noexcept
Constructs from raw Properties.
Definition SDL3pp_properties.h:688
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:694
Properties(std::initializer_list< std::pair< StringParam, std::variant< StringParam, void *, Sint64, float, bool > > > entries)
Create a group of properties.
Definition SDL3pp_properties.h:733
Represent a mutable property name from a given Properties.
Definition SDL3pp_properties.h:937
PropertyMutableProxy & operator=(V &&value)
Change the value of this property.
Definition SDL3pp_properties.h:942
PropertyProxy(PropertiesRef props, StringParam name)
Constructor.
Definition SDL3pp_properties.h:870
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93