move sub-functions of value impls to concrete types

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2023-12-03 18:44:09 +01:00 committed by Folling
parent 2f5159beac
commit a934564afc
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
14 changed files with 339 additions and 119 deletions

View file

@ -14,31 +14,23 @@ IKARUS_BEGIN_HEADER
/// \brief A numeric value. For example "Age" or "Height".
struct IkarusNumberValue;
/// \brief Creates a number value from long doubles.
/// \param data The number data or null if you wish to create an empty value.
/// \details LibIkarus does not take ownership of this array.
/// \param data_size The size of the data array.
/// \brief Creates a number value.
/// \return The value or null if an error occurs.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusNumberValue * ikarus_number_value_create(long double * data, size_t data_size);
/// \brief Creates an indeterminate number value.
/// \return The value.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusNumberValue * ikarus_number_value_create_indeterminate();
IKA_API IkarusNumberValue * ikarus_number_value_create();
/// \brief Fetches the underlying data of a number value at a specific index.
/// \param value The number value.
/// \pre \li Must not be null.
/// \param idx The index of the data to fetch.
/// \pre \li Must be less than the size of the value.
/// \return The underlying data or null if an error occurs or the value is indeterminate.
/// \return The underlying data or null if an error occurs or the value is undefined.
IKA_API long double const * ikarus_number_value_get(IkarusNumberValue * value, size_t idx);
/// \brief Fetches the size of the underlying data of a number value.
/// \param value The number value.
/// \pre \li Must not be null.
/// \return The size of the underlying data or 0 if an error occurs or the value is indeterminate.
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
IKA_API size_t ikarus_number_value_get_size(IkarusNumberValue const * value);
/// \brief Sets the data of a number value at a specific index.
@ -47,14 +39,13 @@ IKA_API size_t ikarus_number_value_get_size(IkarusNumberValue const * value);
/// \param idx The index of the data to set.
/// \pre \li Must be less than the size of the value.
/// \param new_data The new data.
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, size_t idx, long double new_data);
IKA_API void ikarus_number_value_set(IkarusNumberValue * value, size_t idx, long double const * new_data);
/// \brief Removes a data from a number value.
/// \param value The number value.
/// \pre \li Must not be null.
/// \param idx The index of the data to remove.
/// \pre \li Must be less than the size of the value.
/// \remark This will shift all data after the index by one to the left.
IKA_API void ikarus_number_value_remove(IkarusNumberValue * value, size_t idx);
/// \brief Inserts a data into a number value.
@ -63,14 +54,61 @@ IKA_API void ikarus_number_value_remove(IkarusNumberValue * value, size_t idx);
/// \param idx The index of the data to insert.
/// \pre \li Must be less than or equal to the size of the value.
/// \param new_data The new data.
/// \remark This will shift all data after the index by one to the right.
IKA_API void ikarus_number_insert(IkarusNumberValue * value, size_t idx, long double new_data);
IKA_API void ikarus_number_value_insert(IkarusNumberValue * value, size_t idx, long double const * new_data);
/// \brief Clears a number value.
/// \param value The number value.
/// \remark Noop if the value is undefined.
IKA_API void ikarus_number_value_clear(IkarusNumberValue * value);
/// \brief Checks if a number value is undefined.
/// \param value The number value.
/// \pre \li Must not be null.
/// \return True if the value is undefined, false otherwise.
IKA_API bool ikarus_number_value_is_undefined(IkarusNumberValue const * value);
/// \brief Changes a number value's undefined state.
/// \param value The number value.
/// \pre \li Must not be null.
/// \param undefined The new undefined state.
/// \remark Noop if the value is already undefined.
/// \remark If the value is set to undefined, all data will be cleared.
/// \remark If the value is set to not undefined, the value is as if newly created.
IKA_API void ikarus_number_value_set_undefined(IkarusNumberValue * value, bool undefined);
/// \brief Converts a number value to a string.
/// \param value The number value to convert.
/// \pre \li Must not be null.
/// \return The converted string.
/// \remark Must be freed with #ikarus_free.
/// \remark Undefined if the value is undefined.
IKA_API char const * ikarus_number_value_to_string(IkarusNumberValue const * value);
/// \brief Checks if two values are equal.
/// \param lhs The left hand side value.
/// \pre \li Must not be null.
/// \param rhs The right hand side value.
/// \pre \li Must not be null.
/// \return True if the values' data are equal, false otherwise.
IKA_API bool ikarus_number_value_is_equal(IkarusNumberValue const * lhs, IkarusNumberValue const * rhs);
/// \brief Creates a copy of a number value.
/// \param value The value to copy.
/// \pre \li Must not be null.
/// \return The copied value.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusNumberValue * ikarus_number_value_copy(IkarusNumberValue const * value);
/// \brief Converts a number value to an entity value.
/// \param value The number value to convert.
/// \pre \li Must not be null.
/// \return The converted entity value.
/// \remark This is the same pointer, so freeing it implies freeing the original value.
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * value);
/// \see ikarus_toggle_value_to_value
IKA_API struct IkarusValue const * ikarus_number_value_to_value_const(IkarusNumberValue const * value);
IKARUS_END_HEADER
/// @}

