SDL_properties.h 15 KB

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