Atlas - SDL_properties.h
Home / ext / SDL / include / SDL3 Lines: 1 | Size: 20371 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22/** 23 * # CategoryProperties 24 * 25 * A property is a variable that can be created and retrieved by name at 26 * runtime. 27 * 28 * All properties are part of a property group (SDL_PropertiesID). A property 29 * group can be created with the SDL_CreateProperties function and destroyed 30 * with the SDL_DestroyProperties function. 31 * 32 * Properties can be added to and retrieved from a property group through the 33 * following functions: 34 * 35 * - SDL_SetPointerProperty and SDL_GetPointerProperty operate on `void*` 36 * pointer types. 37 * - SDL_SetStringProperty and SDL_GetStringProperty operate on string types. 38 * - SDL_SetNumberProperty and SDL_GetNumberProperty operate on signed 64-bit 39 * integer types. 40 * - SDL_SetFloatProperty and SDL_GetFloatProperty operate on floating point 41 * types. 42 * - SDL_SetBooleanProperty and SDL_GetBooleanProperty operate on boolean 43 * types. 44 * 45 * Properties can be removed from a group by using SDL_ClearProperty. 46 */ 47 48 49#ifndef SDL_properties_h_ 50#define SDL_properties_h_ 51 52#include <SDL3/SDL_stdinc.h> 53#include <SDL3/SDL_error.h> 54 55#include <SDL3/SDL_begin_code.h> 56/* Set up for C function definitions, even when using C++ */ 57#ifdef __cplusplus 58extern "C" { 59#endif 60 61/** 62 * An ID that represents a properties set. 63 * 64 * \since This datatype is available since SDL 3.2.0. 65 */ 66typedef Uint32 SDL_PropertiesID; 67 68/** 69 * SDL property type 70 * 71 * \since This enum is available since SDL 3.2.0. 72 */ 73typedef enum SDL_PropertyType 74{ 75 SDL_PROPERTY_TYPE_INVALID, 76 SDL_PROPERTY_TYPE_POINTER, 77 SDL_PROPERTY_TYPE_STRING, 78 SDL_PROPERTY_TYPE_NUMBER, 79 SDL_PROPERTY_TYPE_FLOAT, 80 SDL_PROPERTY_TYPE_BOOLEAN 81} SDL_PropertyType; 82 83/** 84 * A generic property for naming things. 85 * 86 * This property is intended to be added to any SDL_PropertiesID that needs a 87 * generic name associated with the property set. It is not guaranteed that 88 * any property set will include this key, but it is convenient to have a 89 * standard key that any piece of code could reasonably agree to use. 90 * 91 * For example, the properties associated with an SDL_Texture might have a 92 * name string of "player sprites", or an SDL_AudioStream might have 93 * "background music", etc. This might also be useful for an SDL_IOStream to 94 * list the path to its asset. 95 * 96 * There is no format for the value set with this key; it is expected to be 97 * human-readable and informational in nature, possibly for logging or 98 * debugging purposes. 99 * 100 * SDL does not currently set this property on any objects it creates, but 101 * this may change in later versions; it is currently expected that apps and 102 * external libraries will take advantage of it, when appropriate. 103 * 104 * \since This macro is available since SDL 3.4.0. 105 */ 106#define SDL_PROP_NAME_STRING "SDL.name" 107 108/** 109 * Get the global SDL properties. 110 * 111 * \returns a valid property ID on success or 0 on failure; call 112 * SDL_GetError() for more information. 113 * 114 * \threadsafety It is safe to call this function from any thread. 115 * 116 * \since This function is available since SDL 3.2.0. 117 */ 118extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void); 119 120/** 121 * Create a group of properties. 122 * 123 * All properties are automatically destroyed when SDL_Quit() is called. 124 * 125 * \returns an ID for a new group of properties, or 0 on failure; call 126 * SDL_GetError() for more information. 127 * 128 * \threadsafety It is safe to call this function from any thread. 129 * 130 * \since This function is available since SDL 3.2.0. 131 * 132 * \sa SDL_DestroyProperties 133 */ 134extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void); 135 136/** 137 * Copy a group of properties. 138 * 139 * Copy all the properties from one group of properties to another, with the 140 * exception of properties requiring cleanup (set using 141 * SDL_SetPointerPropertyWithCleanup()), which will not be copied. Any 142 * property that already exists on `dst` will be overwritten. 143 * 144 * \param src the properties to copy. 145 * \param dst the destination properties. 146 * \returns true on success or false on failure; call SDL_GetError() for more 147 * information. 148 * 149 * \threadsafety It is safe to call this function from any thread. This 150 * function acquires simultaneous mutex locks on both the source 151 * and destination property sets. 152 * 153 * \since This function is available since SDL 3.2.0. 154 */ 155extern SDL_DECLSPEC bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst); 156 157/** 158 * Lock a group of properties. 159 * 160 * Obtain a multi-threaded lock for these properties. Other threads will wait 161 * while trying to lock these properties until they are unlocked. Properties 162 * must be unlocked before they are destroyed. 163 * 164 * The lock is automatically taken when setting individual properties, this 165 * function is only needed when you want to set several properties atomically 166 * or want to guarantee that properties being queried aren't freed in another 167 * thread. 168 * 169 * \param props the properties to lock. 170 * \returns true on success or false on failure; call SDL_GetError() for more 171 * information. 172 * 173 * \threadsafety It is safe to call this function from any thread. 174 * 175 * \since This function is available since SDL 3.2.0. 176 * 177 * \sa SDL_UnlockProperties 178 */ 179extern SDL_DECLSPEC bool SDLCALL SDL_LockProperties(SDL_PropertiesID props); 180 181/** 182 * Unlock a group of properties. 183 * 184 * \param props the properties to unlock. 185 * 186 * \threadsafety It is safe to call this function from any thread. 187 * 188 * \since This function is available since SDL 3.2.0. 189 * 190 * \sa SDL_LockProperties 191 */ 192extern SDL_DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props); 193 194/** 195 * A callback used to free resources when a property is deleted. 196 * 197 * This should release any resources associated with `value` that are no 198 * longer needed. 199 * 200 * This callback is set per-property. Different properties in the same group 201 * can have different cleanup callbacks. 202 * 203 * This callback will be called _during_ SDL_SetPointerPropertyWithCleanup if 204 * the function fails for any reason. 205 * 206 * \param userdata an app-defined pointer passed to the callback. 207 * \param value the pointer assigned to the property to clean up. 208 * 209 * \threadsafety This callback may fire without any locks held; if this is a 210 * concern, the app should provide its own locking. 211 * 212 * \since This datatype is available since SDL 3.2.0. 213 * 214 * \sa SDL_SetPointerPropertyWithCleanup 215 */ 216typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value); 217 218/** 219 * Set a pointer property in a group of properties with a cleanup function 220 * that is called when the property is deleted. 221 * 222 * The cleanup function is also called if setting the property fails for any 223 * reason. 224 * 225 * For simply setting basic data types, like numbers, bools, or strings, use 226 * SDL_SetNumberProperty, SDL_SetBooleanProperty, or SDL_SetStringProperty 227 * instead, as those functions will handle cleanup on your behalf. This 228 * function is only for more complex, custom data. 229 * 230 * \param props the properties to modify. 231 * \param name the name of the property to modify. 232 * \param value the new value of the property, or NULL to delete the property. 233 * \param cleanup the function to call when this property is deleted, or NULL 234 * if no cleanup is necessary. 235 * \param userdata a pointer that is passed to the cleanup function. 236 * \returns true on success or false on failure; call SDL_GetError() for more 237 * information. 238 * 239 * \threadsafety It is safe to call this function from any thread. 240 * 241 * \since This function is available since SDL 3.2.0. 242 * 243 * \sa SDL_GetPointerProperty 244 * \sa SDL_SetPointerProperty 245 * \sa SDL_CleanupPropertyCallback 246 */ 247extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata); 248 249/** 250 * Set a pointer property in a group of properties. 251 * 252 * \param props the properties to modify. 253 * \param name the name of the property to modify. 254 * \param value the new value of the property, or NULL to delete the property. 255 * \returns true on success or false on failure; call SDL_GetError() for more 256 * information. 257 * 258 * \threadsafety It is safe to call this function from any thread. 259 * 260 * \since This function is available since SDL 3.2.0. 261 * 262 * \sa SDL_GetPointerProperty 263 * \sa SDL_HasProperty 264 * \sa SDL_SetBooleanProperty 265 * \sa SDL_SetFloatProperty 266 * \sa SDL_SetNumberProperty 267 * \sa SDL_SetPointerPropertyWithCleanup 268 * \sa SDL_SetStringProperty 269 */ 270extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value); 271 272/** 273 * Set a string property in a group of properties. 274 * 275 * This function makes a copy of the string; the caller does not have to 276 * preserve the data after this call completes. 277 * 278 * \param props the properties to modify. 279 * \param name the name of the property to modify. 280 * \param value the new value of the property, or NULL to delete the property. 281 * \returns true on success or false on failure; call SDL_GetError() for more 282 * information. 283 * 284 * \threadsafety It is safe to call this function from any thread. 285 * 286 * \since This function is available since SDL 3.2.0. 287 * 288 * \sa SDL_GetStringProperty 289 */ 290extern SDL_DECLSPEC bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value); 291 292/** 293 * Set an integer property in a group of properties. 294 * 295 * \param props the properties to modify. 296 * \param name the name of the property to modify. 297 * \param value the new value of the property. 298 * \returns true on success or false on failure; call SDL_GetError() for more 299 * information. 300 * 301 * \threadsafety It is safe to call this function from any thread. 302 * 303 * \since This function is available since SDL 3.2.0. 304 * 305 * \sa SDL_GetNumberProperty 306 */ 307extern SDL_DECLSPEC bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value); 308 309/** 310 * Set a floating point property in a group of properties. 311 * 312 * \param props the properties to modify. 313 * \param name the name of the property to modify. 314 * \param value the new value of the property. 315 * \returns true on success or false on failure; call SDL_GetError() for more 316 * information. 317 * 318 * \threadsafety It is safe to call this function from any thread. 319 * 320 * \since This function is available since SDL 3.2.0. 321 * 322 * \sa SDL_GetFloatProperty 323 */ 324extern SDL_DECLSPEC bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value); 325 326/** 327 * Set a boolean property in a group of properties. 328 * 329 * \param props the properties to modify. 330 * \param name the name of the property to modify. 331 * \param value the new value of the property. 332 * \returns true on success or false on failure; call SDL_GetError() for more 333 * information. 334 * 335 * \threadsafety It is safe to call this function from any thread. 336 * 337 * \since This function is available since SDL 3.2.0. 338 * 339 * \sa SDL_GetBooleanProperty 340 */ 341extern SDL_DECLSPEC bool SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, bool value); 342 343/** 344 * Return whether a property exists in a group of properties. 345 * 346 * \param props the properties to query. 347 * \param name the name of the property to query. 348 * \returns true if the property exists, or false if it doesn't. 349 * 350 * \threadsafety It is safe to call this function from any thread. 351 * 352 * \since This function is available since SDL 3.2.0. 353 * 354 * \sa SDL_GetPropertyType 355 */ 356extern SDL_DECLSPEC bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, const char *name); 357 358/** 359 * Get the type of a property in a group of properties. 360 * 361 * \param props the properties to query. 362 * \param name the name of the property to query. 363 * \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is 364 * not set. 365 * 366 * \threadsafety It is safe to call this function from any thread. 367 * 368 * \since This function is available since SDL 3.2.0. 369 * 370 * \sa SDL_HasProperty 371 */ 372extern SDL_DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name); 373 374/** 375 * Get a pointer property from a group of properties. 376 * 377 * By convention, the names of properties that SDL exposes on objects will 378 * start with "SDL.", and properties that SDL uses internally will start with 379 * "SDL.internal.". These should be considered read-only and should not be 380 * modified by applications. 381 * 382 * \param props the properties to query. 383 * \param name the name of the property to query. 384 * \param default_value the default value of the property. 385 * \returns the value of the property, or `default_value` if it is not set or 386 * not a pointer property. 387 * 388 * \threadsafety It is safe to call this function from any thread, although 389 * the data returned is not protected and could potentially be 390 * freed if you call SDL_SetPointerProperty() or 391 * SDL_ClearProperty() on these properties from another thread. 392 * If you need to avoid this, use SDL_LockProperties() and 393 * SDL_UnlockProperties(). 394 * 395 * \since This function is available since SDL 3.2.0. 396 * 397 * \sa SDL_GetBooleanProperty 398 * \sa SDL_GetFloatProperty 399 * \sa SDL_GetNumberProperty 400 * \sa SDL_GetPropertyType 401 * \sa SDL_GetStringProperty 402 * \sa SDL_HasProperty 403 * \sa SDL_SetPointerProperty 404 */ 405extern SDL_DECLSPEC void * SDLCALL SDL_GetPointerProperty(SDL_PropertiesID props, const char *name, void *default_value); 406 407/** 408 * Get a string property from a group of properties. 409 * 410 * \param props the properties to query. 411 * \param name the name of the property to query. 412 * \param default_value the default value of the property. 413 * \returns the value of the property, or `default_value` if it is not set or 414 * not a string property. 415 * 416 * \threadsafety It is safe to call this function from any thread, although 417 * the data returned is not protected and could potentially be 418 * freed if you call SDL_SetStringProperty() or 419 * SDL_ClearProperty() on these properties from another thread. 420 * If you need to avoid this, use SDL_LockProperties() and 421 * SDL_UnlockProperties(). 422 * 423 * \since This function is available since SDL 3.2.0. 424 * 425 * \sa SDL_GetPropertyType 426 * \sa SDL_HasProperty 427 * \sa SDL_SetStringProperty 428 */ 429extern SDL_DECLSPEC const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value); 430 431/** 432 * Get a number property from a group of properties. 433 * 434 * You can use SDL_GetPropertyType() to query whether the property exists and 435 * is a number property. 436 * 437 * \param props the properties to query. 438 * \param name the name of the property to query. 439 * \param default_value the default value of the property. 440 * \returns the value of the property, or `default_value` if it is not set or 441 * not a number property. 442 * 443 * \threadsafety It is safe to call this function from any thread. 444 * 445 * \since This function is available since SDL 3.2.0. 446 * 447 * \sa SDL_GetPropertyType 448 * \sa SDL_HasProperty 449 * \sa SDL_SetNumberProperty 450 */ 451extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value); 452 453/** 454 * Get a floating point property from a group of properties. 455 * 456 * You can use SDL_GetPropertyType() to query whether the property exists and 457 * is a floating point property. 458 * 459 * \param props the properties to query. 460 * \param name the name of the property to query. 461 * \param default_value the default value of the property. 462 * \returns the value of the property, or `default_value` if it is not set or 463 * not a float property. 464 * 465 * \threadsafety It is safe to call this function from any thread. 466 * 467 * \since This function is available since SDL 3.2.0. 468 * 469 * \sa SDL_GetPropertyType 470 * \sa SDL_HasProperty 471 * \sa SDL_SetFloatProperty 472 */ 473extern SDL_DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value); 474 475/** 476 * Get a boolean property from a group of properties. 477 * 478 * You can use SDL_GetPropertyType() to query whether the property exists and 479 * is a boolean property. 480 * 481 * \param props the properties to query. 482 * \param name the name of the property to query. 483 * \param default_value the default value of the property. 484 * \returns the value of the property, or `default_value` if it is not set or 485 * not a boolean property. 486 * 487 * \threadsafety It is safe to call this function from any thread. 488 * 489 * \since This function is available since SDL 3.2.0. 490 * 491 * \sa SDL_GetPropertyType 492 * \sa SDL_HasProperty 493 * \sa SDL_SetBooleanProperty 494 */ 495extern SDL_DECLSPEC bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, bool default_value); 496 497/** 498 * Clear a property from a group of properties. 499 * 500 * \param props the properties to modify. 501 * \param name the name of the property to clear. 502 * \returns true on success or false on failure; call SDL_GetError() for more 503 * information. 504 * 505 * \threadsafety It is safe to call this function from any thread. 506 * 507 * \since This function is available since SDL 3.2.0. 508 */ 509extern SDL_DECLSPEC bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name); 510 511/** 512 * A callback used to enumerate all the properties in a group of properties. 513 * 514 * This callback is called from SDL_EnumerateProperties(), and is called once 515 * per property in the set. 516 * 517 * \param userdata an app-defined pointer passed to the callback. 518 * \param props the SDL_PropertiesID that is being enumerated. 519 * \param name the next property name in the enumeration. 520 * 521 * \threadsafety SDL_EnumerateProperties holds a lock on `props` during this 522 * callback. 523 * 524 * \since This datatype is available since SDL 3.2.0. 525 * 526 * \sa SDL_EnumerateProperties 527 */ 528typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name); 529 530/** 531 * Enumerate the properties contained in a group of properties. 532 * 533 * The callback function is called for each property in the group of 534 * properties. The properties are locked during enumeration. 535 * 536 * \param props the properties to query. 537 * \param callback the function to call for each property. 538 * \param userdata a pointer that is passed to `callback`. 539 * \returns true on success or false on failure; call SDL_GetError() for more 540 * information. 541 * 542 * \threadsafety It is safe to call this function from any thread. 543 * 544 * \since This function is available since SDL 3.2.0. 545 */ 546extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata); 547 548/** 549 * Destroy a group of properties. 550 * 551 * All properties are deleted and their cleanup functions will be called, if 552 * any. 553 * 554 * \param props the properties to destroy. 555 * 556 * \threadsafety This function should not be called while these properties are 557 * locked or other threads might be setting or getting values 558 * from these properties. 559 * 560 * \since This function is available since SDL 3.2.0. 561 * 562 * \sa SDL_CreateProperties 563 */ 564extern SDL_DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props); 565 566/* Ends C function definitions when using C++ */ 567#ifdef __cplusplus 568} 569#endif 570#include <SDL3/SDL_close_code.h> 571 572#endif /* SDL_properties_h_ */ 573[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.