Path: blob/master/thirdparty/sdl/include/SDL3/SDL_properties.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryProperties23*24* A property is a variable that can be created and retrieved by name at25* runtime.26*27* All properties are part of a property group (SDL_PropertiesID). A property28* group can be created with the SDL_CreateProperties function and destroyed29* with the SDL_DestroyProperties function.30*31* Properties can be added to and retrieved from a property group through the32* following functions:33*34* - SDL_SetPointerProperty and SDL_GetPointerProperty operate on `void*`35* pointer types.36* - SDL_SetStringProperty and SDL_GetStringProperty operate on string types.37* - SDL_SetNumberProperty and SDL_GetNumberProperty operate on signed 64-bit38* integer types.39* - SDL_SetFloatProperty and SDL_GetFloatProperty operate on floating point40* types.41* - SDL_SetBooleanProperty and SDL_GetBooleanProperty operate on boolean42* types.43*44* Properties can be removed from a group by using SDL_ClearProperty.45*/464748#ifndef SDL_properties_h_49#define SDL_properties_h_5051#include <SDL3/SDL_stdinc.h>52#include <SDL3/SDL_error.h>5354#include <SDL3/SDL_begin_code.h>55/* Set up for C function definitions, even when using C++ */56#ifdef __cplusplus57extern "C" {58#endif5960/**61* SDL properties ID62*63* \since This datatype is available since SDL 3.2.0.64*/65typedef Uint32 SDL_PropertiesID;6667/**68* SDL property type69*70* \since This enum is available since SDL 3.2.0.71*/72typedef enum SDL_PropertyType73{74SDL_PROPERTY_TYPE_INVALID,75SDL_PROPERTY_TYPE_POINTER,76SDL_PROPERTY_TYPE_STRING,77SDL_PROPERTY_TYPE_NUMBER,78SDL_PROPERTY_TYPE_FLOAT,79SDL_PROPERTY_TYPE_BOOLEAN80} SDL_PropertyType;8182/**83* Get the global SDL properties.84*85* \returns a valid property ID on success or 0 on failure; call86* SDL_GetError() for more information.87*88* \since This function is available since SDL 3.2.0.89*/90extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGlobalProperties(void);9192/**93* Create a group of properties.94*95* All properties are automatically destroyed when SDL_Quit() is called.96*97* \returns an ID for a new group of properties, or 0 on failure; call98* SDL_GetError() for more information.99*100* \threadsafety It is safe to call this function from any thread.101*102* \since This function is available since SDL 3.2.0.103*104* \sa SDL_DestroyProperties105*/106extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void);107108/**109* Copy a group of properties.110*111* Copy all the properties from one group of properties to another, with the112* exception of properties requiring cleanup (set using113* SDL_SetPointerPropertyWithCleanup()), which will not be copied. Any114* property that already exists on `dst` will be overwritten.115*116* \param src the properties to copy.117* \param dst the destination properties.118* \returns true on success or false on failure; call SDL_GetError() for more119* information.120*121* \threadsafety It is safe to call this function from any thread.122*123* \since This function is available since SDL 3.2.0.124*/125extern SDL_DECLSPEC bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst);126127/**128* Lock a group of properties.129*130* Obtain a multi-threaded lock for these properties. Other threads will wait131* while trying to lock these properties until they are unlocked. Properties132* must be unlocked before they are destroyed.133*134* The lock is automatically taken when setting individual properties, this135* function is only needed when you want to set several properties atomically136* or want to guarantee that properties being queried aren't freed in another137* thread.138*139* \param props the properties to lock.140* \returns true on success or false on failure; call SDL_GetError() for more141* information.142*143* \threadsafety It is safe to call this function from any thread.144*145* \since This function is available since SDL 3.2.0.146*147* \sa SDL_UnlockProperties148*/149extern SDL_DECLSPEC bool SDLCALL SDL_LockProperties(SDL_PropertiesID props);150151/**152* Unlock a group of properties.153*154* \param props the properties to unlock.155*156* \threadsafety It is safe to call this function from any thread.157*158* \since This function is available since SDL 3.2.0.159*160* \sa SDL_LockProperties161*/162extern SDL_DECLSPEC void SDLCALL SDL_UnlockProperties(SDL_PropertiesID props);163164/**165* A callback used to free resources when a property is deleted.166*167* This should release any resources associated with `value` that are no168* longer needed.169*170* This callback is set per-property. Different properties in the same group171* can have different cleanup callbacks.172*173* This callback will be called _during_ SDL_SetPointerPropertyWithCleanup if174* the function fails for any reason.175*176* \param userdata an app-defined pointer passed to the callback.177* \param value the pointer assigned to the property to clean up.178*179* \threadsafety This callback may fire without any locks held; if this is a180* concern, the app should provide its own locking.181*182* \since This datatype is available since SDL 3.2.0.183*184* \sa SDL_SetPointerPropertyWithCleanup185*/186typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value);187188/**189* Set a pointer property in a group of properties with a cleanup function190* that is called when the property is deleted.191*192* The cleanup function is also called if setting the property fails for any193* reason.194*195* For simply setting basic data types, like numbers, bools, or strings, use196* SDL_SetNumberProperty, SDL_SetBooleanProperty, or SDL_SetStringProperty197* instead, as those functions will handle cleanup on your behalf. This198* function is only for more complex, custom data.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, or NULL to delete the property.203* \param cleanup the function to call when this property is deleted, or NULL204* if no cleanup is necessary.205* \param userdata a pointer that is passed to the cleanup function.206* \returns true on success or false on failure; call SDL_GetError() for more207* information.208*209* \threadsafety It is safe to call this function from any thread.210*211* \since This function is available since SDL 3.2.0.212*213* \sa SDL_GetPointerProperty214* \sa SDL_SetPointerProperty215* \sa SDL_CleanupPropertyCallback216*/217extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata);218219/**220* Set a pointer property in a group of properties.221*222* \param props the properties to modify.223* \param name the name of the property to modify.224* \param value the new value of the property, or NULL to delete the property.225* \returns true on success or false on failure; call SDL_GetError() for more226* information.227*228* \threadsafety It is safe to call this function from any thread.229*230* \since This function is available since SDL 3.2.0.231*232* \sa SDL_GetPointerProperty233* \sa SDL_HasProperty234* \sa SDL_SetBooleanProperty235* \sa SDL_SetFloatProperty236* \sa SDL_SetNumberProperty237* \sa SDL_SetPointerPropertyWithCleanup238* \sa SDL_SetStringProperty239*/240extern SDL_DECLSPEC bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value);241242/**243* Set a string property in a group of properties.244*245* This function makes a copy of the string; the caller does not have to246* preserve the data after this call completes.247*248* \param props the properties to modify.249* \param name the name of the property to modify.250* \param value the new value of the property, or NULL to delete the property.251* \returns true on success or false on failure; call SDL_GetError() for more252* information.253*254* \threadsafety It is safe to call this function from any thread.255*256* \since This function is available since SDL 3.2.0.257*258* \sa SDL_GetStringProperty259*/260extern SDL_DECLSPEC bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value);261262/**263* Set an integer property in a group of properties.264*265* \param props the properties to modify.266* \param name the name of the property to modify.267* \param value the new value of the property.268* \returns true on success or false on failure; call SDL_GetError() for more269* information.270*271* \threadsafety It is safe to call this function from any thread.272*273* \since This function is available since SDL 3.2.0.274*275* \sa SDL_GetNumberProperty276*/277extern SDL_DECLSPEC bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value);278279/**280* Set a floating point property in a group of properties.281*282* \param props the properties to modify.283* \param name the name of the property to modify.284* \param value the new value of the property.285* \returns true on success or false on failure; call SDL_GetError() for more286* information.287*288* \threadsafety It is safe to call this function from any thread.289*290* \since This function is available since SDL 3.2.0.291*292* \sa SDL_GetFloatProperty293*/294extern SDL_DECLSPEC bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value);295296/**297* Set a boolean property in a group of properties.298*299* \param props the properties to modify.300* \param name the name of the property to modify.301* \param value the new value of the property.302* \returns true on success or false on failure; call SDL_GetError() for more303* information.304*305* \threadsafety It is safe to call this function from any thread.306*307* \since This function is available since SDL 3.2.0.308*309* \sa SDL_GetBooleanProperty310*/311extern SDL_DECLSPEC bool SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, bool value);312313/**314* Return whether a property exists in a group of properties.315*316* \param props the properties to query.317* \param name the name of the property to query.318* \returns true if the property exists, or false if it doesn't.319*320* \threadsafety It is safe to call this function from any thread.321*322* \since This function is available since SDL 3.2.0.323*324* \sa SDL_GetPropertyType325*/326extern SDL_DECLSPEC bool SDLCALL SDL_HasProperty(SDL_PropertiesID props, const char *name);327328/**329* Get the type of a property in a group of properties.330*331* \param props the properties to query.332* \param name the name of the property to query.333* \returns the type of the property, or SDL_PROPERTY_TYPE_INVALID if it is334* not set.335*336* \threadsafety It is safe to call this function from any thread.337*338* \since This function is available since SDL 3.2.0.339*340* \sa SDL_HasProperty341*/342extern SDL_DECLSPEC SDL_PropertyType SDLCALL SDL_GetPropertyType(SDL_PropertiesID props, const char *name);343344/**345* Get a pointer property from a group of properties.346*347* By convention, the names of properties that SDL exposes on objects will348* start with "SDL.", and properties that SDL uses internally will start with349* "SDL.internal.". These should be considered read-only and should not be350* modified by applications.351*352* \param props the properties to query.353* \param name the name of the property to query.354* \param default_value the default value of the property.355* \returns the value of the property, or `default_value` if it is not set or356* not a pointer property.357*358* \threadsafety It is safe to call this function from any thread, although359* the data returned is not protected and could potentially be360* freed if you call SDL_SetPointerProperty() or361* SDL_ClearProperty() on these properties from another thread.362* If you need to avoid this, use SDL_LockProperties() and363* SDL_UnlockProperties().364*365* \since This function is available since SDL 3.2.0.366*367* \sa SDL_GetBooleanProperty368* \sa SDL_GetFloatProperty369* \sa SDL_GetNumberProperty370* \sa SDL_GetPropertyType371* \sa SDL_GetStringProperty372* \sa SDL_HasProperty373* \sa SDL_SetPointerProperty374*/375extern SDL_DECLSPEC void * SDLCALL SDL_GetPointerProperty(SDL_PropertiesID props, const char *name, void *default_value);376377/**378* Get a string property from a group of properties.379*380* \param props the properties to query.381* \param name the name of the property to query.382* \param default_value the default value of the property.383* \returns the value of the property, or `default_value` if it is not set or384* not a string property.385*386* \threadsafety It is safe to call this function from any thread, although387* the data returned is not protected and could potentially be388* freed if you call SDL_SetStringProperty() or389* SDL_ClearProperty() on these properties from another thread.390* If you need to avoid this, use SDL_LockProperties() and391* SDL_UnlockProperties().392*393* \since This function is available since SDL 3.2.0.394*395* \sa SDL_GetPropertyType396* \sa SDL_HasProperty397* \sa SDL_SetStringProperty398*/399extern SDL_DECLSPEC const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);400401/**402* Get a number property from a group of properties.403*404* You can use SDL_GetPropertyType() to query whether the property exists and405* is a number property.406*407* \param props the properties to query.408* \param name the name of the property to query.409* \param default_value the default value of the property.410* \returns the value of the property, or `default_value` if it is not set or411* not a number property.412*413* \threadsafety It is safe to call this function from any thread.414*415* \since This function is available since SDL 3.2.0.416*417* \sa SDL_GetPropertyType418* \sa SDL_HasProperty419* \sa SDL_SetNumberProperty420*/421extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 default_value);422423/**424* Get a floating point property from a group of properties.425*426* You can use SDL_GetPropertyType() to query whether the property exists and427* is a floating point property.428*429* \param props the properties to query.430* \param name the name of the property to query.431* \param default_value the default value of the property.432* \returns the value of the property, or `default_value` if it is not set or433* not a float property.434*435* \threadsafety It is safe to call this function from any thread.436*437* \since This function is available since SDL 3.2.0.438*439* \sa SDL_GetPropertyType440* \sa SDL_HasProperty441* \sa SDL_SetFloatProperty442*/443extern SDL_DECLSPEC float SDLCALL SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float default_value);444445/**446* Get a boolean property from a group of properties.447*448* You can use SDL_GetPropertyType() to query whether the property exists and449* is a boolean property.450*451* \param props the properties to query.452* \param name the name of the property to query.453* \param default_value the default value of the property.454* \returns the value of the property, or `default_value` if it is not set or455* not a boolean property.456*457* \threadsafety It is safe to call this function from any thread.458*459* \since This function is available since SDL 3.2.0.460*461* \sa SDL_GetPropertyType462* \sa SDL_HasProperty463* \sa SDL_SetBooleanProperty464*/465extern SDL_DECLSPEC bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, bool default_value);466467/**468* Clear a property from a group of properties.469*470* \param props the properties to modify.471* \param name the name of the property to clear.472* \returns true on success or false on failure; call SDL_GetError() for more473* information.474*475* \threadsafety It is safe to call this function from any thread.476*477* \since This function is available since SDL 3.2.0.478*/479extern SDL_DECLSPEC bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name);480481/**482* A callback used to enumerate all the properties in a group of properties.483*484* This callback is called from SDL_EnumerateProperties(), and is called once485* per property in the set.486*487* \param userdata an app-defined pointer passed to the callback.488* \param props the SDL_PropertiesID that is being enumerated.489* \param name the next property name in the enumeration.490*491* \threadsafety SDL_EnumerateProperties holds a lock on `props` during this492* callback.493*494* \since This datatype is available since SDL 3.2.0.495*496* \sa SDL_EnumerateProperties497*/498typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_PropertiesID props, const char *name);499500/**501* Enumerate the properties contained in a group of properties.502*503* The callback function is called for each property in the group of504* properties. The properties are locked during enumeration.505*506* \param props the properties to query.507* \param callback the function to call for each property.508* \param userdata a pointer that is passed to `callback`.509* \returns true on success or false on failure; call SDL_GetError() for more510* information.511*512* \threadsafety It is safe to call this function from any thread.513*514* \since This function is available since SDL 3.2.0.515*/516extern SDL_DECLSPEC bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata);517518/**519* Destroy a group of properties.520*521* All properties are deleted and their cleanup functions will be called, if522* any.523*524* \param props the properties to destroy.525*526* \threadsafety This function should not be called while these properties are527* locked or other threads might be setting or getting values528* from these properties.529*530* \since This function is available since SDL 3.2.0.531*532* \sa SDL_CreateProperties533*/534extern SDL_DECLSPEC void SDLCALL SDL_DestroyProperties(SDL_PropertiesID props);535536/* Ends C function definitions when using C++ */537#ifdef __cplusplus538}539#endif540#include <SDL3/SDL_close_code.h>541542#endif /* SDL_properties_h_ */543544545