add flatbuffers support and initial rewrite

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2024-05-12 14:15:42 +02:00 committed by Folling
parent b5852698e3
commit 70820129ae
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
72 changed files with 3929 additions and 1403 deletions

View file

@ -4,10 +4,10 @@
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/id.h>
#include <ikarus/macros.h>
#include <ikarus/objects/properties/property_type.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.
@ -15,9 +15,10 @@
IKARUS_BEGIN_HEADER
/// \brief Properties are the placeholders of values for entities.
/// \details Each entity can have any number of properties.
/// \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
@ -29,32 +30,10 @@ IKARUS_BEGIN_HEADER
/// - Age (Number)
/// - ISBN (Text)
///
/// Every property has settings which can be used to customise the property further.
/// Two settings that are shared among all properties are the following:
/// - List
/// - May be undefined
///
/// Additionally, each property has a default value. If no default value is provided, a sensible default is chosen.
/// Setting a default value that isn't valid for the property is an error. Changing settings so that the current default
/// value becomes invalid is valid but unsets the custom default value.
///
/// The former transforms a property into a list. Instead of one number, you could then specify a series of numbers.
/// The latter allows you to specify an "unknown" value for a property.
/// It might not be known if a character is dead or not for example.
///
/// Each entity associated with the property has a value for it.
///
/// Properties can also be added to blueprints in which case they are available for all entities associated with the
/// blueprint.
///
/// We call properties within entities "Entity Properties" and properties within blueprints "Blueprint Properties".
///
///
/// \remark Properties are scoped to the blueprint or entity they are associated with.
/// \remark Values for properties are lazily created as space saving measure.
/// \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.
/// This default value is specified when the property is created and can be updated later.
/// \remark Properties' tree structures are scoped to the entity or blueprint they are associated with.
struct IkarusProperty;
/// \brief Deletes a property.
@ -71,7 +50,7 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The ID of the property or 0 if an error occurs.
IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
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.
@ -81,31 +60,66 @@ IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusE
/// \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.
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
/// \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);
/// \brief Gets the source of a property.
// 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.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the default value 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 default value of the property or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
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.
@ -125,28 +139,6 @@ IKA_API void ikarus_property_visit(
IkarusErrorData * error_out
);
/// \see ikarus_property_visit
IKA_API void ikarus_property_visit_const(
IkarusProperty const * property,
void (*toggle_property_visitor)(struct IkarusToggleProperty const *, void *),
void (*number_property_visitor)(struct IkarusNumberProperty const *, void *),
void (*text_property_visitor)(struct IkarusTextProperty const *, void *),
void * data,
IkarusErrorData * error_out
);
/// \brief Casts a property to an object.
/// \param property The property to cast.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The property represented as an object or null if an error occurs.
/// \remark This operation is guaranteed to be very fast and is intended to be used frequently.
IKA_API struct IkarusObject * ikarus_property_to_object(IkarusProperty * property, IkarusErrorData * error_out);
/// \see ikarus_property_to_object
IKA_API struct IkarusObject const * ikarus_property_to_object_const(IkarusProperty const * property, IkarusErrorData * error_out);
IKARUS_END_HEADER
// @}