split property & values into separate classes and files
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
f38ebeab14
commit
e377340781
28 changed files with 700 additions and 269 deletions
44
include/ikarus/values/number_value.h
Normal file
44
include/ikarus/values/number_value.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
/// \file number_value.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup entity_value Entity Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
struct IkarusNumberValue;
|
||||
|
||||
/// \brief Creates a number value from a long double.
|
||||
/// \param value The numeric value.
|
||||
/// \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 \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, bool new_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, false is returned.
|
||||
IKA_API long double ikarus_number_value_get_underlying(IkarusNumberValue const * value);
|
||||
|
||||
/// \brief Converts a number value to an entity value.
|
||||
/// \param number_value The number value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusEntityValue * ikarus_number_value_to_entity_value(IkarusNumberValue * number_value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
44
include/ikarus/values/text_value.h
Normal file
44
include/ikarus/values/text_value.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
/// \file text_value.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup entity_value Entity Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
struct IkarusTextValue;
|
||||
|
||||
/// \brief Creates a text value from a boolean.
|
||||
/// \param value The text value.
|
||||
/// \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 \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_text_value_set(IkarusTextValue * value, bool new_value);
|
||||
|
||||
/// \brief Fetches the underlying value of a text value.
|
||||
/// \param value The text value.
|
||||
/// \return The underlying value.
|
||||
/// \warning If the value is indeterminate, false is returned.
|
||||
IKA_API char const * ikarus_text_value_get_underlying(IkarusTextValue const * value);
|
||||
|
||||
/// \brief Converts a text value to an entity value.
|
||||
/// \param text_value The text value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusEntityValue * ikarus_text_value_to_entity_value(IkarusTextValue * text_value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
44
include/ikarus/values/toggle_value.h
Normal file
44
include/ikarus/values/toggle_value.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
/// \file toggle_value.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup entity_value Entity Values
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
struct IkarusToggleValue;
|
||||
|
||||
/// \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 \li Must not be null.
|
||||
/// \param new_value The new value.
|
||||
IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, bool new_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 Converts a toggle value to an entity value.
|
||||
/// \param toggle_value The toggle value to convert.
|
||||
/// \return The converted entity value.
|
||||
IKA_API struct IkarusEntityValue * ikarus_toggle_value_to_entity_value(IkarusToggleValue * toggle_value);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
|
@ -1,16 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
// IMPLEMENTATION_DETAIL_PROPERTY_TYPES
|
||||
|
||||
/// \file value.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/property_type.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
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.
|
||||
|
|
@ -19,112 +14,47 @@ IKARUS_BEGIN_HEADER
|
|||
/// \see PropertyType PropertySettings
|
||||
/// @{
|
||||
|
||||
/// \brief A true/false boolean-like value. For example "IsDead".
|
||||
struct IkarusToggleValue;
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief An arbitrary numeric value. For example "Age".
|
||||
struct IkarusNumberValue;
|
||||
/// \brief The common type for all values.
|
||||
struct IkarusValue;
|
||||
|
||||
/// \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.
|
||||
/// \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_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);
|
||||
IKA_API bool ikarus_value_is_indeterminate(IkarusValue 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 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 a copy and 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.
|
||||
/// \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 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(
|
||||
IkarusEntityValue * value,
|
||||
void (*toggle)(IkarusToggleValue *, void *),
|
||||
void (*number)(IkarusNumberValue *, void *),
|
||||
void (*text)(IkarusTextValue *, void *),
|
||||
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
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue