libikarus/include/ikarus/values/value.h
2025-04-15 12:10:42 +02:00

66 lines
2.4 KiB
C

#pragma once
/// \file value.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/macros.h>
/// \defgroup values 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
/// @{
IKARUS_BEGIN_HEADER
/// \brief The common type for all values.
struct IkarusValue;
/// \brief Checks if a value is indeterminate.
/// \param value The value.
/// \pre \li Must not be null.
/// \return True if the value is indeterminate, false otherwise.
IKA_API bool ikarus_value_is_indeterminate(IkarusValue const * value);
/// \brief Sets the indeterminate state of a value.
/// \param value The value.
/// \pre \li Must not be null.
/// \param indeterminate The new indeterminate state.
IKA_API void ikarus_value_set_indeterminate(IkarusValue * value, bool indeterminate);
/// \brief Converts an entity value to a string.
/// \pre \li Must not be null.
/// \param value The entity value.
/// \return A string representation of the value or null if an error occurred.
/// \remark The returned value is owned by the caller.
IKA_API char const * ikarus_value_to_string(IkarusValue const * value);
/// \brief Visits an entity value, calling the appropriate function for the value's type.
/// \param value The entity value to visit.
/// \pre \li Must not be null.
/// \param toggle_visitor The function to call if the value is a toggle value. Skipped if null.
/// \param number_visitor The function to call if the value is a number value. Skipped if null.
/// \param text_visitor 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(
IkarusValue * value,
void (*toggle_visitor)(struct IkarusToggleValue *, void *),
void (*number_visitor)(struct IkarusNumberValue *, void *),
void (*text_visitor)(struct IkarusTextValue *, void *),
void * data
);
/// \see ikarus_value_visit
IKA_API void ikarus_value_visit_const(
IkarusValue const * value,
void (*toggle_visitor)(struct IkarusToggleValue const *, void *),
void (*number_visitor)(struct IkarusNumberValue const *, void *),
void (*text_visitor)(struct IkarusTextValue const *, void *),
void * data
);
IKARUS_END_HEADER
/// @}