SDL_properties.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. Simple DiretMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_properties.h
  20. *
  21. * Header file for SDL properties.
  22. */
  23. #ifndef SDL_properties_h_
  24. #define SDL_properties_h_
  25. #include <SDL3/SDL_begin_code.h>
  26. /* Set up for C function definitions, even when using C++ */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * SDL properties ID
  32. */
  33. typedef Uint32 SDL_PropertiesID;
  34. /**
  35. * SDL property type
  36. */
  37. typedef enum
  38. {
  39. SDL_PROPERTY_TYPE_INVALID,
  40. SDL_PROPERTY_TYPE_POINTER,
  41. SDL_PROPERTY_TYPE_STRING,
  42. SDL_PROPERTY_TYPE_NUMBER,
  43. SDL_PROPERTY_TYPE_FLOAT,
  44. } SDL_PropertyType;
  45. /**
  46. * Get the global SDL properties
  47. *
  48. * \returns a valid property ID on success or 0 on failure; call
  49. * SDL_GetError() for more information.
  50. *
  51. * \since This function is available since SDL 3.0.0.
  52. *
  53. * \sa SDL_GetProperty
  54. * \sa SDL_SetProperty
  55. */
  56. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
  57. /**
  58. * Create a set of properties
  59. *
  60. * All properties are automatically destroyed when SDL_Quit() is called.
  61. *
  62. * \returns an ID for a new set of properties, or 0 on failure; call
  63. * SDL_GetError() for more information.
  64. *
  65. * \threadsafety It is safe to call this function from any thread.
  66. *
  67. * \since This function is available since SDL 3.0.0.
  68. *
  69. * \sa SDL_DestroyProperties
  70. */
  71. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
  72. /**
  73. * Lock a set of properties
  74. *
  75. * Obtain a multi-threaded lock for these properties. Other threads will wait
  76. * while trying to lock these properties until they are unlocked. Properties
  77. * must be unlocked before they are destroyed.
  78. *
  79. * The lock is automatically taken when setting individual properties, this
  80. * function is only needed when you want to set several properties atomically
  81. * or want to guarantee that properties being queried aren't freed in another
  82. * thread.
  83. *
  84. * \param props the properties to lock
  85. * \returns 0 on success or a negative error code on failure; call
  86. * SDL_GetError() for more information.
  87. *
  88. * \threadsafety It is safe to call this function from any thread.
  89. *
  90. * \since This function is available since SDL 3.0.0.
  91. *
  92. * \sa SDL_UnlockProperties
  93. */
  94. extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
  95. /**
  96. * Unlock a set of properties
  97. *
  98. * \param props the properties to unlock
  99. *
  100. * \threadsafety It is safe to call this function from any thread.
  101. *
  102. * \since This function is available since SDL 3.0.0.
  103. *
  104. * \sa SDL_LockProperties
  105. */
  106. extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
  107. /**
  108. * Set a property on a set of properties with a cleanup function that is
  109. * called when the property is deleted
  110. *
  111. * \param props the properties to modify
  112. * \param name the name of the property to modify
  113. * \param value the new value of the property, or NULL to delete the property
  114. * \param cleanup the function to call when this property is deleted, or NULL
  115. * if no cleanup is necessary
  116. * \param userdata a pointer that is passed to the cleanup function
  117. * \returns 0 on success or a negative error code on failure; call
  118. * SDL_GetError() for more information.
  119. *
  120. * \threadsafety It is safe to call this function from any thread.
  121. *
  122. * \since This function is available since SDL 3.0.0.
  123. *
  124. * \sa SDL_GetProperty
  125. * \sa SDL_SetProperty
  126. */
  127. extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
  128. /**
  129. * Set a property on a set of properties
  130. *
  131. * \param props the properties to modify
  132. * \param name the name of the property to modify
  133. * \param value the new value of the property, or NULL to delete the property
  134. * \returns 0 on success or a negative error code on failure; call
  135. * SDL_GetError() for more information.
  136. *
  137. * \threadsafety It is safe to call this function from any thread.
  138. *
  139. * \since This function is available since SDL 3.0.0.
  140. *
  141. * \sa SDL_GetProperty
  142. * \sa SDL_SetPropertyWithCleanup
  143. */
  144. extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
  145. /**
  146. * Set a string property on a set of properties
  147. *
  148. * \param props the properties to modify
  149. * \param name the name of the property to modify
  150. * \param value the new value of the property, or NULL to delete the property
  151. * \returns 0 on success or a negative error code on failure; call
  152. * SDL_GetError() for more information.
  153. *
  154. * \threadsafety It is safe to call this function from any thread.
  155. *
  156. * \since This function is available since SDL 3.0.0.
  157. *
  158. * \sa SDL_GetStringProperty
  159. */
  160. extern DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
  161. /**
  162. * Set an integer property on a set of properties
  163. *
  164. * \param props the properties to modify
  165. * \param name the name of the property to modify
  166. * \param value the new value of the property
  167. * \returns 0 on success or a negative error code on failure; call
  168. * SDL_GetError() for more information.
  169. *
  170. * \threadsafety It is safe to call this function from any thread.
  171. *
  172. * \since This function is available since SDL 3.0.0.
  173. *
  174. * \sa SDL_GetNumberProperty
  175. */
  176. extern DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
  177. /**
  178. * Set a floating point property on a set of properties
  179. *
  180. * \param props the properties to modify
  181. * \param name the name of the property to modify
  182. * \param value the new value of the property
  183. * \returns 0 on success or a negative error code on failure; call
  184. * SDL_GetError() for more information.
  185. *
  186. * \threadsafety It is safe to call this function from any thread.
  187. *
  188. * \since This function is available since SDL 3.0.0.
  189. *
  190. * \sa SDL_GetFloatProperty
  191. */
  192. extern DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
  193. /**
  194. * Get the type of a property on a set of properties
  195. *
  196. * \param props the properties to query
  197. * \param name the name of the property to query
  198. * \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is not set.
  199. *
  200. * \threadsafety It is safe to call this function from any thread.
  201. *
  202. * \since This function is available since SDL 3.0.0.
  203. */
  204. extern DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name);
  205. /**
  206. * Get a property on a set of properties
  207. *
  208. * By convention, the names of properties that SDL exposes on objects will
  209. * start with "SDL.", and properties that SDL uses internally will start with
  210. * "SDL.internal.". These should be considered read-only and should not be
  211. * modified by applications.
  212. *
  213. * \param props the properties to query
  214. * \param name the name of the property to query
  215. * \param default_value the default value of the property
  216. * \returns the value of the property, or `default_value` if it is not set or not a pointer property.
  217. *
  218. * \threadsafety It is safe to call this function from any thread, although
  219. * the data returned is not protected and could potentially be
  220. * freed if you call SDL_SetProperty() or SDL_ClearProperty() on
  221. * these properties from another thread. If you need to avoid
  222. * this, use SDL_LockProperties() and SDL_UnlockProperties().
  223. *
  224. * \since This function is available since SDL 3.0.0.
  225. *
  226. * \sa SDL_GetPropertyType
  227. * \sa SDL_SetProperty
  228. */
  229. extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_value);
  230. /**
  231. * Get a string property on a set of properties
  232. *
  233. * \param props the properties to query
  234. * \param name the name of the property to query
  235. * \param default_value the default value of the property
  236. * \returns the value of the property, or `default_value` if it is not set or not a string property.
  237. *
  238. * \threadsafety It is safe to call this function from any thread.
  239. *
  240. * \since This function is available since SDL 3.0.0.
  241. *
  242. * \sa SDL_GetPropertyType
  243. * \sa SDL_SetStringProperty
  244. */
  245. extern DECLSPEC const char *SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
  246. /**
  247. * Get a number property on a set of properties
  248. *
  249. * You can use SDL_GetPropertyType() to query whether the property exists and is a number property.
  250. *
  251. * \param props the properties to query
  252. * \param name the name of the property to query
  253. * \param default_value the default value of the property
  254. * \returns the value of the property, or `default_value` if it is not set or not a number property.
  255. *
  256. * \threadsafety It is safe to call this function from any thread.
  257. *
  258. * \since This function is available since SDL 3.0.0.
  259. *
  260. * \sa SDL_GetPropertyType
  261. * \sa SDL_SetNumberProperty
  262. */
  263. extern DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value);
  264. /**
  265. * Get a floating point property on a set of properties
  266. *
  267. * You can use SDL_GetPropertyType() to query whether the property exists and is a floating point property.
  268. *
  269. * \param props the properties to query
  270. * \param name the name of the property to query
  271. * \param default_value the default value of the property
  272. * \returns the value of the property, or `default_value` if it is not set or not a float property.
  273. *
  274. * \threadsafety It is safe to call this function from any thread.
  275. *
  276. * \since This function is available since SDL 3.0.0.
  277. *
  278. * \sa SDL_GetPropertyType
  279. * \sa SDL_SetFloatProperty
  280. */
  281. extern DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value);
  282. /**
  283. * Clear a property on a set of properties
  284. *
  285. * \param props the properties to modify
  286. * \param name the name of the property to clear
  287. * \returns 0 on success or a negative error code on failure; call
  288. * SDL_GetError() for more information.
  289. *
  290. * \threadsafety It is safe to call this function from any thread.
  291. *
  292. * \since This function is available since SDL 3.0.0.
  293. *
  294. * \sa SDL_GetProperty
  295. */
  296. extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
  297. typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name);
  298. /**
  299. * Enumerate the properties on a set of properties
  300. *
  301. * The callback function is called for each property on the set of properties. The properties are locked during enumeration.
  302. *
  303. * \param props the properties to query
  304. * \param callback the function to call for each property
  305. * \param userdata a pointer that is passed to `callback`
  306. * \returns 0 on success or a negative error code on failure; call
  307. * SDL_GetError() for more information.
  308. *
  309. * \threadsafety It is safe to call this function from any thread.
  310. *
  311. * \since This function is available since SDL 3.0.0.
  312. */
  313. extern DECLSPEC int SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
  314. /**
  315. * Destroy a set of properties
  316. *
  317. * All properties are deleted and their cleanup functions will be called, if
  318. * any.
  319. *
  320. * \param props the properties to destroy
  321. *
  322. * \threadsafety This function should not be called while these properties are
  323. * locked or other threads might be setting or getting values
  324. * from these properties.
  325. *
  326. * \since This function is available since SDL 3.0.0.
  327. *
  328. * \sa SDL_CreateProperties
  329. */
  330. extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
  331. /* Ends C function definitions when using C++ */
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335. #include <SDL3/SDL_close_code.h>
  336. #endif /* SDL_properties_h_ */