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,7 +4,6 @@
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/id.h>
#include <ikarus/macros.h>
#include <ikarus/stdtypes.h>
@ -14,9 +13,10 @@
IKARUS_BEGIN_HEADER
/// \brief A blueprint object.
/// \details A blueprint is a collection of properties which can be linked to entities.
/// Each entity the blueprint is linked to will have values for the blueprints properties.q
/// \brief Blueprints are templates for managing common properties of entities.
/// \details A blueprint is a collection of properties which can be linked to entities.
/// Each entity the blueprint is linked to will have values for the blueprints
/// properties. Changes in blueprints will be reflected in all linked entities.
struct IkarusBlueprint;
/// \brief Creates a blueprint.
@ -25,19 +25,24 @@ struct IkarusBlueprint;
/// \pre \li Must exist.
/// \param name The name of the blueprint.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \pre \li Must be unique among all blueprints in the project.
/// \param error_out \see errors.h
/// \return The created blueprint or null if an error occurs.
IKA_API IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
IKA_API IkarusBlueprint * ikarus_blueprint_create(
struct IkarusProject * project,
char const * name,
IkarusErrorData * error_out
);
/// \brief Deletes & frees a blueprint.
/// \brief Deletes a blueprint.
/// \param blueprint The blueprint to delete.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \remark The blueprint must not be accessed after deletion.
IKA_API void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * error_out);
IKA_API void ikarus_blueprint_delete(
IkarusBlueprint * blueprint,
IkarusErrorData * error_out
);
/// \brief Gets the ID of a blueprint.
/// \param blueprint The blueprint to get the ID of.
@ -45,23 +50,32 @@ IKA_API void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorDat
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The ID of the blueprint or 0 if an error occurs.
IKA_API IkarusId ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
IKA_API int64_t ikarus_blueprint_get_id(
IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
/// \brief Gets the project a blueprint is part of.
/// \param blueprint The blueprint to get the project of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The project the blueprint is part of or null if an error occurs.
IKA_API IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
/// \return The project or null if an error occurs.
IKA_API IkarusProject * ikarus_blueprint_get_project(
IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
/// \brief Gets the name of a blueprint.
/// \param blueprint The blueprint 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 blueprint or null if an error occurs.
IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
/// \return The name or null if an error occurs.
IKA_API char const * ikarus_blueprint_get_name(
IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
/// \brief Sets the name of a blueprint.
/// \param blueprint The blueprint to set the name of.
@ -69,10 +83,12 @@ IKA_API char const * ikarus_blueprint_get_name(IkarusBlueprint const * blueprint
/// \pre \li Must exist.
/// \param name The new name of the blueprint.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \pre \li Must be unique among all blueprints in the project.
/// \param error_out \see errors.h
IKA_API void ikarus_blueprint_set_name(IkarusBlueprint * blueprint, char const * name, IkarusErrorData * error_out);
IKA_API void ikarus_blueprint_set_name(
IkarusBlueprint * blueprint,
char const * name,
IkarusErrorData * error_out
);
/// \brief Gets the properties of a blueprint.
/// \param blueprint The blueprint to get the properties of.
@ -96,7 +112,10 @@ IKA_API void ikarus_blueprint_get_properties(
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The number of properties or undefined if an error occurs.
IKA_API size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
IKA_API size_t ikarus_blueprint_get_property_count(
IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
/// \brief Gets the entities linked to a blueprint.
/// \param blueprint The blueprint to get the linked entities of.
@ -120,7 +139,10 @@ IKA_API void ikarus_blueprint_get_linked_entities(
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The number of linked entities or undefined if an error occurs.
IKA_API size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
IKA_API size_t ikarus_blueprint_get_linked_entity_count(
IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
IKARUS_END_HEADER

View file

@ -1,7 +1,6 @@
#pragma once
#include <ikarus/errors.h>
#include <ikarus/id.h>
#include <ikarus/macros.h>
#include <ikarus/stdtypes.h>
@ -14,25 +13,20 @@
IKARUS_BEGIN_HEADER
/// \brief Entities are the core building blocks of Ikarus.
/// \detials Blueprints and Properties define the structure of the data.
/// Entities define the data itself.
/// \details Entities store two data: A name and a set of values.
/// The name identifies the entity but does not have to be unique. The values
/// are the actual information of the entity.
///
/// Properties can be associated with Entities in two ways:
/// - Directly: The property is linked to the entity.
/// - Indirectly: The property is linked to a blueprint the entity is linked to.
/// For documentation on the types and layout of values \see Values.h.
///
/// For each property an entity is linked to, it has a value. These values depend on the property's type.
/// For more information on the types see the property documentation.
/// Entities can be linked to blueprints.
/// The entity has a (possibly uninitialized) value for each property of all
/// blueprints it is linked to. \see Property.h \see Blueprint.h.
///
/// Values are the core type of data within Ikarus.
/// Each value is associated with one page and one property.
///
/// \remark Values are typed, the type of a value is specified by its associated property.
/// For more information on the types see the property documentation.
///
/// \remark Values are guaranteed to be in valid format for a given type
/// but not guaranteed to be valid under the settings of the property.
/// This is because changing the settings can invalidate existing values without resetting them.
/// We distinguish between `EntityValues` and `EntityPropertyValues`.
/// `EntityValues` are a direct part of the entity.
/// `EntityPropertyValues` are an indirect part of the entity, linked to them
/// via a blueprint.
struct IkarusEntity;
/// \brief Creates an entity.
@ -41,11 +35,13 @@ struct IkarusEntity;
/// \pre \li Must exist.
/// \param name The name of the entity.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \pre \li Must be unique among all entities in the project.
/// \param error_out \see errors.h
/// \return The created entity or null if an error occurs.
IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name, IkarusErrorData * error_out);
IKA_API IkarusEntity * ikarus_entity_create(
struct IkarusProject * project,
char const * name,
IkarusErrorData * error_out
);
/// \brief Deletes an entity.
/// \param entity The entity to delete.
@ -53,15 +49,17 @@ IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \remark The entity must not be accessed after deletion.
IKA_API void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out);
IKA_API void
ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out);
/// \brief Gets the ID of an entity.
/// \param entity The entity to get the ID of.
/// \brief Gets the id of an entity.
/// \param entity The entity 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 entity or 0 if an error occurs.
IKA_API IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out);
/// \return The id of the entity or 0 if an error occurs.
IKA_API int64_t
ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out);
/// \brief Gets the project an entity is part of.
/// \param entity The entity to get the project of.
@ -69,7 +67,10 @@ IKA_API IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorDa
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The project the entity is part of or null if an error occurs.
IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out);
IKA_API IkarusProject * ikarus_entity_get_project(
IkarusEntity const * entity,
IkarusErrorData * error_out
);
/// \brief Gets the name of an entity.
/// \param entity The entity to get the name of.
@ -77,7 +78,10 @@ IKA_API IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, I
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The name of the entity or null if an error occurs.
IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusErrorData * error_out);
IKA_API char const * ikarus_entity_get_name(
IkarusEntity const * entity,
IkarusErrorData * error_out
);
/// \brief Sets the name of an entity.
/// \param entity The entity to set the name of.
@ -85,10 +89,12 @@ IKA_API char const * ikarus_entity_get_name(IkarusEntity const * entity, IkarusE
/// \pre \li Must exist.
/// \param name The new name of the entity.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \pre \li Must be unique among all entities in the project.
/// \param error_out \see errors.h
IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, IkarusErrorData * error_out);
IKA_API void ikarus_entity_set_name(
IkarusEntity * entity,
char const * name,
IkarusErrorData * error_out
);
/// \brief Checks if an entity is linked to a blueprint.
/// \param entity The entity to check.
@ -99,8 +105,11 @@ IKA_API void ikarus_entity_set_name(IkarusEntity * entity, char const * name, Ik
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return True if the entity is linked to the blueprint, false otherwise.
IKA_API bool
ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusBlueprint const * blueprint, IkarusErrorData * error_out);
IKA_API bool ikarus_entity_is_linked_to_blueprint(
IkarusEntity const * entity,
struct IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
);
/// \brief Links an entity to a blueprint.
/// \param entity The entity to link.
@ -111,10 +120,14 @@ ikarus_entity_is_linked_to_blueprint(IkarusEntity const * entity, struct IkarusB
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \remark No-op if the entity is already linked to the blueprint.
IKA_API void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
IKA_API void ikarus_entity_link_to_blueprint(
IkarusEntity * entity,
struct IkarusBlueprint * blueprint,
IkarusErrorData * error_out
);
/// \brief Unlinks an entity from a blueprint. All values of the properties of the blueprint the entity is linked with
/// will be deleted.
/// \brief Unlinks an entity from a blueprint.
/// All values of the blueprints' properties will be deleted.
/// \param entity The entity to unlink.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -123,9 +136,13 @@ IKA_API void ikarus_entity_link_to_blueprint(IkarusEntity * entity, struct Ikaru
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \remark No-op if the entity is not linked to the blueprint.
IKA_API void ikarus_entity_unlink_from_blueprint(IkarusEntity * entity, struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
IKA_API void ikarus_entity_unlink_from_blueprint(
IkarusEntity * entity,
struct IkarusBlueprint * blueprint,
IkarusErrorData * error_out
);
/// \brief Gets the blueprints an entity is linked to.
/// \brief Gets all blueprints an entity is linked to.
/// \param entity The entity to get the blueprints of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -142,14 +159,80 @@ IKA_API void ikarus_entity_get_linked_blueprints(
);
/// \brief Gets the number of blueprints an entity is linked to.
/// \param entity The entity to get the number of blueprints of.
/// \param entity The entity to get the number of linked blueprints of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The number of blueprints or undefined if an error occurs.
IKA_API size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * entity, IkarusErrorData * error_out);
IKA_API size_t ikarus_entity_get_linked_blueprint_count(
IkarusEntity const * entity,
IkarusErrorData * error_out
);
/// \brief Checks if an entity has a specific property.
/// \brief Checks if an entity has a value with a given name.
/// \param entity The entity to check.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The name of the value to check.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
/// \return False if the entity does not have a value associated with
/// the name or if an error occurs, true otherwise.
IKA_API bool ikarus_entity_has_value(
IkarusEntity const * entity,
char const * name,
IkarusErrorData * error_out
);
/// \brief Gets the value of an entity.
/// \param entity The entity to get the value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The name of the value to get.
/// \pre \li Must not be null.
/// \pre \li Must be an existing value of the entity.
/// \param error_out \see errors.h
/// \return The value of the entity or null if an error occurs.
IKA_API struct IkarusValue * ikarus_entity_get_value(
IkarusEntity const * entity,
char const * name,
IkarusErrorData * error_out
);
/// \brief Sets the value of an entity.
/// If the entity does not have a value associated with the name, it is created.
/// \remark Types are overwritten if the value already exists.
/// \param entity The entity to set the value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The name of the value to set.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param value The new value of the entity.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
IKA_API void ikarus_entity_set_value(
IkarusEntity * entity,
char const * name,
struct IkarusValue const * value,
IkarusErrorData * error_out
);
/// \brief Removes a value from an entity.
/// \pre \li The value must exist.
/// \param entity The entity to delete the value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The name of the value to delete.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
IKA_API void ikarus_entity_remove_value(
IkarusEntity * entity,
char const * name,
IkarusErrorData * error_out
);
/// \brief Checks if a property is linked to an entity.
/// \param entity The entity to check.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -157,14 +240,19 @@ IKA_API size_t ikarus_entity_get_linked_blueprint_count(IkarusEntity const * ent
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return False if an error occurs or the entity does not have the property, true otherwise.
IKA_API bool ikarus_entity_has_property(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
/// \return False if an error occurs or the entity does not have the property,
/// true otherwise.
IKA_API bool ikarus_entity_has_property(
IkarusEntity const * entity,
struct IkarusProperty const * property,
IkarusErrorData * error_out
);
/// \brief Gets the properties of an entity.
/// \param entity The entity to get the properties of.
/// \brief Gets the properties an entity is linked to.
/// \param entity The entity to get the linked properties of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param properties_out The buffer to write the properties to.
/// \param properties_out The buffer to write the linked properties to.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
/// \param properties_out_size The size of the buffer.
@ -176,30 +264,37 @@ IKA_API void ikarus_entity_get_properties(
IkarusErrorData * error_out
);
/// \brief Gets the number of properties of an entity.
/// \param entity The entity to get the number of properties of.
/// \brief Gets the number of properties an entity is linked to.
/// \param entity The entity to get the number of linked properties of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The number of properties or undefined if an error occurs.
IKA_API size_t ikarus_entity_get_property_count(IkarusEntity const * entity, IkarusErrorData * error_out);
IKA_API size_t ikarus_entity_get_property_count(
IkarusEntity const * entity,
IkarusErrorData * error_out
);
/// \brief Gets the value of a property of an entity.
/// \details If the entity has never set the value of the property, the default value is returned (which may be undefined).
/// \details If the entity has never set the value of the property,
/// the property's default value is returned.
/// \param entity The entity to get the value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param property The property to get the value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \pre \li Must be linked to the entity.
/// \param error_out \see errors.h
/// \return The value of the property or null if the entity does not have the property or an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusEntityPropertyValue *
ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const * property, IkarusErrorData * error_out);
/// \return The value of the property or null if an error occurs.
IKA_API struct IkarusValue * ikarus_entity_get_property_value(
IkarusEntity const * entity,
struct IkarusProperty const * property,
IkarusErrorData * error_out
);
/// \brief Sets the value of a property of an entity.
/// \param entity The entity to set the value of.
/// \param entity The entity to set the property value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param property The property to set the value of.
@ -211,7 +306,7 @@ ikarus_entity_get_value(IkarusEntity const * entity, struct IkarusProperty const
/// \pre \li Must be valid for the property's settings.
/// \param error_out \see errors.h
/// \remark If the entity does not have the property, this function fails.
IKA_API void ikarus_entity_set_value(
IKA_API void ikarus_entity_set_property_value(
IkarusEntity * entity,
struct IkarusProperty const * property,
struct IkarusValue const * value,

View file

@ -1,50 +0,0 @@
#pragma once
/// \file object.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/macros.h>
/// \defgroup object Objects
/// \brief Objects are a compound type of all types of objects in the database.
/// \details The following objects currently exist:
/// - \ref blueprint.h "Blueprints"
/// - \ref property.h "Properties"
/// - \ref entity.h "Entities"
/// @{
IKARUS_BEGIN_HEADER
/// \brief A generic object. Wraps all types of objects, including folders.
struct IkarusObject;
/// \brief Visits an object. Calling the appropriate function for the object's type.
/// \param object The object to visit.
/// \param blueprint_visitor The function to call if the object is a blueprint. Skipped if null.
/// \param property_visitor The function to call if the object is a property. Skipped if null.
/// \param entity_visitor The function to call if the object is an entity. Skipped if null.
/// \param data The data passed to the visitor functions.
/// \param error_out \see errors.h
IKA_API void ikarus_object_visit(
IkarusObject * object,
void (*blueprint_visitor)(struct IkarusBlueprint *, IkarusErrorData * error_out, void *),
void (*property_visitor)(struct IkarusProperty *, IkarusErrorData * error_out, void *),
void (*entity_visitor)(struct IkarusEntity *, IkarusErrorData * error_out, void *),
void * data,
IkarusErrorData * error_out
);
/// \see ikarus_object_visit
IKA_API void ikarus_object_visit_const(
IkarusObject const * object,
void (*blueprint_visitor)(struct IkarusBlueprint const *, IkarusErrorData * error_out, void *),
void (*property_visitor)(struct IkarusProperty const *, IkarusErrorData * error_out, void *),
void (*entity_visitor)(struct IkarusEntity const *, IkarusErrorData * error_out, void *),
void * data,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}

View file

@ -1,34 +0,0 @@
#pragma once
/// \file object_type.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/macros.h>
/// \addtogroup objects Objects
/// @{
IKARUS_BEGIN_HEADER
/// \brief The type of an object.
enum IkarusObjectType {
/// \brief Not an object or no object.
IkarusObjectType_None = 0,
/// \brief An IkarusEntity.
IkarusObjectType_Entity = 0b00000001,
/// \brief An IkarusBlueprint.
IkarusObjectType_Blueprint = 0b00000010,
/// \brief An IkarusProperty.
IkarusObjectType_Property = 0b00000011,
};
/// \brief Converts an IkarusObjectType to a string.
/// \param type The type to convert.
/// \return The string representation of the type.
/// \remark The returned string must not be freed.
char const * ikarus_object_type_to_string(IkarusObjectType type);
IKARUS_END_HEADER
/// @}

View file

@ -20,7 +20,6 @@ struct IkarusNumberProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -36,31 +35,6 @@ IKA_API IkarusNumberProperty * ikarus_number_property_create(
IkarusErrorData * error_out
);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusNumberValue *
ikarus_number_property_get_default_value(struct IkarusNumberProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_number_property_set_default_value(
struct IkarusNumberProperty * property,
struct IkarusNumberValue * new_default_value,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}

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
// @}

View file

@ -1,62 +0,0 @@
#pragma once
/// \file property_source.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// @{
IKARUS_BEGIN_HEADER
struct IkarusPropertyScope;
/// \brief Creates an blueprint property source.
/// \param blueprint The blueprint to create the property source for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The created property source or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope *
ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
/// \brief Creates an entity property source.
/// \param entity The entity to create the property source for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The created property source or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope * ikarus_property_source_create_entity(struct IkarusEntity * entity, IkarusErrorData * error_out);
/// \brief Visits a property source, calling the appropriate callback.
/// \param property_source The property source to visit.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param blueprint_visitor The callback to call if the source is a blueprint, skipped if null.
/// \param entity_visitor The callback to call if the source is an entity, skipped if null.
/// \param user_data User data to pass to the callbacks.
/// \param error_out \see errors.h
IKA_API void ikarus_property_source_visit(
struct IkarusPropertyScope * property_source,
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
void (*entity_visitor)(struct IkarusEntity *, void *),
void * user_data,
IkarusErrorData * error_out
);
/// \see ikarus_property_source_visit
IKA_API void ikarus_property_source_visit_const(
struct IkarusPropertyScope const * property_source,
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
void (*entity_visitor)(struct IkarusEntity const *, void *),
void * user_data,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}

View file

@ -1,27 +0,0 @@
#pragma once
/// \file property_type.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// @{
IKARUS_BEGIN_HEADER
/// \brief The type of a property.
/// \details Designates the type of data stored by the property as well as which settings are
/// available.
enum IkarusPropertyType {
/// \brief A true/false boolean-esque value.
IkarusPropertyType_Toggle = 0x10000000,
/// \brief A numeric value, limited to IEEE 80 bit floating point numbers.
IkarusPropertyType_Number = 0x20000000,
/// \brief An arbitrary UTF-8 textual value.
IkarusPropertyType_Text = 0x30000000,
};
IKARUS_END_HEADER
/// @}

View file

@ -20,7 +20,6 @@ struct IkarusTextProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -32,31 +31,7 @@ IKA_API IkarusTextProperty * ikarus_text_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusTextValue* default_value,
IkarusErrorData * error_out
);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusTextValue * ikarus_text_property_get_default_value(struct IkarusTextProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_text_property_set_default_value(
struct IkarusTextProperty * property,
struct IkarusTextValue * new_default_value,
struct IkarusTextValue * default_value,
IkarusErrorData * error_out
);

View file

@ -7,11 +7,11 @@
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
/// @{
IKARUS_BEGIN_HEADER
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
struct IkarusToggleProperty;
/// \brief Creates a toggle property.
@ -20,44 +20,15 @@ struct IkarusToggleProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param default_value The default value for the property.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
/// \return The created property or null if an error occurs.
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusToggleValue * default_value,
IkarusErrorData * error_out
);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusToggleValue *
ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_toggle_property_set_default_value(
struct IkarusToggleProperty * property,
struct IkarusToggleValue * new_default_value,
IkarusErrorData * error_out
);