#pragma once /// \file property_settings.h /// \author Folling #include /// \defgroup property_settings PropertySettings /// \brief Property settings add additional constraints to properties. /// \details Each property has a certain set of settings. The options available depend on the type of the property. /// Settings can be changed after the property has been created. Examples of settings are: /// Note that the default value must be set using the concrete subtypes to ascertain type correctness. /// - Minimum: The minimum value for a number property. /// - Matches: A regular expression that the value of a text property must match. /// There are also some common settings, shared among all properties: /// - Default Value (default: PropertyType's default default (sic) value): The value that is returned if no value is specified /// for some entity. /// - List (default: false): If set to true, the property becomes a list. Instead of one number, you could then specify a series /// of numbers. Note that each element in the list is subject to changes in values. E.g. when we say that all values are changed /// in some way (e.g. reset to the default value), this applies to all elements in the list. /// - Allow undefined (default: false): If set to true, you can specify an "unknown" value for a property. /// It might not be known if a character is dead or not for example. /// @{ IKARUS_BEGIN_HEADER struct IkarusPropertySettings; /// \brief Gets the default value of a property. /// \param settings The settings to get the default value of. /// \pre \li Must not be null. /// \pre \li Must exist. /// \return The default value of the property or null if an error occurs. /// \remark Must be freed using #ikarus_free. IKA_API struct IkarusValue const * ikarus_property_settings_get_default_value(IkarusPropertySettings const * settings); /// \brief Fetches whether a property is a list. /// \param settings The property settings. /// \pre \li Must not be null. /// \return True if the property is a list, false otherwise. IKA_API bool ikarus_property_settings_is_list(IkarusPropertySettings const * settings); /// \brief Sets whether a property is a list. /// \details Noop if unchanged. A change from list -> single truncates to just the first element. A change from single -> list /// sets the first element to the current value. /// \param settings The property settings. /// \pre \li Must not be null. /// \param list Whether the property should be /// a list. IKA_API void ikarus_property_settings_set_is_list(IkarusPropertySettings * settings, bool list); /// \brief Fetches whether a property may be undefined. /// \param settings The property settings. /// \pre \li Must not be null. /// \return True if the property may be undefined, false otherwise. IKA_API bool ikarus_property_settings_may_be_undefined(IkarusPropertySettings const * settings); /// \brief Sets whether a property may be undefined. /// \details Noop if unchanged. If the transition is from undefined -> defined, all undefined values will be reset to the /// default value. /// \param settings The property settings. /// \pre \li Must not be null. /// \param allow_undefined Whether the property should be allowed to be undefined. /// \param allow_undefined Whether the property should be allowed to be undefined. IKA_API void ikarus_property_settings_set_may_be_undefined(IkarusPropertySettings * settings, bool allow_undefined); /// \brief Visits a property settings. Calling the appropriate function for the property's type. /// \param settings The property settings. /// \pre \li Must not be null. /// \param toggle_property_visitor The function to call if the property is a toggle property. Skipped if null. /// \param number_property_visitor The function to call if the property is a number property. Skipped if null. /// \param text_property_visitor The function to call if the property is a text property. Skipped if null. /// \param data Data passed to the visitors. IKA_API void ikarus_property_settings_visit( struct IkarusPropertySettings * settings, void (*toggle_property_visitor)(struct IkarusTogglePropertySettings * settings, void * data), void (*number_property_visitor)(struct IkarusNumberPropertySettings * settings, void * data), void (*text_property_visitor)(struct IkarusTextPropertySettings * settings, void * data), void * data ); IKA_API void ikarus_property_settings_visit_const( struct IkarusPropertySettings const * settings, void (*toggle_property_visitor)(struct IkarusTogglePropertySettings const * settings, void * data), void (*number_property_visitor)(struct IkarusNumberPropertySettings const * settings, void * data), void (*text_property_visitor)(struct IkarusTextPropertySettings const * settings, void * data), void * data ); IKARUS_END_HEADER /// @}