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 template<PropertyType T>
893 auto As() const;
894
896 template<PropertyValue T>
897 auto As() const;
898
900 operator void*() const { return m_props.GetPointerProperty(m_name); }
901
903 operator const char*() const { return m_props.GetStringProperty(m_name); }
904
906 template<std::integral T>
907 operator T() const
908 {
909 return T(m_props.GetNumberProperty(m_name));
910 }
911
913 template<std::floating_point T>
914 operator T() const
915 {
916 return T(m_props.GetFloatProperty(m_name));
917 }
918
920 operator bool() const { return m_props.GetBooleanProperty(m_name); }
921
923 template<class T>
924 auto visit(T visitor) const
925 {
926 switch (GetType()) {
927 case SDL_PROPERTY_TYPE_POINTER: return visitor((void*)(*this));
928 case SDL_PROPERTY_TYPE_STRING: return visitor((const char*)(*this));
929 case SDL_PROPERTY_TYPE_NUMBER: return visitor(Sint64(*this));
930 case SDL_PROPERTY_TYPE_FLOAT: return visitor(float(*this));
931 case SDL_PROPERTY_TYPE_BOOLEAN: return visitor(bool(*this));
932 default: return visitor(std::nullopt);
933 }
934 }
935
936private:
937 PropertiesRef m_props;
938
939 StringParam m_name;
940
941 friend class PropertyIterator;
942};
943
946{
948
950 template<PropertyValue V>
952 {
953 GetProperties().Set(GetName(), std::forward<V>(value));
954 return *this;
955 }
956};
957
960{
961public:
963 constexpr PropertyIterator() = default;
964
966 PropertyIterator(PropertiesRef props, size_t index = 0)
967 : m_index(index)
968 {
969 props.Enumerate(
970 [this](auto, const char* key) { m_keys.emplace_back(key); });
971 if (m_index < m_keys.size()) m_proxy = {props, m_keys[m_index]};
972 }
973
974 ~PropertyIterator() = default;
975
977 constexpr bool operator==(std::nullptr_t) const
978 {
979 return m_index >= m_keys.size();
980 }
981
983 constexpr bool operator==(const PropertyIterator& other) const
984 {
985 return m_index == other.m_index;
986 }
987
989 const PropertyProxy& operator*() const { return m_proxy; }
990
992 const PropertyProxy* operator->() const { return &m_proxy; }
993
996 {
997 ++m_index;
998 update();
999 return *this;
1000 }
1001
1004 {
1005 auto copy = *this;
1006 ++(*this);
1007 return copy;
1008 }
1009
1012 {
1013 --m_index;
1014 update();
1015 return *this;
1016 }
1017
1020 {
1021 auto copy = *this;
1022 --(*this);
1023 return copy;
1024 }
1025
1026private:
1027 std::vector<std::string> m_keys;
1028 PropertyProxy m_proxy{{}, ""};
1029 size_t m_index = 0;
1030
1031 void update()
1032 {
1033 if (m_index < m_keys.size()) m_proxy.m_name = m_keys[m_index];
1034 }
1035};
1036
1037#if SDL_VERSION_ATLEAST(3, 4, 0)
1038
1061constexpr const char* PROP_NAME_STRING = SDL_PROP_NAME_STRING;
1062
1063#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1064
1077{
1078 return {CheckError(SDL_GetGlobalProperties())};
1079}
1080
1097
1099 : Properties(CheckError(SDL_CreateProperties()))
1100{
1101}
1102
1122{
1123 CheckError(SDL_CopyProperties(src, dst));
1124}
1125
1127{
1128 SDL::CopyProperties(get(), dst);
1129}
1130
1153{
1154 CheckError(SDL_LockProperties(props));
1155}
1156
1158
1160 : m_lock(resource)
1161{
1162 LockProperties(m_lock);
1163}
1164
1177{
1178 SDL_UnlockProperties(props);
1179}
1180
1182{
1183 SDL_assert_paranoid(lock.resource() == *this);
1184 std::move(lock).reset();
1185}
1186
1188{
1189 if (!m_lock) return;
1190 UnlockProperties(m_lock);
1191 m_lock = {};
1192}
1193
1195{
1196 return {*this, name};
1197}
1198
1200{
1201 return {*this, name};
1202}
1203
1204inline PropertyIterator PropertiesBase::begin() const { return {*this}; }
1205
1206inline std::nullptr_t PropertiesBase::end() const { return nullptr; }
1207
1217template<PropertyValue V>
1218inline void SetProperty(PropertiesRef props, StringParam name, V value)
1219{
1220 struct
1221 {
1222 PropertiesRef props;
1223 StringParam name;
1224
1225 void operator()(std::nullopt_t) { props.ClearProperty(name); }
1226 void operator()(void* v) { props.SetPointerProperty(name, v); }
1227 void operator()(const char* v) { props.SetStringProperty(name, v); }
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 void operator()(const PropertyProxy& prop) { prop.visit(*this); }
1232
1233 } visitor(props, name);
1234 if constexpr (std::is_same_v<V, bool>) {
1235 visitor(value);
1236 } else if constexpr (std::integral<V>) {
1237 visitor(Sint64(value));
1238 } else if constexpr (std::floating_point<V>) {
1239 visitor(float(value));
1240 } else if constexpr (std::convertible_to<V, StringParam>) {
1241 visitor(StringParam(value));
1242 } else {
1243 visitor(value);
1244 }
1245}
1246
1247template<PropertyValue V>
1248inline void PropertiesBase::Set(StringParam name, V&& value)
1249{
1250 SDL::SetProperty(get(), name, std::forward<V>(value));
1251}
1252
1283 StringParam name,
1284 void* value,
1286 void* userdata)
1287{
1288 CheckError(
1289 SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata));
1290}
1291
1321 StringParam name,
1322 void* value,
1323 CleanupPropertyCB cleanup)
1324{
1325 using Wrapper = CallbackWrapper<CleanupPropertyCB>;
1326 SDL_SetPointerPropertyWithCleanup(
1327 props, name, value, &Wrapper::CallOnce, Wrapper::Wrap(std::move(cleanup)));
1328}
1329
1331 StringParam name,
1332 void* value,
1334 void* userdata)
1335{
1336 SDL::SetPointerPropertyWithCleanup(get(), name, value, cleanup, userdata);
1337}
1338
1340 StringParam name,
1341 void* value,
1342 CleanupPropertyCB cleanup)
1343{
1344 SDL::SetPointerPropertyWithCleanup(get(), name, value, std::move(cleanup));
1345}
1346
1369 StringParam name,
1370 void* value)
1371{
1372 CheckError(SDL_SetPointerProperty(props, name, value));
1373}
1374
1376{
1377 SDL::SetPointerProperty(get(), name, value);
1378}
1379
1399 StringParam name,
1400 StringParam value)
1401{
1402 CheckError(SDL_SetStringProperty(props, name, value));
1403}
1404
1406 StringParam value)
1407{
1408 SDL::SetStringProperty(get(), name, value);
1409}
1410
1426 StringParam name,
1427 Sint64 value)
1428{
1429 CheckError(SDL_SetNumberProperty(props, name, value));
1430}
1431
1433{
1434 SDL::SetNumberProperty(get(), name, value);
1435}
1436
1451inline void SetFloatProperty(PropertiesRef props, StringParam name, float value)
1452{
1453 CheckError(SDL_SetFloatProperty(props, name, value));
1454}
1455
1456inline void PropertiesBase::SetFloatProperty(StringParam name, float value)
1457{
1458 SDL::SetFloatProperty(get(), name, value);
1459}
1460
1476 StringParam name,
1477 bool value)
1478{
1479 CheckError(SDL_SetBooleanProperty(props, name, value));
1480}
1481
1483{
1484 SDL::SetBooleanProperty(get(), name, value);
1485}
1486
1500inline bool HasProperty(PropertiesRef props, StringParam name)
1501{
1502 return SDL_HasProperty(props, name);
1503}
1504
1506{
1507 return SDL::HasProperty(get(), name);
1508}
1509
1524{
1525 return SDL_GetPropertyType(props, name);
1526}
1527
1529{
1530 return SDL::GetPropertyType(get(), name);
1531}
1532
1541{
1542 return {props, name};
1543}
1544
1546{
1547 return SDL::GetProperty(get(), name);
1548}
1549
1581 StringParam name,
1582 void* default_value = nullptr)
1583{
1584 return SDL_GetPointerProperty(props, name, default_value);
1585}
1586
1588 void* default_value) const
1589{
1590 return SDL::GetPointerProperty(get(), name, default_value);
1591}
1592
1614inline const char* GetStringProperty(PropertiesRef props,
1615 StringParam name,
1616 StringParam default_value = "")
1617{
1618 return SDL_GetStringProperty(props, name, default_value);
1619}
1620
1622 StringParam name,
1623 StringParam default_value) const
1624{
1625 return SDL::GetStringProperty(get(), name, default_value);
1626}
1627
1649 StringParam name,
1650 Sint64 default_value = 0)
1651{
1652 return SDL_GetNumberProperty(props, name, default_value);
1653}
1654
1656 Sint64 default_value) const
1657{
1658 return SDL::GetNumberProperty(get(), name, default_value);
1659}
1660
1682 StringParam name,
1683 float default_value = 0)
1684{
1685 return SDL_GetFloatProperty(props, name, default_value);
1686}
1687
1689 float default_value) const
1690{
1691 return SDL::GetFloatProperty(get(), name, default_value);
1692}
1693
1715 StringParam name,
1716 bool default_value = false)
1717{
1718 return SDL_GetBooleanProperty(props, name, default_value);
1719}
1720
1722 bool default_value) const
1723{
1724 return SDL::GetBooleanProperty(get(), name, default_value);
1725}
1726
1728template<PropertyType T>
1730{
1731 if constexpr (T == PROPERTY_TYPE_POINTER) {
1732 return GetPointerProperty(props, name);
1733 } else if constexpr (T == PROPERTY_TYPE_STRING) {
1734 return GetStringProperty(props, name);
1735 } else if constexpr (T == PROPERTY_TYPE_NUMBER) {
1736 return GetNumberProperty(props, name);
1737 } else if constexpr (T == PROPERTY_TYPE_FLOAT) {
1738 return GetFloatProperty(props, name);
1739 } else {
1740 static_assert(T == PROPERTY_TYPE_BOOLEAN, "Invalid Property type");
1741 return GetBooleanProperty(props, name);
1742 }
1743}
1744
1746template<PropertyValue T>
1748{
1749 if constexpr (std::is_same_v<T, bool>) {
1750 return GetBooleanProperty(props, name);
1751 } else if constexpr (std::integral<T>) {
1752 return static_cast<T>(GetNumberProperty(props, name));
1753 } else if constexpr (std::floating_point<T>) {
1754 return static_cast<T>(GetFloatProperty(props, name));
1755 } else if constexpr (std::is_same_v<T, char*>) {
1756 return GetStringProperty(props, name);
1757 } else if constexpr (std::convertible_to<T, StringParam>) {
1758 return static_cast<T>(GetStringProperty(props, name));
1759 } else if constexpr (std::convertible_to<T, void*>) {
1760 return static_cast<T>(GetPointerProperty(props, name));
1761 } else {
1762 static_assert(std::convertible_to<PropertyProxy, T>, "invalid type");
1763 return static_cast<T>(PropertyProxy(props, name));
1764 }
1765}
1766
1768template<PropertyType T>
1770{
1771 return prop_cast<T>(prop.GetProperties(), prop.GetName());
1772}
1773
1775template<PropertyValue T>
1777{
1778 return prop_cast<T>(prop.GetProperties(), prop.GetName());
1779}
1780
1782template<PropertyType T>
1784{
1785 return prop_cast<T>(m_props, m_name);
1786}
1787
1789template<PropertyValue T>
1790auto PropertyProxy::As() const
1791{
1792 return prop_cast<T>(m_props, m_name);
1793}
1794
1807{
1808 CheckError(SDL_ClearProperty(props, name));
1809}
1810
1812{
1813 SDL::ClearProperty(get(), name);
1814}
1815
1833 void* userdata)
1834{
1835 CheckError(SDL_EnumerateProperties(props, callback, userdata));
1836}
1837
1853 EnumeratePropertiesCB callback)
1854{
1855 return EnumerateProperties(
1856 props,
1857 [](void* userdata, PropertiesID props, const char* name) {
1858 auto& f = *static_cast<const EnumeratePropertiesCB*>(userdata);
1859 f(props, name);
1860 },
1861 &callback);
1862}
1863
1865 void* userdata) const
1866{
1867 SDL::EnumerateProperties(get(), callback, userdata);
1868}
1869
1871{
1872 SDL::EnumerateProperties(get(), std::move(callback));
1873}
1874
1884{
1885 Uint64 count = 0;
1886 EnumerateProperties(props, [&count](auto, const char*) { count++; });
1887 return count;
1888}
1889
1891{
1892 return SDL::CountProperties(get());
1893}
1894
1912{
1913 SDL_DestroyProperties(props);
1914}
1915
1917
1919
1930
1931} // namespace SDL
1932
1933#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:960
PropertyIterator operator--(int)
Post-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1019
constexpr PropertyIterator()=default
Default constructor.
PropertyIterator & operator--()
Pre-decrement operator to move to the previous property.
Definition SDL3pp_properties.h:1011
constexpr bool operator==(const PropertyIterator &other) const
Comparison operator.
Definition SDL3pp_properties.h:983
PropertyIterator(PropertiesRef props, size_t index=0)
Constructor.
Definition SDL3pp_properties.h:966
const PropertyProxy & operator*() const
Dereference operator to get the current property proxy.
Definition SDL3pp_properties.h:989
PropertyIterator operator++(int)
Post-increment operator to move to the next property.
Definition SDL3pp_properties.h:1003
const PropertyProxy * operator->() const
Arrow operator to get a pointer to the current property proxy.
Definition SDL3pp_properties.h:992
PropertyIterator & operator++()
Pre-increment operator to move to the next property.
Definition SDL3pp_properties.h:995
constexpr bool operator==(std::nullptr_t) const
Comparison with nullptr, to check if the iterator is at the end.
Definition SDL3pp_properties.h:977
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
auto As() const
Convert to given type.
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:924
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:1159
Uint64 GetCount() const
Returns the number of properties this has.
Definition SDL3pp_properties.h:1890
void ClearProperty(PropertiesRef props, StringParam name)
Clear a property from a group of properties.
Definition SDL3pp_properties.h:1806
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:1883
void SetNumberProperty(StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1432
bool GetBooleanProperty(StringParam name, bool default_value=false) const
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1721
bool GetBooleanProperty(PropertiesRef props, StringParam name, bool default_value=false)
Get a boolean property from a group of properties.
Definition SDL3pp_properties.h:1714
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:1061
void LockProperties(PropertiesRef props)
Lock a group of properties.
Definition SDL3pp_properties.h:1152
void EnumerateProperties(PropertiesRef props, EnumeratePropertiesCallback callback, void *userdata)
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1831
void * GetPointerProperty(StringParam name, void *default_value=nullptr) const
Get a pointer property from a group of properties.
Definition SDL3pp_properties.h:1587
PropertyProxy GetProperty(PropertiesRef props, StringParam name)
Get a property from a group of properties.
Definition SDL3pp_properties.h:1540
const char * GetStringProperty(PropertiesRef props, StringParam name, StringParam default_value="")
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1614
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:1282
void SetFloatProperty(PropertiesRef props, StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1451
PropertiesLock Lock()
Lock a group of properties.
Definition SDL3pp_properties.h:1157
void SetBooleanProperty(PropertiesRef props, StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1475
PropertyProxy operator[](StringParam name) const
Access a property from a group of properties.
Definition SDL3pp_properties.h:1194
Properties()
Create a group of properties.
Definition SDL3pp_properties.h:1098
float GetFloatProperty(PropertiesRef props, StringParam name, float default_value=0)
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1681
PropertyIterator begin() const
Gets an iterator to the first property in a group of properties.
Definition SDL3pp_properties.h:1204
void SetProperty(PropertiesRef props, StringParam name, V value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1218
std::nullptr_t end() const
Gets sentinel iterator for a group of properties.
Definition SDL3pp_properties.h:1206
const char * GetStringProperty(StringParam name, StringParam default_value="") const
Get a string property from a group of properties.
Definition SDL3pp_properties.h:1621
PropertyType GetPropertyType(StringParam name) const
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1528
Properties CreateProperties()
Create a group of properties.
Definition SDL3pp_properties.h:1096
void SetNumberProperty(PropertiesRef props, StringParam name, Sint64 value)
Set an integer property in a group of properties.
Definition SDL3pp_properties.h:1425
void Set(StringParam name, V &&value)
Set a property in a group of properties.
Definition SDL3pp_properties.h:1248
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:1121
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:1398
bool HasProperty(PropertiesRef props, StringParam name)
Return whether a property exists in a group of properties.
Definition SDL3pp_properties.h:1500
Sint64 GetNumberProperty(PropertiesRef props, StringParam name, Sint64 default_value=0)
Get a number property from a group of properties.
Definition SDL3pp_properties.h:1648
PropertyType GetPropertyType(PropertiesRef props, StringParam name)
Get the type of a property in a group of properties.
Definition SDL3pp_properties.h:1523
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:1811
auto prop_cast(PropertiesRef props, StringParam name)
Cast property to given PropertyType.
Definition SDL3pp_properties.h:1729
constexpr PropertyType PROPERTY_TYPE_INVALID
INVALID.
Definition SDL3pp_properties.h:67
void UnlockProperties(PropertiesRef props)
Unlock a group of properties.
Definition SDL3pp_properties.h:1176
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:1916
void Copy(PropertiesRef dst)
Copy a group of properties.
Definition SDL3pp_properties.h:1126
float GetFloatProperty(StringParam name, float default_value=0) const
Get a floating point property from a group of properties.
Definition SDL3pp_properties.h:1688
auto As() const
Convert to given type.
Definition SDL3pp_properties.h:1783
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:1655
void SetPointerProperty(PropertiesRef props, StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1368
void Enumerate(EnumeratePropertiesCallback callback, void *userdata) const
Enumerate the properties contained in a group of properties.
Definition SDL3pp_properties.h:1864
void reset()
Unlock a group of properties.
Definition SDL3pp_properties.h:1187
void SetBooleanProperty(StringParam name, bool value)
Set a boolean property in a group of properties.
Definition SDL3pp_properties.h:1482
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:1580
void SetFloatProperty(StringParam name, float value)
Set a floating point property in a group of properties.
Definition SDL3pp_properties.h:1456
void Unlock(PropertiesLock &&lock)
Unlock a group of properties.
Definition SDL3pp_properties.h:1181
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:1330
void SetPointerProperty(StringParam name, void *value)
Set a pointer property in a group of properties.
Definition SDL3pp_properties.h:1375
PropertyProxy Get(StringParam name) const
Get a property from a group of properties.
Definition SDL3pp_properties.h:1545
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:1505
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:1405
void DestroyProperties(PropertiesID props)
Destroy a group of properties.
Definition SDL3pp_properties.h:1911
PropertiesRef GetGlobalProperties()
Get the global SDL properties.
Definition SDL3pp_properties.h:1076
::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:3782
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:946
PropertyMutableProxy & operator=(V &&value)
Change the value of this property.
Definition SDL3pp_properties.h:951
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