#pragma once // IMPLEMENTATION_DETAIL_PROPERTY_TYPES /// \file value.h /// \author Folling #include #include #include IKARUS_BEGIN_HEADER /// \defgroup entity_value Entity Values /// \brief The values stored in entities. /// \details Each entity has a value for each property it is associated with. /// The value is of the type specified by the property and constrained by the property's settings. /// A value may be indeterminate which means it is unknown or not specified. /// \see PropertyType PropertySettings /// @{ /// \brief A true/false boolean-like value. For example "IsDead". struct IkarusToggleValue; /// \brief An arbitrary numeric value. For example "Age". struct IkarusNumberValue; /// \brief An arbitrary textual value. For example "First Name". struct IkarusTextValue; /// \brief The value of an entity associated with a property. struct IkarusEntityValue; /// \brief Creates a toggle value from a boolean. /// \param value The toggle value. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusToggleValue * ikarus_toggle_value_create(bool value); /// \brief Creates an indeterminate toggle value. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusToggleValue * ikarus_toggle_value_create_indeterminate(); /// \brief Sets the value of a toggle value. /// \param value The toggle value. /// \pre Must not be null. /// \param new_value The new value. IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, bool new_value); /// \brief Creates a number value from a number. /// \param value The number value. /// \pre Must be finite & not NaN. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusNumberValue * ikarus_number_value_create(long double value); /// \brief Creates an indeterminate number value. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusNumberValue * ikarus_number_value_create_indeterminate(); /// \brief Sets the value of a number value. /// \param value The number value. /// \pre Must not be null. /// \param new_value The new value. IKA_API void ikarus_number_value_set(IkarusNumberValue * value, bool new_value); /// \brief Creates a text value from string. /// \param value The text value. /// \pre Must not be null. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusTextValue * ikarus_text_value_create(char const * value); /// \brief Creates an indeterminate text value. /// \return The entity value. /// \remark Must be freed with #ikarus_free. IKA_API IkarusTextValue * ikarus_text_value_create_indeterminate(); /// \brief Sets the value of a text value. /// \param value The text value. /// \pre Must not be null. /// \param new_value The new value. IKA_API void ikarus_text_value_set(IkarusTextValue * value, bool new_value); /// \brief Checks if a toggle value is indeterminate. /// \param value The toggle value. /// \pre Must not be null. /// \return True if the value is indeterminate, false otherwise. IKA_API bool ikarus_toggle_value_is_indeterminate(IkarusToggleValue const * value); /// \brief Checks if a number value is indeterminate. /// \param value The number value. /// \pre Must not be null. /// \return True if the value is indeterminate, false otherwise. IKA_API bool ikarus_number_value_is_indeterminate(IkarusNumberValue const * value); /// \brief Checks if a text value is indeterminate. /// \param value The text value. /// \pre Must not be null. /// \return True if the value is indeterminate, false otherwise. IKA_API bool ikarus_text_value_is_indeterminate(IkarusTextValue const * value); /// \brief Fetches the underlying value of a toggle value. /// \param value The toggle value. /// \return The underlying value. /// \warning If the value is indeterminate, false is returned. IKA_API bool ikarus_toggle_value_get_underlying(IkarusToggleValue const * value); /// \brief Fetches the underlying value of a number value. /// \param value The number value. /// \return The underlying value. /// \warning If the value is indeterminate, 0.0 is returned. IKA_API long double ikarus_number_value_get_underlying(IkarusNumberValue const * value); /// \brief Fetches the underlying value of a text value. /// \param value The text value. /// \return A copy of the underlying value. /// \remark The returned value is a copy and owned by the caller. /// \warning If the value is indeterminate, an empty string is returned. IKA_API char const * ikarus_text_value_get_underlying(IkarusTextValue const * value); /// \brief Visits an entity value, calling the appropriate function for the value's type. /// \param value The entity value to visit. /// \param toggle The function to call if the value is a toggle value. Skipped if null. /// \param number The function to call if the value is a number value. Skipped if null. /// \param text The function to call if the value is a text value. Skipped if null. /// \param data The data passed to the visitor functions. IKA_API void ikarus_value_visit( IkarusEntityValue * value, void (*toggle)(IkarusToggleValue *, void *), void (*number)(IkarusNumberValue *, void *), void (*text)(IkarusTextValue *, void *), void * data ); IKARUS_END_HEADER