libikarus/include/ikarus/objects/properties/property.h
folling 4d7bf09c4e
add flatbuffers support and initial rewrite
Signed-off-by: Folling <mail@folling.io>
2025-04-15 12:11:25 +02:00

144 lines
6 KiB
C

#pragma once
/// \file property.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/macros.h>
#include <ikarus/stdtypes.h>
#include <ikarus/values/value_cardinality.h>
#include <ikarus/values/value_type.h>
/// \defgroup properties Properties
/// \brief Properties define the structure and types of data.
/// @{
IKARUS_BEGIN_HEADER
/// \brief Properties define the structure of blueprints.
/// \details Each blueprint can have any number of properties.
/// Every property has a type that identifies the kind of data that can be put in.
/// This is the "base class" of properties. See the derived types (e.g. IkarusToggleProperty) for more information.
///
/// The following types currently exist:
/// - Toggle: A true/false boolean-like value
/// - Number: An arbitrary numeric value
/// - Text: An arbitrary textual value
///
/// Property Examples:
/// - Is Dead (Toggle)
/// - Age (Number)
/// - ISBN (Text)
///
/// Each entity associated with the property has a value for it.
///
/// \remark Values for properties are lazily created to save space.
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
struct IkarusProperty;
/// \brief Deletes a property.
/// \param property The property to delete.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \remark The property must not be accessed after deletion.
IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData * error_out);
/// \brief Gets the ID of a property.
/// \param property The property to get the ID of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The ID of the property or 0 if an error occurs.
IKA_API int64_t ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the project of a property.
/// \param property The property to get the project of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The project of the property or null if an error occurs.
IKA_API struct IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the name of an property.
/// \param entity The property to get the name of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The name of the property or null if an error occurs.
IKA_API char const * ikarus_property_get_name(IkarusProperty const * entity, IkarusErrorData * error_out);
/// \brief Sets the name of an property.
/// \param entity The property to set the name of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The new name of the property.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
IKA_API void ikarus_property_set_name(IkarusProperty * entity, char const * name, IkarusErrorData * error_out);
/// \brief Gets the type info of a property.
/// \param property The property to get the type info of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The type info of the property or null if an error occurs.
/// \remark Changing the type of a property is not supported. This is because the property would need to change
IKA_API IkarusValueType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
// there is no `set_type` as we encode type information in the underlying datatype
/// \briefs Gets a property's cardinality.
/// \param property The property to get the cardinality of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The cardinality of the property or false if an error occurs.
IKA_API IkarusValueCardinality ikarus_property_get_cardinality(IkarusProperty const * property, IkarusErrorData * error_out);
/// \briefs Sets a property's default value.
/// \param property The property to set the cardinality of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \\param cardinality The new cardinality of the property.
/// \param error_out \see errors.h
IKA_API void
ikarus_property_set_cardinality(IkarusProperty * property, IkarusValueCardinality cardinality, IkarusErrorData * error_out);
/// \briefs Gets a property's default value.
/// \param property The property to get the default value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value of the property or null if an error occurs.
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the source blueprint of a property.
/// \param property The property to get the source of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The source of the property or null if an error occurs.
IKA_API struct IkarusBlueprint * ikarus_property_get_blueprint(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Visits a property. Calling the appropriate function for the property's type.
/// \param property The property to visit.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param toggle_property_visitor The function to call if the property is a toggle property. Skipped if null.
/// \param number_property_visitor The function to call if the property is a number property. Skipped if null.
/// \param text_property_visitor The function to call if the property is a text property. Skipped if null.
/// \param data The data to pass to the functions.
/// \param error_out \see errors.h
IKA_API void ikarus_property_visit(
IkarusProperty * property,
void (*toggle_property_visitor)(struct IkarusToggleProperty *, void *),
void (*number_property_visitor)(struct IkarusNumberProperty *, void *),
void (*text_property_visitor)(struct IkarusTextProperty *, void *),
void * data,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
// @}