libikarus/include/ikarus/objects/object.h
folling bf2c971669
add object_get/set_name/information
Signed-off-by: Folling <mail@folling.io>
2025-04-15 12:10:51 +02:00

106 lines
4.1 KiB
C

#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 Fetches the project of an object.
/// \param object The object to fetch the project from.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The project of the object or null if an error occurs.
IKA_API struct IkarusProject * ikarus_object_get_project(IkarusObject const * object, IkarusErrorData * error_out);
/// \brief Fetches the name of an object.
/// \param object The object to fetch the name from.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The name of the object or null if an error occurs.
IKA_API char const * ikarus_object_get_name(IkarusObject const * object, IkarusErrorData * error_out);
/// \brief Sets the name of an object.
/// \param object The object to set the name of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_name The new name of the object.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param error_out \see errors.h
IKA_API void ikarus_object_set_name(IkarusObject const * object, char const * new_name, IkarusErrorData * error_out);
/// \brief Fetches the information of an object.
/// \param object The object to fetch the information from.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The information of the object or null if an error occurs.
IKA_API char const * ikarus_object_get_info(IkarusObject const * object, IkarusErrorData * error_out);
/// \brief Sets the information of an object.
/// \param object The object to set the information of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_info The new information of the object.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
IKA_API void ikarus_object_set_info(IkarusObject const * object, char const * new_info, IkarusErrorData * error_out);
/// \brief Compares two objects for equality.
/// \details This neither compares the pointers nor does a deep copy. Instead it figures out if the objects _are_ the
/// same object.
/// \param lhs The left hand side object.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param rhs The right hand side object.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return True if the objects are equal, false otherwise.
IKA_API bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const * rhs, IkarusErrorData * error_out);
/// \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 *, void *),
void (*property_visitor)(struct IkarusProperty *, void *),
void (*entity_visitor)(struct IkarusEntity *, 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 *, void *),
void (*property_visitor)(struct IkarusProperty const *, void *),
void (*entity_visitor)(struct IkarusEntity const *, void *),
void * data,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}