SDL_properties.h 14 KB

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