implement toggle/number/text values

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
folling 2023-11-26 13:55:14 +01:00 committed by Folling
parent ea221cdf85
commit ff9bf0c14a
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
14 changed files with 280 additions and 48 deletions

View file

@ -33,28 +33,28 @@ enum IkarusErrorInfo {
/// \brief No error occurred.
IkarusErrorInfo_Type_None = 0x0002000000000000,
/// \brief The user misused the API.
/// \example Accessing a resource that does not exist.
/// Example: Accessing a resource that does not exist.
IkarusErrorInfo_Type_Client_Misuse = 0x0002000100000001,
/// \brief The user provided invalid input.
/// \example Passing null for a pointer that must not be null.
/// Example: Passing null for a pointer that must not be null.
IkarusErrorInfo_Type_Client_Input = 0x0002000100000002,
/// \brief An error occurred while interacting with a dependency from ikarus.
/// \example An error occurred in the underlying OS library.
/// Example: An error occurred in the underlying OS library.
IkarusErrorInfo_Type_SubSystem_Dependency = 0x0002000200000001,
/// \brief An error occurred while interacting with the database.
/// \example An error occurred while executing a query.
/// Example: An error occurred while executing a query.
IkarusErrorInfo_Type_SubSystem_Database = 0x0002000200000002,
/// \brief An error occurred while interacting with the filesystem.
/// \example An error occurred while reading a file.
/// Example: An error occurred while reading a file.
IkarusErrorInfo_Type_SubSystem_Filesystem = 0x0002000200000003,
/// \brief A datapoint within ikarus is invalid for the current state of the system.
/// \example The name of an object is found to be invalid UTF8.
/// Example: The name of an object is found to be invalid UTF8.
IkarusErrorInfo_Type_LibIkarus_InvalidState = 0x0002000300000001,
/// \brief LibIkarus is unable to perform a certain operation that should succeed.
/// \example Migrating a project fails
/// Example: Migrating a project fails
IkarusErrorInfo_Type_LibIkarus_CannotPerformOperation = 0x0002000300000002,
/// \brief LibIkarus is unable to perform a certain operation within a given timeframe.
/// \example A query takes longer than the timeout.
/// Example: A query takes longer than the timeout.
IkarusErrorInfo_Type_LibIkarus_Timeout = 0x0002000300000003,
/// \brief The type of error is unknown.
IkarusErrorInfo_Type_Unknown = 0xFFFFFFFF,

View file

@ -24,21 +24,21 @@ IKA_API IkarusNumberValue * ikarus_number_value_create(long double value);
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusNumberValue * ikarus_number_value_create_indeterminate();
/// \brief Fetches the underlying value of a number value.
/// \param value The number value.
/// \return The underlying value.
/// \warning Undefined if the value is indeterminate.
IKA_API long double ikarus_number_value_get(IkarusNumberValue const * value);
/// \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);
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * number_value);
IKARUS_END_HEADER

View file

@ -24,21 +24,22 @@ IKA_API IkarusTextValue * ikarus_text_value_create(char const * value);
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusTextValue * ikarus_text_value_create_indeterminate();
/// \brief Fetches the underlying value of a text value.
/// \param value The text value.
/// \return The underlying value.
/// \warning Undefined if the value is indeterminate.
/// \remark The value is owned by libikarus and must not be freed.
IKA_API char const * ikarus_text_value_get_underlying(IkarusTextValue const * value);
/// \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);
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * text_value);
IKARUS_END_HEADER

View file

@ -24,21 +24,21 @@ IKA_API IkarusToggleValue * ikarus_toggle_value_create(bool value);
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusToggleValue * ikarus_toggle_value_create_indeterminate();
/// \brief Fetches the underlying value of a toggle value.
/// \param value The toggle value.
/// \return The underlying value.
/// \warning Undefined if the value is indeterminate.
IKA_API bool ikarus_toggle_value_get(IkarusToggleValue const * value);
/// \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);
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * toggle_value);
IKARUS_END_HEADER

View file

@ -4,7 +4,6 @@
/// \author Folling <folling@ikarus.world>
#include <ikarus/macros.h>
#include <ikarus/stdtypes.h>
/// \defgroup entity_value Entity Values
/// \brief The values stored in entities.
@ -25,15 +24,22 @@ struct IkarusValue;
/// \return True if the value is indeterminate, false otherwise.
IKA_API bool ikarus_value_is_indeterminate(IkarusValue 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.
/// \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.