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 <vector>
7#include <SDL3/SDL_properties.h>
8#include "SDL3pp_callbackWrapper.h"
9#include "SDL3pp_error.h"
10#include "SDL3pp_resource.h"
11#include "SDL3pp_strings.h"
12#include "SDL3pp_version.h"
13
14namespace SDL {
15
41
42// Forward decl
43struct PropertiesBase;
44
45// Forward decl
46struct Properties;
47
49using PropertiesID = SDL_PropertiesID;
50
57
58// Forward decl
59struct PropertiesLock;
60
66using PropertyType = SDL_PropertyType;
67
69 SDL_PROPERTY_TYPE_INVALID;
70
72 SDL_PROPERTY_TYPE_POINTER;
73
75 SDL_PROPERTY_TYPE_STRING;
76
78 SDL_PROPERTY_TYPE_NUMBER;
79
80constexpr PropertyType PROPERTY_TYPE_FLOAT = SDL_PROPERTY_TYPE_FLOAT;
81
83 SDL_PROPERTY_TYPE_BOOLEAN;
84
85// Forward decl
86struct PropertyProxy;
87
88// Forward decl
90
91// Forward decl
92struct PropertyIterator;
93
95template<class T>
97 std::convertible_to<T, const PropertyProxy&> ||
98 std::convertible_to<T, void*> || std::convertible_to<T, StringParam> ||
99 std::convertible_to<T, Sint64> || std::convertible_to<T, float>;
100
118using EnumeratePropertiesCallback = void(SDLCALL*)(void* userdata,
119 PropertiesID props,
120 const char* name);
121
141 std::function<void(PropertiesID props, const char* name)>;
142
165using CleanupPropertyCallback = void(SDLCALL*)(void* userdata, void* value);
166
190using CleanupPropertyCB = std::function<void(void* value)>;
191
197struct PropertiesBase : ResourceBaseT<PropertiesID>
198{
200
215 void Destroy();
216
224
230 PropertyIterator begin() const;
231
237 std::nullptr_t end() const;
238
246
264 void Copy(PropertiesRef dst);
265
287
297 void Unlock(PropertiesLock&& lock);
298
307 template<PropertyValue V>
308 void Set(StringParam name, V&& value);
309
339 void* value,
341 void* userdata);
342
371 void* value,
372 CleanupPropertyCB cleanup);
373
394 void SetPointerProperty(StringParam name, void* value);
395
413 void SetStringProperty(StringParam name, StringParam value);
414
428 void SetNumberProperty(StringParam name, Sint64 value);
429
443 void SetFloatProperty(StringParam name, float value);
444
458 void SetBooleanProperty(StringParam name, bool value);
459
472 bool HasProperty(StringParam name) const;
473
488
495 PropertyProxy Get(StringParam name) const;
496
527 void* default_value = nullptr) const;
528
549 const char* GetStringProperty(StringParam name,
550 StringParam default_value = "") const;
551
571 Sint64 GetNumberProperty(StringParam name, Sint64 default_value = 0) const;
572
592 float GetFloatProperty(StringParam name, float default_value = 0) const;
593
613 bool GetBooleanProperty(StringParam name, bool default_value = false) const;
614
625 void ClearProperty(StringParam name);
626
641 void Enumerate(EnumeratePropertiesCallback callback, void* userdata) const;
642
656 void Enumerate(EnumeratePropertiesCB callback) const;
657
665 Uint64 GetCount() const;
666};
667
679{
680 using PropertiesBase::PropertiesBase;
681
689 constexpr explicit Properties(PropertiesID resource) noexcept
690 : PropertiesBase(resource)
691 {
692 }
693
695 constexpr Properties(Properties&& other) noexcept
696 : Properties(other.release())
697 {
698 }
699
715 Properties();
716
735 std::initializer_list<
736 std::pair<StringParam,
737 std::variant<StringParam, void*, Sint64, float, bool>>> entries)
738 : Properties()
739 {
740 for (auto& [name, value] : entries) {
741 std::visit(
742 [this, &name](auto& arg) {
743 if constexpr (std::is_convertible_v<decltype(arg),
744 const StringParam&>) {
745 Set(name.c_str(), arg.c_str());
746 } else {
747 Set(name.c_str(), arg);
748 }
749 },
750 value);
751 }
752 }
753
755 ~Properties() { SDL_DestroyProperties(get()); }
756
758 constexpr Properties& operator=(Properties&& other) noexcept
759 {
760 swap(*this, other);
761 return *this;
762 }
763};
764
788{
789 PropertiesRef m_lock;
790
791public:
815
817 PropertiesLock(const PropertiesLock& other) = delete;
818
821 : m_lock(std::move(other.m_lock))
822 {
823 }
824
835
836 PropertiesLock& operator=(const PropertiesLock& other) = delete;
837
840 {
841 std::swap(m_lock, other.m_lock);
842 return *this;
843 }
844
846 constexpr operator bool() const { return bool(m_lock); }
847
857 void reset();
858
860 PropertiesRef resource() const { return m_lock; }
861
863 void release() { m_lock.release(); }
864};
865
868{
869public:
872 : m_props(props)
873 , m_name(name)
874 {
875 }
876
878 bool IsValid() const { return m_props.HasProperty(m_name.c_str()); }
879
882 {
883 return m_props.GetPropertyType(m_name.c_str());
884 }
885
887 const char* GetName() const { return m_name; }
888
890 PropertiesRef GetProperties() const { return m_props; }
891
893 template<PropertyType T>
894 auto As() const;
895
897 template<PropertyValue T>
898 auto As() const;
899
901 operator void*() const { return m_props.GetPointerProperty(m_name); }
902
904 operator const char*() const { return m_props.GetStringProperty(m_name); }
905
907 template<std::integral T>
908 operator T() const
909 {
910 return T(m_props.GetNumberProperty(m_name));
911 }
912
914 template<std::floating_point T>
915 operator T() const
916 {
917 return T(m_props.GetFloatProperty(m_name));
918 }
919
921 operator bool() const { return m_props.GetBooleanProperty(m_name); }
922
924 template<class T>
925 auto visit(T visitor) const
926 {
927 switch (GetType()) {
928 case SDL_PROPERTY_TYPE_POINTER: return visitor((void*)(*this));
929 case SDL_PROPERTY_TYPE_STRING: return visitor((const char*)(*this));
930 case SDL_PROPERTY_TYPE_NUMBER: return visitor(Sint64(*this));
931 case SDL_PROPERTY_TYPE_FLOAT: return visitor(float(*this));
932 case SDL_PROPERTY_TYPE_BOOLEAN: return visitor(bool(*this));
933 default: return visitor(std::nullopt);
934 }
935 }
936
937private:
938 PropertiesRef m_props;
939
940 StringParam m_name;
941
942 friend class PropertyIterator;
943};
944
947{
949
951 template<PropertyValue V>
953 {
954 GetProperties().Set(GetName(), std::forward<V>(value));
955 return *this;
956 }
957};
958
961{
962public:
964 constexpr PropertyIterator() = default;
965
967 PropertyIterator(PropertiesRef props, size_t index = 0)
968 : m_index(index)
969 {
970 props.Enumerate(
971 [this](auto, const char* key) { m_keys.emplace_back(key); });
972 if (m_index < m_keys.size()) m_proxy = {props, m_keys[m_index]};
973 }
974
975 ~PropertyIterator() = default;
976
978 constexpr bool operator==(std::nullptr_t) const
979 {
980 return m_index >= m_keys.size();
981 }
982
984 constexpr bool operator==(const PropertyIterator& other) const
985 {
986 return m_index == other.m_index;
987 }
988
990 const PropertyProxy& operator*() const { return m_proxy; }
991
993 const PropertyProxy* operator->() const { return &m_proxy; }
994
997 {
998 ++m_index;
999 update();
1000 return *this;
1001 }
1002
1005 {
1006 auto copy = *this;
1007 ++(*this);
1008 return copy;
1009 }
1010
1013 {
1014 --m_index;
1015 update();
1016 return *this;
1017 }
1018
1021 {
1022 auto copy = *this;
1023 --(*this);
1024 return copy;
1025 }
1026
1027private:
1028 std::vector<std::string> m_keys;
1029 PropertyProxy m_proxy{{}, ""};
1030 size_t m_index = 0;
1031
1032 void update()
1033 {
1034 if (m_index < m_keys.size()) m_proxy.m_name = m_keys[m_index];
1035 }
1036};
1037
1038#if SDL_VERSION_ATLEAST(3, 4, 0)
1039
1062constexpr const char* PROP_NAME_STRING = SDL_PROP_NAME_STRING;
1063
1064#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1065
1078{
1079 return {CheckError(SDL_GetGlobalProperties())};
1080}
1081
1098
1100 : Properties(CheckError(SDL_CreateProperties()))
1101{
1102}
1103
1123{
1124 CheckError(SDL_CopyProperties(src, dst));
1125}
1126
1128{
1129 SDL::CopyProperties(get(), dst);
1130}
1131
1154{
1155 CheckError(SDL_LockProperties(props));
1156}
1157
1159
1161 : m_lock(resource)
1162{
1163 LockProperties(m_lock);
1164}
1165
1178{
1179 SDL_UnlockProperties(props);
1180}
1181
1183{
1184 SDL_assert_paranoid(lock.resource() == *this);
1185 std::move(lock).reset();
1186}
1187
1189{
1190 if (!m_lock) return;
1191 UnlockProperties(m_lock);
1192 m_lock = {};
1193}
1194
1196{
1197 return {*this, name};
1198}
1199
1201{
1202 return {*this, name};
1203}
1204
1205inline PropertyIterator PropertiesBase::begin() const { return {*this}; }
1206
1207inline std::nullptr_t PropertiesBase::end() const { return nullptr; }
1208
1218template<PropertyValue V>
1219inline void SetProperty(PropertiesRef props, StringParam name, V value)
1220{
1221 struct
1222 {
1223 PropertiesRef props;
1224 StringParam name;
1225
1226 void operator()(std::nullopt_t) { props.ClearProperty(name); }
1227 void operator()(void* v) { props.SetPointerProperty(name, v); }
1228 void operator()(const char* v) { props.SetStringProperty(name, v); }
1229 void operator()(Sint64 v) { props.SetNumberProperty(name, v); }
1230 void operator()(float v) { props.SetFloatProperty(name, v); }
1231 void operator()(bool v) { props.SetBooleanProperty(name, v); }
1232 void operator()(const PropertyProxy& prop) { prop.visit(*this); }
1233
1234 } visitor(props, name);
1235 if constexpr (std::is_same_v<V, bool>) {
1236 visitor(value);
1237 } else if constexpr (std::integral<V>) {
1238 visitor(Sint64(value));
1239 } else if constexpr (std::floating_point<V>) {
1240 visitor(float(value));
1241 } else if constexpr (std::convertible_to<V, StringParam>) {
1242 visitor(StringParam(value));
1243 } else {
1244 visitor(value);
1245 }
1246}
1247
1248template<PropertyValue V>
1249inline void PropertiesBase::Set(StringParam name, V&& value)
1250{
1251 SDL::SetProperty(get(), name, std::forward<V>(value));
1252}
1253
1284 StringParam name,
1285 void* value,
1287 void* userdata)
1288{
1289 CheckError(
1290 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
1291}
1292
1322 StringParam name,
1323 void* value,
1324 CleanupPropertyCB cleanup)
1325{
1326 using Wrapper = CallbackWrapper<CleanupPropertyCB>;
1327 SDL_SetPointerPropertyWithCleanup(
1328 props, name, value, &Wrapper::CallOnce, Wrapper::Wrap(std::move(cleanup)));
1329}
1330
1332 StringParam name,
1333 void* value,
1335 void* userdata)
1336{
1337 SDL::SetPointerPropertyWithCleanup(get(), name, value, cleanup, userdata);
1338}
1339
1341 StringParam name,
1342 void* value,
1343 CleanupPropertyCB cleanup)
1344{
1345 SDL::SetPointerPropertyWithCleanup(get(), name, value, std::move(cleanup));
1346}
1347
1370 StringParam name,
1371 void* value)
1372{
1373 CheckError(SDL_SetPointerProperty(props, name, value));
1374}
1375
1377{
1378 SDL::SetPointerProperty(get(), name, value);
1379}
1380
1400 StringParam name,
1401 StringParam value)
1402{
1403 CheckError(SDL_SetStringProperty(props, name, value));
1404}
1405
1407 StringParam value)
1408{
1409 SDL::SetStringProperty(get(), name, value);
1410}
1411
1427 StringParam name,
1428 Sint64 value)
1429{
1430 CheckError(SDL_SetNumberProperty(props, name, value));
1431}
1432
1434{
1435 SDL::SetNumberProperty(get(), name, value);
1436}
1437
1452inline void SetFloatProperty(PropertiesRef props, StringParam name, float value)
1453{
1454 CheckError(SDL_SetFloatProperty(props, name, value));
1455}
1456
1457inline void PropertiesBase::SetFloatProperty(StringParam name, float value)
1458{
1459 SDL::SetFloatProperty(get(), name, value);
1460}
1461
1477 StringParam name,
1478 bool value)
1479{
1480 CheckError(SDL_SetBooleanProperty(props, name, value));
1481}
1482
1484{
1485 SDL::SetBooleanProperty(get(), name, value);
1486}
1487
1501inline bool HasProperty(PropertiesRef props, StringParam name)
1502{
1503 return SDL_HasProperty(props, name);
1504}
1505
1507{
1508 return SDL::HasProperty(get(), name);
1509}
1510
1525{
1526 return SDL_GetPropertyType(props, name);
1527}
1528
1530{
1531 return SDL::GetPropertyType(get(), name);
1532}
1533
1542{
1543 return {props, name};
1544}
1545
1547{
1548 return SDL::GetProperty(get(), name);
1549}
1550
1582 StringParam name,
1583 void* default_value = nullptr)
1584{
1585 return SDL_GetPointerProperty(props, name, default_value);
1586}
1587
1589 void* default_value) const
1590{
1591 return SDL::GetPointerProperty(get(), name, default_value);
1592}
1593
1615inline const char* GetStringProperty(PropertiesRef props,
1616 StringParam name,
1617 StringParam default_value = "")
1618{
1619 return SDL_GetStringProperty(props, name, default_value);
1620}
1621
1623 StringParam name,
1624 StringParam default_value) const
1625{
1626 return SDL::GetStringProperty(get(), name, default_value);
1627}
1628
1650 StringParam name,
1651 Sint64 default_value = 0)
1652{
1653 return SDL_GetNumberProperty(props, name, default_value);
1654}
1655
1657 Sint64 default_value) const
1658{
1659 return SDL::GetNumberProperty(get(), name, default_value);
1660}
1661
1683 StringParam name,
1684 float default_value = 0)
1685{
1686 return SDL_GetFloatProperty(props, name, default_value);
1687}
1688
1690 float default_value) const
1691{
1692 return SDL::GetFloatProperty(get(), name, default_value);
1693}
1694
1716 StringParam name,
1717 bool default_value = false)
1718{
1719 return SDL_GetBooleanProperty(props, name, default_value);
1720}
1721
1723 bool default_value) const
1724{
1725 return SDL::GetBooleanProperty(get(), name, default_value);
1726}
1727
1729template<PropertyType T>
1731{
1732 if constexpr (T == PROPERTY_TYPE_POINTER) {
1733 return GetPointerProperty(props, name);
1734 } else if constexpr (T == PROPERTY_TYPE_STRING) {
1735 return GetStringProperty(props, name);
1736 } else if constexpr (T == PROPERTY_TYPE_NUMBER) {
1737 return GetNumberProperty(props, name);
1738 } else if constexpr (T == PROPERTY_TYPE_FLOAT) {
1739 return GetFloatProperty(props, name);
1740 } else {
1741 static_assert(T == PROPERTY_TYPE_BOOLEAN, "Invalid Property type");
1742 return GetBooleanProperty(props, name);
1743 }
1744}
1745
1747template<PropertyValue T>
1749{
1750 if constexpr (std::is_same_v<T, bool>) {
1751 return GetBooleanProperty(props, name);
1752 } else if constexpr (std::integral<T>) {
1753 return static_cast<T>(GetNumberProperty(props, name));
1754 } else if constexpr (std::floating_point<T>) {
1755 return static_cast<T>(GetFloatProperty(props, name));
1756 } else if constexpr (std::is_same_v<T, char*>) {
1757 return GetStringProperty(props, name);
1758 } else if constexpr (std::convertible_to<T, StringParam>) {
1759 return static_cast<T>(GetStringProperty(props, name));
1760 } else if constexpr (std::convertible_to<T, void*>) {
1761 return static_cast<T>(GetPointerProperty(props, name));
1762 } else {
1763 static_assert(std::convertible_to<PropertyProxy, T>, "invalid type");
1764 return static_cast<T>(PropertyProxy(props, name));
1765 }
1766}
1767
1769template<PropertyType T>
1771{
1772 return prop_cast<T>(prop.GetProperties(), prop.GetName());
1773}
1774
1776template<PropertyValue T>
1778{
1779 return prop_cast<T>(prop.GetProperties(), prop.GetName());
1780}
1781
1783template<PropertyType T>
1785{
1786 return prop_cast<T>(m_props, m_name);
1787}
1788
1790template<PropertyValue T>
1791auto PropertyProxy::As() const
1792{
1793 return prop_cast<T>(m_props, m_name);
1794}
1795
1808{
1809 CheckError(SDL_ClearProperty(props, name));
1810}
1811
1813{
1814 SDL::ClearProperty(get(), name);
1815}
1816
1834 void* userdata)
1835{
1836 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1837}
1838
1854 EnumeratePropertiesCB callback)
1855{
1856 return EnumerateProperties(
1857 props,
1858 [](void* userdata, PropertiesID props, const char* name) {
1859 auto& f = *static_cast<const EnumeratePropertiesCB*>(userdata);
1860 f(props, name);
1861 },
1862 &callback);
1863}
1864
1866 void* userdata) const
1867{
1868 SDL::EnumerateProperties(get(), callback, userdata);
1869}
1870
1872{
1873 SDL::EnumerateProperties(get(), std::move(callback));
1874}
1875
1885{
1886 Uint64 count = 0;
1887 EnumerateProperties(props, [&count](auto, const char*) { count++; });
1888 return count;
1889}
1890
1892{
1893 return SDL::CountProperties(get());
1894}
1895
1913{
1914 SDL_DestroyProperties(props);
1915}
1916
1918
1920
1931
1932} // namespace SDL
1933
1934#endif /* SDL3PP_PROPERTIES_H_ */
Lock a group of properties.
Definition SDL3pp_properties.h:788
~PropertiesLock()
Unlock a group of properties.
Definition SDL3pp_properties.h:834
PropertiesLock(const PropertiesLock &other)=delete
Copy constructor.
void release()
Releases the lock without unlocking.
Definition SDL3pp_properties.h:863
PropertiesRef resource() const
Get the reference to locked resource.
Definition SDL3pp_properties.h:860
PropertiesLock(PropertiesLock &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:820
PropertiesLock & operator=(PropertiesLock &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:839
Iterator for properties in a Properties set.
Definition SDL3pp_properties.h:961
PropertyIterator operator--(int)
Post-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1020
constexpr PropertyIterator()=default
Default constructor.
PropertyIterator & operator--()
Pre-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1012
constexpr bool operator==(const PropertyIterator &other) const
Comparison operator.
Definition SDL3pp_properties.h:984
PropertyIterator(PropertiesRef props, size_t index=0)
Constructor.
Definition SDL3pp_properties.h:967
const PropertyProxy & operator*() const
Dereference operator to get the current property proxy.
Definition SDL3pp_properties.h:990
PropertyIterator operator++(int)
Post-increment operator to move to the next property.
Definition SDL3pp_properties.h:1004
const PropertyProxy * operator->() const
Arrow operator to get a pointer to the current property proxy.
Definition SDL3pp_properties.h:993
PropertyIterator & operator++()
Pre-increment operator to move to the next property.
Definition SDL3pp_properties.h:996
constexpr bool operator==(std::nullptr_t) const
Comparison with nullptr, to check if the iterator is at the end.
Definition SDL3pp_properties.h:978
Represent a property name from a given Properties.
Definition SDL3pp_properties.h:868
PropertiesRef GetProperties() const
Get the property group this proxy belongs to.
Definition SDL3pp_properties.h:890
const char * GetName() const
Get Property name.
Definition SDL3pp_properties.h:887
auto As() const
Convert to given type.
PropertyProxy(PropertiesRef props, StringParam name)
Constructor.
Definition SDL3pp_properties.h:871
bool IsValid() const
True if the there is a property with this name.
Definition SDL3pp_properties.h:878
PropertyType GetType() const
Get Property type.
Definition SDL3pp_properties.h:881
auto visit(T visitor) const
Call visitor with the correct type based on its GetType().
Definition SDL3pp_properties.h:925
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
constexpr StringParam(const char *str="")
Constructs from a C string.
Definition SDL3pp_strings.h:69
A value assignable to a property.
Definition SDL3pp_properties.h:96
#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:82
PropertiesLock(PropertiesRef resource)
Lock a group of properties.
Definition SDL3pp_properties.h:1160
Uint64 GetCount() const
Returns the number of properties this has.
Definition SDL3pp_properties.h:1891
void ClearProperty(PropertiesRef props, StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1807
std::function< void(void *value)> CleanupPropertyCB
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:190
Uint64 CountProperties(PropertiesRef props)
Returns the number of properties this has.
Definition SDL3pp_properties.h:1884
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1433
bool GetBooleanProperty(StringParam name, bool default_value=false) const
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1722
bool GetBooleanProperty(PropertiesRef props, StringParam name, bool default_value=false)
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1715
void(SDLCALL *)(void *userdata, void *value) CleanupPropertyCallback
A callback used to free resources when a property is deleted.
Definition SDL3pp_properties.h:165
constexpr const char * PROP_NAME_STRING
A generic property for naming things.
Definition SDL3pp_properties.h:1062
void LockProperties(PropertiesRef props)
Lock a group of properties.
Definition SDL3pp_properties.h:1153
void EnumerateProperties(PropertiesRef props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1832
void * GetPointerProperty(StringParam name, void *default_value=nullptr) const
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1588
PropertyProxy GetProperty(PropertiesRef props, StringParam name)
Get a property from a group of properties.
Definition SDL3pp_properties.h:1541
const char * GetStringProperty(PropertiesRef props, StringParam name, StringParam default_value="")
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1615
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:1283
void SetFloatProperty(PropertiesRef props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1452
PropertiesLock Lock()
Lock a group of properties.
Definition SDL3pp_properties.h:1158
void SetBooleanProperty(PropertiesRef props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1476
PropertyProxy operator[](StringParam name) const
Access a property from a group of properties.
Definition SDL3pp_properties.h:1195
Properties()
Create a group of properties.
Definition SDL3pp_properties.h:1099
float GetFloatProperty(PropertiesRef props, StringParam name, float default_value=0)
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1682
PropertyIterator begin() const
Gets an iterator to the first property in a group of properties.
Definition SDL3pp_properties.h:1205
void SetProperty(PropertiesRef props, StringParam name, V value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1219
std::nullptr_t end() const
Gets sentinel iterator for a group of properties.
Definition SDL3pp_properties.h:1207
const char * GetStringProperty(StringParam name, StringParam default_value="") const
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1622
PropertyType GetPropertyType(StringParam name) const
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1529
Properties CreateProperties()
Create a group of properties.
Definition SDL3pp_properties.h:1097
void SetNumberProperty(PropertiesRef props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1426
void Set(StringParam name, V &&value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1249
constexpr PropertyType PROPERTY_TYPE_NUMBER
NUMBER.
Definition SDL3pp_properties.h:77
void CopyProperties(PropertiesRef src, PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:1122
constexpr PropertyType PROPERTY_TYPE_POINTER
POINTER.
Definition SDL3pp_properties.h:71
void SetStringProperty(PropertiesRef props, StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1399
bool HasProperty(PropertiesRef props, StringParam name)
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1501
Sint64 GetNumberProperty(PropertiesRef props, StringParam name, Sint64 default_value=0)
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1649
PropertyType GetPropertyType(PropertiesRef props, StringParam name)
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1524
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 ClearProperty(StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1812
auto prop_cast(PropertiesRef props, StringParam name)
Cast property to given PropertyType.
Definition SDL3pp_properties.h:1730
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition SDL3pp_properties.h:68
void UnlockProperties(PropertiesRef props)
Unlock a group of properties.
Definition SDL3pp_properties.h:1177
constexpr PropertyType PROPERTY_TYPE_FLOAT
FLOAT.
Definition SDL3pp_properties.h:80
constexpr PropertyType PROPERTY_TYPE_STRING
STRING.
Definition SDL3pp_properties.h:74
void Destroy()
Destroy a group of properties.
Definition SDL3pp_properties.h:1917
void Copy(PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:1127
float GetFloatProperty(StringParam name, float default_value=0) const
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1689
auto As() const
Convert to given type.
Definition SDL3pp_properties.h:1784
SDL_PropertiesID PropertiesID
Alias to raw representation for Properties.
Definition SDL3pp_properties.h:49
Sint64 GetNumberProperty(StringParam name, Sint64 default_value=0) const
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1656
void SetPointerProperty(PropertiesRef props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1369
void Enumerate(EnumeratePropertiesCallback callback, void *userdata) const
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1865
void reset()
Unlock a group of properties.
Definition SDL3pp_properties.h:1188
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1483
SDL_PropertyType PropertyType
SDL property type.
Definition SDL3pp_properties.h:66
void * GetPointerProperty(PropertiesRef props, StringParam name, void *default_value=nullptr)
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1581
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1457
void Unlock(PropertiesLock &&lock)
Unlock a group of properties.
Definition SDL3pp_properties.h:1182
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:1331
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1376
PropertyProxy Get(StringParam name) const
Get a property from a group of properties.
Definition SDL3pp_properties.h:1546
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:118
bool HasProperty(StringParam name) const
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1506
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:56
void SetStringProperty(StringParam name, StringParam value)
Set a string property in a group of properties.
Definition SDL3pp_properties.h:1406
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition SDL3pp_properties.h:1912
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition SDL3pp_properties.h:1077
::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:3815
Main include header for the SDL3pp library.
Definition SDL3pp_callbackWrapper.h:20
Base class to Properties.
Definition SDL3pp_properties.h:198
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An ID that represents a properties set.
Definition SDL3pp_properties.h:679
constexpr Properties & operator=(Properties &&other) noexcept
Assignment operator.
Definition SDL3pp_properties.h:758
~Properties()
Destructor.
Definition SDL3pp_properties.h:755
constexpr Properties(PropertiesID resource) noexcept
Constructs from raw Properties.
Definition SDL3pp_properties.h:689
constexpr Properties(Properties &&other) noexcept
Move constructor.
Definition SDL3pp_properties.h:695
Properties(std::initializer_list< std::pair< StringParam, std::variant< StringParam, void *, Sint64, float, bool > > > entries)
Create a group of properties.
Definition SDL3pp_properties.h:734
Represent a mutable property name from a given Properties.
Definition SDL3pp_properties.h:947
PropertyMutableProxy & operator=(V &&value)
Change the value of this property.
Definition SDL3pp_properties.h:952
PropertyProxy(PropertiesRef props, StringParam name)
Constructor.
Definition SDL3pp_properties.h:871
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93