SDL_properties.h 14 KB

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