SDL_properties.h 16 KB

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