SDL_properties.h 15 KB

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