View file

@ -11,29 +11,27 @@
IKARUS_BEGIN_HEADER
/// \brief A textual value. For example "Surname" or "Description".
/// \brief A textual value. For example "Surname" or "Description"
struct IkarusTextValue;
/// \brief Creates a text value from strings.
/// \param data The text data or null if you wish to create an empty value.
/// \details LibIkarus does not take ownership of this array.
/// \param data_size The size of the data array.
/// \brief Creates a text value.
/// \return The value or null if an error occurs.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusTextValue * ikarus_text_value_create(char const ** data, size_t data_size);
IKA_API IkarusTextValue * ikarus_text_value_create();
/// \brief Creates an indeterminate text value.
/// \return The value.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusTextValue * ikarus_text_value_create_indeterminate();
/// \see ikarus_number_value_get
IKA_API char const * const * ikarus_text_value_get(IkarusTextValue const * value, size_t idx);
/// \brief Fetches the underlying data of a number value at a specific index.
/// \param value The number value.
/// \pre \li Must not be null.
/// \param idx The index of the data to fetch.
/// \pre \li Must be less than the size of the value.
/// \return The underlying data or null if an error occurs or the value is undefined.
/// \remark This value is owned by LibIkarus and must not be freed.
IKA_API char const * ikarus_text_value_get(IkarusTextValue * value, size_t idx);
/// \brief Fetches the size of the underlying data of a text value.
/// \param value The text value.
/// \pre \li Must not be null.
/// \return The size of the underlying data or 0 if an error occurs or the value is indeterminate.
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
IKA_API size_t ikarus_text_value_get_size(IkarusTextValue const * value);
/// \brief Sets the data of a text value at a specific index.
@ -41,7 +39,7 @@ IKA_API size_t ikarus_text_value_get_size(IkarusTextValue const * value);
/// \pre \li Must not be null.
/// \param idx The index of the data to set.
/// \pre \li Must be less than the size of the value.
/// \param new_data The new data.
/// \param new_data The new data. LibIkarus assumes ownership of this pointer.
IKA_API void ikarus_text_value_set(IkarusTextValue * value, size_t idx, char const * new_data);
/// \brief Removes a data from a text value.
@ -49,7 +47,6 @@ IKA_API void ikarus_text_value_set(IkarusTextValue * value, size_t idx, char con
/// \pre \li Must not be null.
/// \param idx The index of the data to remove.
/// \pre \li Must be less than the size of the value.
/// \remark This will shift all data after the index by one to the left.
IKA_API void ikarus_text_value_remove(IkarusTextValue * value, size_t idx);
/// \brief Inserts a data into a text value.
@ -58,14 +55,61 @@ IKA_API void ikarus_text_value_remove(IkarusTextValue * value, size_t idx);
/// \param idx The index of the data to insert.
/// \pre \li Must be less than or equal to the size of the value.
/// \param new_data The new data.
/// \remark This will shift all data after the index by one to the right.
IKA_API void ikarus_text_insert(IkarusTextValue * value, size_t idx, char const * new_data);
IKA_API void ikarus_text_value_insert(IkarusTextValue * value, size_t idx, char const * new_data);
/// \brief Clears a text value.
/// \param value The text value.
/// \remark Noop if the value is undefined.
IKA_API void ikarus_text_value_clear(IkarusTextValue * value);
/// \brief Checks if a text value is undefined.
/// \param value The text value.
/// \pre \li Must not be null.
/// \return True if the value is undefined, false otherwise.
IKA_API bool ikarus_text_value_is_undefined(IkarusTextValue const * value);
/// \brief Changes a text value's undefined state.
/// \param value The text value.
/// \pre \li Must not be null.
/// \param undefined The new undefined state.
/// \remark Noop if the value is already undefined.
/// \remark If the value is set to undefined, all data will be cleared.
/// \remark If the value is set to not undefined, the value is as if newly created.
IKA_API void ikarus_text_value_set_undefined(IkarusTextValue * value, bool undefined);
/// \brief Converts a text value to a string.
/// \param value The text value to convert.
/// \pre \li Must not be null.
/// \return The converted string.
/// \remark Must be freed with #ikarus_free.
/// \remark Undefined if the value is undefined.
IKA_API char const * ikarus_text_value_to_string(IkarusTextValue const * value);
/// \brief Checks if two values are equal.
/// \param lhs The left hand side value.
/// \pre \li Must not be null.
/// \param rhs The right hand side value.
/// \pre \li Must not be null.
/// \return True if the values' data are equal, false otherwise.
IKA_API bool ikarus_text_value_is_equal(IkarusTextValue const * lhs, IkarusTextValue const * rhs);
/// \brief Creates a copy of a text value.
/// \param value The value to copy.
/// \pre \li Must not be null.
/// \return The copied value.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusTextValue * ikarus_text_value_copy(IkarusTextValue const * value);
/// \brief Converts a text value to an entity value.
/// \param value The text value to convert.
/// \pre \li Must not be null.
/// \return The converted entity value.
/// \remark This is the same pointer, so freeing it implies freeing the original value.
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * value);
/// \see ikarus_toggle_value_to_value
IKA_API struct IkarusValue const * ikarus_text_value_to_value_const(IkarusTextValue const * value);
IKARUS_END_HEADER
/// @}

