SDL_properties.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. Simple DiretMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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_PROPERTY_TYPE_BOOLEAN,
  45. } SDL_PropertyType;
  46. /**
  47. * Get the global SDL properties
  48. *
  49. * \returns a valid property ID on success or 0 on failure; call
  50. * SDL_GetError() for more information.
  51. *
  52. * \since This function is available since SDL 3.0.0.
  53. *
  54. * \sa SDL_GetProperty
  55. * \sa SDL_SetProperty
  56. */
  57. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);
  58. /**
  59. * Create a set of properties
  60. *
  61. * All properties are automatically destroyed when SDL_Quit() is called.
  62. *
  63. * \returns an ID for a new set of properties, or 0 on failure; call
  64. * SDL_GetError() for more information.
  65. *
  66. * \threadsafety It is safe to call this function from any thread.
  67. *
  68. * \since This function is available since SDL 3.0.0.
  69. *
  70. * \sa SDL_DestroyProperties
  71. */
  72. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);
  73. /**
  74. * Lock a set of properties
  75. *
  76. * Obtain a multi-threaded lock for these properties. Other threads will wait
  77. * while trying to lock these properties until they are unlocked. Properties
  78. * must be unlocked before they are destroyed.
  79. *
  80. * The lock is automatically taken when setting individual properties, this
  81. * function is only needed when you want to set several properties atomically
  82. * or want to guarantee that properties being queried aren't freed in another
  83. * thread.
  84. *
  85. * \param props the properties to lock
  86. * \returns 0 on success or a negative error code on failure; call
  87. * SDL_GetError() for more information.
  88. *
  89. * \threadsafety It is safe to call this function from any thread.
  90. *
  91. * \since This function is available since SDL 3.0.0.
  92. *
  93. * \sa SDL_UnlockProperties
  94. */
  95. extern DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props);
  96. /**
  97. * Unlock a set of properties
  98. *
  99. * \param props the properties to unlock
  100. *
  101. * \threadsafety It is safe to call this function from any thread.
  102. *
  103. * \since This function is available since SDL 3.0.0.
  104. *
  105. * \sa SDL_LockProperties
  106. */
  107. extern DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);
  108. /**
  109. * Set a property on a set of properties with a cleanup function that is
  110. * called when the property is deleted
  111. *
  112. * \param props the properties to modify
  113. * \param name the name of the property to modify
  114. * \param value the new value of the property, or NULL to delete the property
  115. * \param cleanup the function to call when this property is deleted, or NULL
  116. * if no cleanup is necessary
  117. * \param userdata a pointer that is passed to the cleanup function
  118. * \returns 0 on success or a negative error code on failure; call
  119. * SDL_GetError() for more information.
  120. *
  121. * \threadsafety It is safe to call this function from any thread.
  122. *
  123. * \since This function is available since SDL 3.0.0.
  124. *
  125. * \sa SDL_GetProperty
  126. * \sa SDL_SetProperty
  127. */
  128. extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
  129. /**
  130. * Set a property on a set of properties
  131. *
  132. * \param props the properties to modify
  133. * \param name the name of the property to modify
  134. * \param value the new value of the property, or NULL to delete the property
  135. * \returns 0 on success or a negative error code on failure; call
  136. * SDL_GetError() for more information.
  137. *
  138. * \threadsafety It is safe to call this function from any thread.
  139. *
  140. * \since This function is available since SDL 3.0.0.
  141. *
  142. * \sa SDL_GetProperty
  143. * \sa SDL_SetPropertyWithCleanup
  144. */
  145. extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
  146. /**
  147. * Set a string property on a set of properties
  148. *
  149. * \param props the properties to modify
  150. * \param name the name of the property to modify
  151. * \param value the new value of the property, or NULL to delete the property
  152. * \returns 0 on success or a negative error code on failure; call
  153. * SDL_GetError() for more information.
  154. *
  155. * \threadsafety It is safe to call this function from any thread.
  156. *
  157. * \since This function is available since SDL 3.0.0.
  158. *
  159. * \sa SDL_GetStringProperty
  160. */
  161. extern DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
  162. /**
  163. * Set an integer property on a set of properties
  164. *
  165. * \param props the properties to modify
  166. * \param name the name of the property to modify
  167. * \param value the new value of the property
  168. * \returns 0 on success or a negative error code on failure; call
  169. * SDL_GetError() for more information.
  170. *
  171. * \threadsafety It is safe to call this function from any thread.
  172. *
  173. * \since This function is available since SDL 3.0.0.
  174. *
  175. * \sa SDL_GetNumberProperty
  176. */
  177. extern DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
  178. /**
  179. * Set a floating point property on a set of properties
  180. *
  181. * \param props the properties to modify
  182. * \param name the name of the property to modify
  183. * \param value the new value of the property
  184. * \returns 0 on success or a negative error code on failure; call
  185. * SDL_GetError() for more information.
  186. *
  187. * \threadsafety It is safe to call this function from any thread.
  188. *
  189. * \since This function is available since SDL 3.0.0.
  190. *
  191. * \sa SDL_GetFloatProperty
  192. */
  193. extern DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
  194. /**
  195. * Set a boolean property on a set of properties
  196. *
  197. * \param props the properties to modify
  198. * \param name the name of the property to modify
  199. * \param value the new value of the property
  200. * \returns 0 on success or a negative error code on failure; call
  201. * SDL_GetError() for more information.
  202. *
  203. * \threadsafety It is safe to call this function from any thread.
  204. *
  205. * \since This function is available since SDL 3.0.0.
  206. *
  207. * \sa SDL_GetBooleanProperty
  208. */
  209. extern DECLSPEC int SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value);
  210. /**
  211. * Get the type of a property on a set of properties
  212. *
  213. * \param props the properties to query
  214. * \param name the name of the property to query
  215. * \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is
  216. * not set.
  217. *
  218. * \threadsafety It is safe to call this function from any thread.
  219. *
  220. * \since This function is available since SDL 3.0.0.
  221. */
  222. extern DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name);
  223. /**
  224. * Get a property on a set of properties
  225. *
  226. * By convention, the names of properties that SDL exposes on objects will
  227. * start with "SDL.", and properties that SDL uses internally will start with
  228. * "SDL.internal.". These should be considered read-only and should not be
  229. * modified by applications.
  230. *
  231. * \param props the properties to query
  232. * \param name the name of the property to query
  233. * \param default_value the default value of the property
  234. * \returns the value of the property, or `default_value` if it is not set or
  235. * not a pointer property.
  236. *
  237. * \threadsafety It is safe to call this function from any thread, although
  238. * the data returned is not protected and could potentially be
  239. * freed if you call SDL_SetProperty() or SDL_ClearProperty() on
  240. * these properties from another thread. If you need to avoid
  241. * this, use SDL_LockProperties() and SDL_UnlockProperties().
  242. *
  243. * \since This function is available since SDL 3.0.0.
  244. *
  245. * \sa SDL_GetPropertyType
  246. * \sa SDL_SetProperty
  247. */
  248. extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_value);
  249. /**
  250. * Get a string property on a set of properties
  251. *
  252. * \param props the properties to query
  253. * \param name the name of the property to query
  254. * \param default_value the default value of the property
  255. * \returns the value of the property, or `default_value` if it is not set or
  256. * not a string property.
  257. *
  258. * \threadsafety It is safe to call this function from any thread.
  259. *
  260. * \since This function is available since SDL 3.0.0.
  261. *
  262. * \sa SDL_GetPropertyType
  263. * \sa SDL_SetStringProperty
  264. */
  265. extern DECLSPEC const char *SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
  266. /**
  267. * Get a number property on a set of properties
  268. *
  269. * You can use SDL_GetPropertyType() to query whether the property exists and
  270. * is a number property.
  271. *
  272. * \param props the properties to query
  273. * \param name the name of the property to query
  274. * \param default_value the default value of the property
  275. * \returns the value of the property, or `default_value` if it is not set or
  276. * not a number property.
  277. *
  278. * \threadsafety It is safe to call this function from any thread.
  279. *
  280. * \since This function is available since SDL 3.0.0.
  281. *
  282. * \sa SDL_GetPropertyType
  283. * \sa SDL_SetNumberProperty
  284. */
  285. extern DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value);
  286. /**
  287. * Get a floating point property on a set of properties
  288. *
  289. * You can use SDL_GetPropertyType() to query whether the property exists and
  290. * is a floating point property.
  291. *
  292. * \param props the properties to query
  293. * \param name the name of the property to query
  294. * \param default_value the default value of the property
  295. * \returns the value of the property, or `default_value` if it is not set or
  296. * not a float property.
  297. *
  298. * \threadsafety It is safe to call this function from any thread.
  299. *
  300. * \since This function is available since SDL 3.0.0.
  301. *
  302. * \sa SDL_GetPropertyType
  303. * \sa SDL_SetFloatProperty
  304. */
  305. extern DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value);
  306. /**
  307. * Get a boolean property on a set of properties
  308. *
  309. * You can use SDL_GetPropertyType() to query whether the property exists and
  310. * is a boolean property.
  311. *
  312. * \param props the properties to query
  313. * \param name the name of the property to query
  314. * \param default_value the default value of the property
  315. * \returns the value of the property, or `default_value` if it is not set or
  316. * not a float property.
  317. *
  318. * \threadsafety It is safe to call this function from any thread.
  319. *
  320. * \since This function is available since SDL 3.0.0.
  321. *
  322. * \sa SDL_GetPropertyType
  323. * \sa SDL_SetBooleanProperty
  324. */
  325. extern DECLSPEC SDL_bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool default_value);
  326. /**
  327. * Clear a property on a set of properties
  328. *
  329. * \param props the properties to modify
  330. * \param name the name of the property to clear
  331. * \returns 0 on success or a negative error code on failure; call
  332. * SDL_GetError() for more information.
  333. *
  334. * \threadsafety It is safe to call this function from any thread.
  335. *
  336. * \since This function is available since SDL 3.0.0.
  337. *
  338. * \sa SDL_GetProperty
  339. */
  340. extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
  341. typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name);
  342. /**
  343. * Enumerate the properties on a set of properties
  344. *
  345. * The callback function is called for each property on the set of properties.
  346. * The properties are locked during enumeration.
  347. *
  348. * \param props the properties to query
  349. * \param callback the function to call for each property
  350. * \param userdata a pointer that is passed to `callback`
  351. * \returns 0 on success or a negative error code on failure; call
  352. * SDL_GetError() for more information.
  353. *
  354. * \threadsafety It is safe to call this function from any thread.
  355. *
  356. * \since This function is available since SDL 3.0.0.
  357. */
  358. extern DECLSPEC int SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
  359. /**
  360. * Destroy a set of properties
  361. *
  362. * All properties are deleted and their cleanup functions will be called, if
  363. * any.
  364. *
  365. * \param props the properties to destroy
  366. *
  367. * \threadsafety This function should not be called while these properties are
  368. * locked or other threads might be setting or getting values
  369. * from these properties.
  370. *
  371. * \since This function is available since SDL 3.0.0.
  372. *
  373. * \sa SDL_CreateProperties
  374. */
  375. extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
  376. /* Ends C function definitions when using C++ */
  377. #ifdef __cplusplus
  378. }
  379. #endif
  380. #include <SDL3/SDL_close_code.h>
  381. #endif /* SDL_properties_h_ */