From e0d1d8bb6fc056dd1cb12a1cda2d61ff58e56a9f Mon Sep 17 00:00:00 2001 From: Folling Date: Mon, 12 Feb 2024 12:06:22 +0100 Subject: [PATCH] expose id getters Signed-off-by: Folling --- include/ikarus/objects/blueprint.h | 9 +++++++++ include/ikarus/objects/entity.h | 9 +++++++++ include/ikarus/objects/properties/property.h | 17 +++++++++++++++++ src/ikarus/objects/blueprint.cpp | 4 ++++ src/ikarus/objects/entity.cpp | 4 ++++ src/ikarus/objects/properties/property.cpp | 4 ++++ src/ikarus/objects/util.hpp | 8 ++++++++ 7 files changed, 55 insertions(+) diff --git a/include/ikarus/objects/blueprint.h b/include/ikarus/objects/blueprint.h index adfacd4..ec2087f 100644 --- a/include/ikarus/objects/blueprint.h +++ b/include/ikarus/objects/blueprint.h @@ -4,6 +4,7 @@ /// \author Folling #include +#include #include #include @@ -38,6 +39,14 @@ IKA_API IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project /// \remark The blueprint must not be accessed after deletion. 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. +/// \pre \li Must not be null. +/// \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); + /// \brief Gets the project a blueprint is part of. /// \param blueprint The blueprint to get the project of. /// \pre \li Must not be null. diff --git a/include/ikarus/objects/entity.h b/include/ikarus/objects/entity.h index 53abc70..04d59b0 100644 --- a/include/ikarus/objects/entity.h +++ b/include/ikarus/objects/entity.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -54,6 +55,14 @@ IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char /// \remark The entity must not be accessed after deletion. 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. +/// \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); + /// \brief Gets the project an entity is part of. /// \param entity The entity to get the project of. /// \pre \li Must not be null. diff --git a/include/ikarus/objects/properties/property.h b/include/ikarus/objects/properties/property.h index 589854f..aa52b2c 100644 --- a/include/ikarus/objects/properties/property.h +++ b/include/ikarus/objects/properties/property.h @@ -4,6 +4,7 @@ /// \author Folling #include +#include #include #include #include @@ -64,6 +65,22 @@ struct IkarusProperty; /// \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 IkarusId 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 type info of a property. /// \param property The property to get the type info of. /// \pre \li Must not be null. diff --git a/src/ikarus/objects/blueprint.cpp b/src/ikarus/objects/blueprint.cpp index dde1193..aa5f35c 100644 --- a/src/ikarus/objects/blueprint.cpp +++ b/src/ikarus/objects/blueprint.cpp @@ -49,6 +49,10 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint, IkarusErrorData * erro blueprint->project->uncache(blueprint); } +IkarusId ikarus_blueprint_get_id(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) { + return ikarus::util::object_get_id(blueprint, error_out); +} + IkarusProject * ikarus_blueprint_get_project(IkarusBlueprint const * blueprint, IkarusErrorData * error_out) { return ikarus::util::object_get_project(blueprint, error_out); } diff --git a/src/ikarus/objects/entity.cpp b/src/ikarus/objects/entity.cpp index 9e791a7..d724259 100644 --- a/src/ikarus/objects/entity.cpp +++ b/src/ikarus/objects/entity.cpp @@ -45,6 +45,10 @@ void ikarus_entity_delete(IkarusEntity * entity, IkarusErrorData * error_out) { entity->project->uncache(entity); } +IkarusId ikarus_entity_get_id(IkarusEntity const * entity, IkarusErrorData * error_out) { + return ikarus::util::object_get_id(entity, error_out); +} + IkarusProject * ikarus_entity_get_project(IkarusEntity const * entity, IkarusErrorData * error_out) { return ikarus::util::object_get_project(entity, error_out); } diff --git a/src/ikarus/objects/properties/property.cpp b/src/ikarus/objects/properties/property.cpp index f45adbb..929d3a6 100644 --- a/src/ikarus/objects/properties/property.cpp +++ b/src/ikarus/objects/properties/property.cpp @@ -28,6 +28,10 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData * property->project->uncache(property); } +IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out) { + return ikarus::util::object_get_id(property, error_out); +} + IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out) { return ikarus::util::object_get_project(property, error_out); } diff --git a/src/ikarus/objects/util.hpp b/src/ikarus/objects/util.hpp index d0b9fa2..8e037ca 100644 --- a/src/ikarus/objects/util.hpp +++ b/src/ikarus/objects/util.hpp @@ -16,6 +16,14 @@ namespace ikarus::util { +template +[[nodiscard]] IkarusId object_get_id(O const * object, IkarusErrorData * error_out) { + IKARUS_FAIL_IF_NULL(object, 0); + IKARUS_FAIL_IF_OBJECT_MISSING(object, 0); + + return object->id; +} + template [[nodiscard]] IkarusProject * object_get_project(O const * object, IkarusErrorData * error_out) { IKARUS_FAIL_IF_NULL(object, nullptr);