View file

@ -14,7 +14,7 @@ IKARUS_BEGIN_HEADER
/// \brief A true/false boolean-esque value. For example "Is Dead".
struct IkarusToggleValue;
/// \brief Creates a toggle value from booleans.
/// \brief Creates a toggle.
/// \return The value or null if an error occurs.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusToggleValue * ikarus_toggle_value_create();
@ -24,13 +24,13 @@ IKA_API IkarusToggleValue * ikarus_toggle_value_create();
/// \pre \li Must not be null.
/// \param idx The index of the data to fetch.
/// \pre \li Must be less than the size of the value.
/// \return The underlying data or null if an error occurs or the value is indeterminate.
/// \return The underlying data or null if an error occurs or the value is undefined.
IKA_API bool const * ikarus_toggle_value_get(IkarusToggleValue * value, size_t idx);
/// \brief Fetches the size of the underlying data of a toggle value.
/// \param value The toggle value.
/// \pre \li Must not be null.
/// \return The size of the underlying data or 0 if an error occurs or the value is indeterminate.
/// \return The size of the underlying data or 0 if an error occurs or the value is undefined.
IKA_API size_t ikarus_toggle_value_get_size(IkarusToggleValue const * value);
/// \brief Sets the data of a toggle value at a specific index.
@ -58,14 +58,57 @@ IKA_API void ikarus_toggle_value_insert(IkarusToggleValue * value, size_t idx, b
/// \brief Clears a toggle value.
/// \param value The toggle value.
/// \remark Noop if the value is indeterminate.
/// \remark Noop if the value is undefined.
IKA_API void ikarus_toggle_value_clear(IkarusToggleValue * value);
/// \brief Checks if a toggle value is undefined.
/// \param value The toggle value.
/// \pre \li Must not be null.
/// \return True if the value is undefined, false otherwise.
IKA_API bool ikarus_toggle_value_is_undefined(IkarusToggleValue const * value);
/// \brief Changes a toggle value's undefined state.
/// \param value The toggle value.
/// \pre \li Must not be null.
/// \param undefined The new undefined state.
/// \remark Noop if the value is already undefined.
/// \remark If the value is set to undefined, all data will be cleared.
/// \remark If the value is set to not undefined, the value is as if newly created.
IKA_API void ikarus_toggle_value_set_undefined(IkarusToggleValue * value, bool undefined);
/// \brief Converts a toggle value to a string.
/// \param value The toggle value to convert.
/// \pre \li Must not be null.
/// \return The converted string.
/// \remark Must be freed with #ikarus_free.
/// \remark Undefined if the value is undefined.
IKA_API char const * ikarus_toggle_value_to_string(IkarusToggleValue const * value);
/// \brief Checks if two values are equal.
/// \param lhs The left hand side value.
/// \pre \li Must not be null.
/// \param rhs The right hand side value.
/// \pre \li Must not be null.
/// \return True if the values' data are equal, false otherwise.
IKA_API bool ikarus_toggle_value_is_equal(IkarusToggleValue const * lhs, IkarusToggleValue const * rhs);
/// \brief Creates a copy of a toggle value.
/// \param value The value to copy.
/// \pre \li Must not be null.
/// \return The copied value.
/// \remark Must be freed with #ikarus_free.
IKA_API IkarusToggleValue * ikarus_toggle_value_copy(IkarusToggleValue const * value);
/// \brief Converts a toggle value to an entity value.
/// \param value The toggle value to convert.
/// \pre \li Must not be null.
/// \return The converted entity value.
/// \remark This is the same pointer, so freeing it implies freeing the original value.
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * value);
/// \see ikarus_toggle_value_to_value
IKA_API struct IkarusValue const * ikarus_toggle_value_to_value_const(IkarusToggleValue const * value);
IKARUS_END_HEADER
/// @}

View file

@ -9,7 +9,7 @@
/// \brief The values of properties.
/// \details Each entity has a value for each property it is associated with.
/// These value classes represent plain objects. They are not associated with any entity.
/// Each value may be indeterminate. \see IkarusProperty
/// Each value may be undefined. \see IkarusProperty
/// Values are stored as lists. If a property is "singular" then its value is a list of size 1.
/// Values are typed, with types existing for each of the corresponding property types.
/// When setting values for a property the type must match the property type and the value must be valid under the property's
@ -21,25 +21,6 @@ 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.