SDL_properties.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. * 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. * The cleanup function is also called if setting the property fails for any
  131. * reason.
  132. *
  133. * \param props the properties to modify
  134. * \param name the name of the property to modify
  135. * \param value the new value of the property, or NULL to delete the property
  136. * \param cleanup the function to call when this property is deleted, or NULL
  137. * if no cleanup is necessary
  138. * \param userdata a pointer that is passed to the cleanup function
  139. * \returns 0 on success or a negative error code on failure; call
  140. * SDL_GetError() for more information.
  141. *
  142. * \threadsafety It is safe to call this function from any thread.
  143. *
  144. * \since This function is available since SDL 3.0.0.
  145. *
  146. * \sa SDL_GetProperty
  147. * \sa SDL_SetProperty
  148. */
  149. extern DECLSPEC int SDLCALL SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata);
  150. /**
  151. * Set a property on a set of properties
  152. *
  153. * \param props the properties to modify
  154. * \param name the name of the property to modify
  155. * \param value the new value of the property, or NULL to delete the property
  156. * \returns 0 on success or a negative error code on failure; call
  157. * SDL_GetError() for more information.
  158. *
  159. * \threadsafety It is safe to call this function from any thread.
  160. *
  161. * \since This function is available since SDL 3.0.0.
  162. *
  163. * \sa SDL_GetProperty
  164. * \sa SDL_SetPropertyWithCleanup
  165. */
  166. extern DECLSPEC int SDLCALL SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value);
  167. /**
  168. * Set a string property on a set of properties
  169. *
  170. * \param props the properties to modify
  171. * \param name the name of the property to modify
  172. * \param value the new value of the property, or NULL to delete the property
  173. * \returns 0 on success or a negative error code on failure; call
  174. * SDL_GetError() for more information.
  175. *
  176. * \threadsafety It is safe to call this function from any thread.
  177. *
  178. * \since This function is available since SDL 3.0.0.
  179. *
  180. * \sa SDL_GetStringProperty
  181. */
  182. extern DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);
  183. /**
  184. * Set an integer property on a set of properties
  185. *
  186. * \param props the properties to modify
  187. * \param name the name of the property to modify
  188. * \param value the new value of the property
  189. * \returns 0 on success or a negative error code on failure; call
  190. * SDL_GetError() for more information.
  191. *
  192. * \threadsafety It is safe to call this function from any thread.
  193. *
  194. * \since This function is available since SDL 3.0.0.
  195. *
  196. * \sa SDL_GetNumberProperty
  197. */
  198. extern DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);
  199. /**
  200. * Set a floating point property on a set of properties
  201. *
  202. * \param props the properties to modify
  203. * \param name the name of the property to modify
  204. * \param value the new value of the property
  205. * \returns 0 on success or a negative error code on failure; call
  206. * SDL_GetError() for more information.
  207. *
  208. * \threadsafety It is safe to call this function from any thread.
  209. *
  210. * \since This function is available since SDL 3.0.0.
  211. *
  212. * \sa SDL_GetFloatProperty
  213. */
  214. extern DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);
  215. /**
  216. * Set a boolean property on a set of properties
  217. *
  218. * \param props the properties to modify
  219. * \param name the name of the property to modify
  220. * \param value the new value of the property
  221. * \returns 0 on success or a negative error code on failure; call
  222. * SDL_GetError() for more information.
  223. *
  224. * \threadsafety It is safe to call this function from any thread.
  225. *
  226. * \since This function is available since SDL 3.0.0.
  227. *
  228. * \sa SDL_GetBooleanProperty
  229. */
  230. extern DECLSPEC int SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value);
  231. /**
  232. * Return whether a property exists in a set of properties.
  233. *
  234. * \param props the properties to query
  235. * \param name the name of the property to query
  236. * \returns SDL_TRUE if the property exists, or SDL_FALSE if it doesn't.
  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. */
  244. extern DECLSPEC SDL_bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, const char *name);
  245. /**
  246. * Get the type of a property on a set of properties
  247. *
  248. * \param props the properties to query
  249. * \param name the name of the property to query
  250. * \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is
  251. * not set.
  252. *
  253. * \threadsafety It is safe to call this function from any thread.
  254. *
  255. * \since This function is available since SDL 3.0.0.
  256. *
  257. * \sa SDL_HasProperty
  258. */
  259. extern DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name);
  260. /**
  261. * Get a property on a set of properties
  262. *
  263. * By convention, the names of properties that SDL exposes on objects will
  264. * start with "SDL.", and properties that SDL uses internally will start with
  265. * "SDL.internal.". These should be considered read-only and should not be
  266. * modified by applications.
  267. *
  268. * \param props the properties to query
  269. * \param name the name of the property to query
  270. * \param default_value the default value of the property
  271. * \returns the value of the property, or `default_value` if it is not set or
  272. * not a pointer property.
  273. *
  274. * \threadsafety It is safe to call this function from any thread, although
  275. * the data returned is not protected and could potentially be
  276. * freed if you call SDL_SetProperty() or SDL_ClearProperty() on
  277. * these properties from another thread. If you need to avoid
  278. * this, use SDL_LockProperties() and SDL_UnlockProperties().
  279. *
  280. * \since This function is available since SDL 3.0.0.
  281. *
  282. * \sa SDL_GetPropertyType
  283. * \sa SDL_HasProperty
  284. * \sa SDL_SetProperty
  285. */
  286. extern DECLSPEC void *SDLCALL SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_value);
  287. /**
  288. * Get a string property on a set of properties
  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 string 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_HasProperty
  302. * \sa SDL_SetStringProperty
  303. */
  304. extern DECLSPEC const char *SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
  305. /**
  306. * Get a number property on a set of properties
  307. *
  308. * You can use SDL_GetPropertyType() to query whether the property exists and
  309. * is a number property.
  310. *
  311. * \param props the properties to query
  312. * \param name the name of the property to query
  313. * \param default_value the default value of the property
  314. * \returns the value of the property, or `default_value` if it is not set or
  315. * not a number property.
  316. *
  317. * \threadsafety It is safe to call this function from any thread.
  318. *
  319. * \since This function is available since SDL 3.0.0.
  320. *
  321. * \sa SDL_GetPropertyType
  322. * \sa SDL_HasProperty
  323. * \sa SDL_SetNumberProperty
  324. */
  325. extern DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value);
  326. /**
  327. * Get a floating point property on a set of properties
  328. *
  329. * You can use SDL_GetPropertyType() to query whether the property exists and
  330. * is a floating point property.
  331. *
  332. * \param props the properties to query
  333. * \param name the name of the property to query
  334. * \param default_value the default value of the property
  335. * \returns the value of the property, or `default_value` if it is not set or
  336. * not a float property.
  337. *
  338. * \threadsafety It is safe to call this function from any thread.
  339. *
  340. * \since This function is available since SDL 3.0.0.
  341. *
  342. * \sa SDL_GetPropertyType
  343. * \sa SDL_HasProperty
  344. * \sa SDL_SetFloatProperty
  345. */
  346. extern DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value);
  347. /**
  348. * Get a boolean property on a set of properties
  349. *
  350. * You can use SDL_GetPropertyType() to query whether the property exists and
  351. * is a boolean property.
  352. *
  353. * \param props the properties to query
  354. * \param name the name of the property to query
  355. * \param default_value the default value of the property
  356. * \returns the value of the property, or `default_value` if it is not set or
  357. * not a float property.
  358. *
  359. * \threadsafety It is safe to call this function from any thread.
  360. *
  361. * \since This function is available since SDL 3.0.0.
  362. *
  363. * \sa SDL_GetPropertyType
  364. * \sa SDL_HasProperty
  365. * \sa SDL_SetBooleanProperty
  366. */
  367. extern DECLSPEC SDL_bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool default_value);
  368. /**
  369. * Clear a property on a set of properties
  370. *
  371. * \param props the properties to modify
  372. * \param name the name of the property to clear
  373. * \returns 0 on success or a negative error code on failure; call
  374. * SDL_GetError() for more information.
  375. *
  376. * \threadsafety It is safe to call this function from any thread.
  377. *
  378. * \since This function is available since SDL 3.0.0.
  379. */
  380. extern DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);
  381. typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name);
  382. /**
  383. * Enumerate the properties on a set of properties
  384. *
  385. * The callback function is called for each property on the set of properties.
  386. * The properties are locked during enumeration.
  387. *
  388. * \param props the properties to query
  389. * \param callback the function to call for each property
  390. * \param userdata a pointer that is passed to `callback`
  391. * \returns 0 on success or a negative error code on failure; call
  392. * SDL_GetError() for more information.
  393. *
  394. * \threadsafety It is safe to call this function from any thread.
  395. *
  396. * \since This function is available since SDL 3.0.0.
  397. */
  398. extern DECLSPEC int SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);
  399. /**
  400. * Destroy a set of properties
  401. *
  402. * All properties are deleted and their cleanup functions will be called, if
  403. * any.
  404. *
  405. * \param props the properties to destroy
  406. *
  407. * \threadsafety This function should not be called while these properties are
  408. * locked or other threads might be setting or getting values
  409. * from these properties.
  410. *
  411. * \since This function is available since SDL 3.0.0.
  412. *
  413. * \sa SDL_CreateProperties
  414. */
  415. extern DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);
  416. /* Ends C function definitions when using C++ */
  417. #ifdef __cplusplus
  418. }
  419. #endif
  420. #include <SDL3/SDL_close_code.h>
  421. #endif /* SDL_properties_h_ */