From 5da995b47e6e617fba177118d5174548697bab5b Mon Sep 17 00:00:00 2001 From: Folling Date: Tue, 26 Dec 2023 13:09:41 +0100 Subject: [PATCH] make object fields public and fixup compile errors Signed-off-by: Folling --- .clang-tidy | 2 +- include/ikarus/objects/blueprint.h | 24 +-- include/ikarus/objects/entity.h | 6 +- include/ikarus/objects/object_type.h | 6 + src/objects/blueprint.cpp | 251 +++++++++++---------------- src/objects/entity.cpp | 21 +++ src/objects/object.cpp | 16 +- src/objects/object.hpp | 15 +- src/objects/object_helper.hpp | 68 ++++++++ src/objects/object_type.cpp | 12 ++ src/objects/properties/property.cpp | 32 ++-- src/persistence/project.cpp | 9 +- src/persistence/project.hpp | 12 +- 13 files changed, 258 insertions(+), 216 deletions(-) create mode 100644 src/objects/object_helper.hpp create mode 100644 src/objects/object_type.cpp diff --git a/.clang-tidy b/.clang-tidy index fa1f43f..7262427 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,6 @@ Checks: >- -*, - bugprone-*, + bugprone-*, -bugprone-lambda-function-name, cppcoreguidelines-*, -cppcoreguidelines-owning-memory, clang-analyzer-*, google-*, -google-readability-todo, diff --git a/include/ikarus/objects/blueprint.h b/include/ikarus/objects/blueprint.h index 57d1a7c..ce83160 100644 --- a/include/ikarus/objects/blueprint.h +++ b/include/ikarus/objects/blueprint.h @@ -35,13 +35,6 @@ 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); -/// \brief Gets the number of properties of a blueprint. -/// \param blueprint The blueprint to get the number of properties of. -/// \pre \li Must not be null. -/// \pre \li Must exist. -/// \return The number of properties or undefined if an error occurs. -IKA_API size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint); - /// \brief Gets the properties of a blueprint. /// \param blueprint The blueprint to get the properties of. /// \pre \li Must not be null. @@ -49,16 +42,17 @@ IKA_API size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * bluep /// \param properties_out The buffer to write the properties to. /// \pre \li Must not be null. /// \param properties_out_size The size of the buffer. +/// \see ikarus_blueprint_get_property_count IKA_API void ikarus_blueprint_get_properties( IkarusBlueprint const * blueprint, struct IkarusProperty ** properties_out, size_t properties_out_size ); -/// \brief Gets the number of entities linked to a blueprint. -/// \param blueprint The blueprint to get the number of linked entities of. +/// \brief Gets the number of properties of a blueprint. +/// \param blueprint The blueprint to get the number of properties of. /// \pre \li Must not be null. /// \pre \li Must exist. -/// \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); +/// \return The number of properties or undefined if an error occurs. +IKA_API size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint); /// \brief Gets the entities linked to a blueprint. /// \param blueprint The blueprint to get the linked entities of. @@ -67,10 +61,18 @@ IKA_API size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * /// \param entities_out The buffer to write the entities to. /// \pre \li Must not be null. /// \param entities_out_size The size of the buffer. +/// \see ikarus_blueprint_get_linked_entity_count IKA_API void ikarus_blueprint_get_linked_entities( IkarusBlueprint const * blueprint, struct IkarusEntity ** entities_out, size_t entities_out_size ); +/// \brief Gets the number of entities linked to a blueprint. +/// \param blueprint The blueprint to get the number of linked entities of. +/// \pre \li Must not be null. +/// \pre \li Must exist. +/// \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); + /// \brief Casts a blueprint to an object. /// \param blueprint The blueprint to cast. /// \pre \li Must not be null. diff --git a/include/ikarus/objects/entity.h b/include/ikarus/objects/entity.h index 5ce2266..782452e 100644 --- a/include/ikarus/objects/entity.h +++ b/include/ikarus/objects/entity.h @@ -45,13 +45,9 @@ struct IkarusEntity; /// \param name The name of the entity. /// \pre \li Must not be null. /// \pre \li Must not be empty. -/// \param blueprints Blueprints to link the entity to (0..n). Null is treated as an empty array. -/// \param blueprints_count The number of blueprints. /// \return The created entity or null if an error occurs. /// \remark Must be freed using #ikarus_free. -IKA_API IkarusEntity * ikarus_entity_create( - struct IkarusProject * project, char const * name, struct IkarusBlueprint ** blueprints, size_t blueprints_count -); +IKA_API IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name); /// \brief Deletes an entity. /// \param entity The entity to delete. diff --git a/include/ikarus/objects/object_type.h b/include/ikarus/objects/object_type.h index efb6609..4298a9b 100644 --- a/include/ikarus/objects/object_type.h +++ b/include/ikarus/objects/object_type.h @@ -22,6 +22,12 @@ enum IkarusObjectType { 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 /// @} diff --git a/src/objects/blueprint.cpp b/src/objects/blueprint.cpp index bdbea93..fc49c71 100644 --- a/src/objects/blueprint.cpp +++ b/src/objects/blueprint.cpp @@ -1,13 +1,16 @@ +#include "ikarus/objects/blueprint.h" + +#include "objects/blueprint.hpp" + #include #include #include #include -#include - -#include #include +#include +#include #include #include @@ -26,40 +29,9 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c return nullptr; } - VTRYRV( - auto const id, - nullptr, - project->get_db() - ->transact([name](auto * db) -> cppbase::Result { - LOG_VERBOSE("creating blueprint in objects table"); - - TRY(db->execute( - "INSERT INTO `objects` (`object_type`, `name`) VALUES(?, ?);", - static_cast(IkarusObjectType_Blueprint), - name - )); - - auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint); - - LOG_DEBUG("blueprint is {}", id); - - LOG_VERBOSE("inserting blueprint into blueprints table"); - - TRY(db->execute("INSERT INTO `blueprints`(`id`) VALUES(?);", id)); - - return cppbase::ok(id); - }) - .on_error([ctx](auto const& err) { - ctx->set_error( - fmt::format("unable to insert blueprint into database: {}", err), - true, - IkarusErrorInfo_Source_SubSystem, - IkarusErrorInfo_Type_SubSystem_Database - ); - }) - ); - - LOG_VERBOSE("successfully created blueprint"); + VTRYRV(auto const id, nullptr, insert_object(project, ctx, IkarusObjectType_Blueprint, name, [](auto * db, IkarusId id) { + return db->execute("INSERT INTO `blueprints`(`id`) VALUES(?)", id); + })); return project->get_blueprint(id); } @@ -67,60 +39,11 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c void ikarus_blueprint_delete(IkarusBlueprint * blueprint) { LOG_INFO("deleting blueprint"); - LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id()); + LOG_DEBUG("project={}; blueprint={}", blueprint->project->get_path().c_str(), blueprint->id); - auto * ctx = blueprint->get_project()->get_function_context(); + auto * ctx = blueprint->project->get_function_context(); - TRYRV( - , - blueprint->get_project() - ->get_db() - ->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->get_id()) - .on_error([ctx](auto const& err) { - ctx->set_error( - fmt::format("failed to delete blueprint from objects table: {}", err), - true, - IkarusErrorInfo_Source_SubSystem, - IkarusErrorInfo_Type_SubSystem_Database - ); - }) - ); - - LOG_VERBOSE("blueprint was successfully deleted from database, freeing"); - - blueprint->get_project()->uncache_blueprint(blueprint); - - LOG_VERBOSE("successfully deleted blueprint"); -} - -size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) { - LOG_VERBOSE("fetching blueprint property count"); - - auto * ctx = blueprint->get_project()->get_function_context(); - - LOG_DEBUG("blueprint={}", blueprint->get_id()); - - VTRYRV( - auto count, - 0, - blueprint->get_project() - ->get_db() - ->query_one("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->get_id()) - .on_error([ctx](auto const& err) { - ctx->set_error( - fmt::format("failed to fetch blueprint property count: {}", err), - true, - IkarusErrorInfo_Source_SubSystem, - IkarusErrorInfo_Type_SubSystem_Database - ); - }) - ); - - LOG_DEBUG("blueprint property count: {}", count); - - LOG_VERBOSE("successfully fetched blueprint property count"); - - return static_cast(count); + delete_object(blueprint->project, ctx, blueprint); } void ikarus_blueprint_get_properties( @@ -129,25 +52,25 @@ void ikarus_blueprint_get_properties( LOG_VERBOSE("fetching blueprint properties"); LOG_DEBUG( - "project={};blueprint={};properties_out_size={}", - blueprint->get_project()->get_path().c_str(), - blueprint->get_id(), + "project={}; blueprint={}; properties_out_size={}", + blueprint->project->get_path().c_str(), + blueprint->id, properties_out_size ); - auto * ctx = blueprint->get_project()->get_function_context(); + auto * ctx = blueprint->project->get_function_context(); IkarusId ids[properties_out_size]; TRYRV( , - blueprint->get_project() + blueprint->project ->get_db() ->query_many_buffered( "SELECT `id` FROM `properties` WHERE `source` = ?", static_cast(ids), properties_out_size, - blueprint->get_id() + blueprint->id ) .on_error([ctx](auto const& err) { ctx->set_error( @@ -167,7 +90,7 @@ void ikarus_blueprint_get_properties( VTRYRV( auto const type, , - IkarusProperty::get_property_type(blueprint->get_project(), id).on_error([ctx, id](auto const& err) { + IkarusProperty::get_property_type(blueprint->project, id).on_error([ctx, id](auto const& err) { ctx->set_error( fmt::format("failed to fetch property {}'s type: {}", id, err), true, @@ -178,25 +101,101 @@ void ikarus_blueprint_get_properties( ); /// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - properties_out[i] = blueprint->get_project()->get_property(id, type); + properties_out[i] = blueprint->project->get_property(id, type); } LOG_VERBOSE("successfully fetched blueprint properties"); } -size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint) { - LOG_VERBOSE("fetching blueprint linked entity count"); +size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) { + LOG_VERBOSE("fetching blueprint property count"); - LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id()); + auto * ctx = blueprint->project->get_function_context(); - auto * ctx = blueprint->get_project()->get_function_context(); + LOG_DEBUG("blueprint={}", blueprint->id); VTRYRV( auto count, 0, - blueprint->get_project() + blueprint->project ->get_db() - ->query_one("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->get_id()) + ->query_one("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->id) + .on_error([ctx](auto const& err) { + ctx->set_error( + fmt::format("failed to fetch blueprint property count: {}", err), + true, + IkarusErrorInfo_Source_SubSystem, + IkarusErrorInfo_Type_SubSystem_Database + ); + }) + ); + + LOG_DEBUG("blueprint property count: {}", count); + + LOG_VERBOSE("successfully fetched blueprint property count"); + + return static_cast(count); +} + +void ikarus_blueprint_get_linked_entities( + IkarusBlueprint const * blueprint, struct IkarusEntity ** entities_out, size_t entities_out_size +) { + LOG_VERBOSE("fetching blueprint linked entities"); + + LOG_DEBUG( + "project={}; blueprint={}; entities_out_size={}", + blueprint->project->get_path().c_str(), + blueprint->id, + entities_out_size + ); + + auto * ctx = blueprint->project->get_function_context(); + + IkarusId ids[entities_out_size]; + + TRYRV( + , + blueprint->project + ->get_db() + ->query_many_buffered( + "SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?", + static_cast(ids), + entities_out_size, + blueprint->id + ) + .on_error([ctx](auto const& err) { + ctx->set_error( + fmt::format("failed to fetch blueprint linked entity ids: {}", err), + true, + IkarusErrorInfo_Source_SubSystem, + IkarusErrorInfo_Type_SubSystem_Database + ); + }) + ); + + LOG_DEBUG("blueprint linked entities: [{}]", fmt::join(ids, ids + entities_out_size, ", ")); + + for (size_t i = 0; i < entities_out_size; ++i) { + /// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + entities_out[i] = blueprint->project->get_entity(ids[i]); + } + + LOG_VERBOSE("successfully fetched blueprint linked entities"); +} + +size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint) { + LOG_VERBOSE("fetching blueprint linked entity count"); + + LOG_DEBUG("project={}; blueprint={}", blueprint->project->get_path().c_str(), blueprint->id); + + auto * ctx = blueprint->project->get_function_context(); + + VTRYRV( + auto count, + 0, + blueprint->project + ->get_db() + ->query_one("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->id) .on_error([ctx](auto const& err) { ctx->set_error( fmt::format("failed to fetch blueprint linked entity count: {}", err), @@ -214,52 +213,6 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin return static_cast(count); } -void ikarus_blueprint_get_linked_entities( - IkarusBlueprint const * blueprint, struct IkarusEntity ** entities_out, size_t entities_out_size -) { - LOG_VERBOSE("fetching blueprint linked entities"); - - LOG_DEBUG( - "project={};blueprint={};entities_out_size={}", - blueprint->get_project()->get_path().c_str(), - blueprint->get_id(), - entities_out_size - ); - - auto * ctx = blueprint->get_project()->get_function_context(); - - IkarusId ids[entities_out_size]; - - TRYRV( - , - blueprint->get_project() - ->get_db() - ->query_many_buffered( - "SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?", - static_cast(ids), - entities_out_size, - blueprint->get_id() - ) - .on_error([ctx](auto const& err) { - ctx->set_error( - fmt::format("failed to fetch blueprint linked entity ids: {}", err), - true, - IkarusErrorInfo_Source_SubSystem, - IkarusErrorInfo_Type_SubSystem_Database - ); - }) - ); - - LOG_DEBUG("blueprint linked entities: [{}]", fmt::join(ids, ids + entities_out_size, ", ")); - - for (size_t i = 0; i < entities_out_size; ++i) { - /// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - entities_out[i] = blueprint->get_project()->get_entity(ids[i]); - } - - LOG_VERBOSE("successfully fetched blueprint linked entities"); -} - IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint) { return static_cast(blueprint); } diff --git a/src/objects/entity.cpp b/src/objects/entity.cpp index e69de29..ce5d853 100644 --- a/src/objects/entity.cpp +++ b/src/objects/entity.cpp @@ -0,0 +1,21 @@ +#include "entity.hpp" + +#include + +#include +#include + +IkarusEntity * ikarus_entity_create(struct IkarusProject * project, char const * name) { + LOG_INFO("creating new entity"); + + LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name); + + auto * ctx = project->get_function_context(); + + if (cppbase::is_empty_or_blank(name)) { + ctx->set_error("name is empty or blank", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input); + return nullptr; + } + + // TODO +} diff --git a/src/objects/object.cpp b/src/objects/object.cpp index 2ce961e..204c7a7 100644 --- a/src/objects/object.cpp +++ b/src/objects/object.cpp @@ -1,17 +1,5 @@ #include "object.hpp" IkarusObject::IkarusObject(IkarusProject * project, IkarusId id): - _project{project}, - _id{id} {} - -IkarusProject * IkarusObject::get_project() { - return _project; -} - -IkarusProject * IkarusObject::get_project() const { - return _project; -} - -IkarusId IkarusObject::get_id() const { - return _id; -} + project{project}, + id{id} {} diff --git a/src/objects/object.hpp b/src/objects/object.hpp index bb28da5..5a94aa2 100644 --- a/src/objects/object.hpp +++ b/src/objects/object.hpp @@ -1,5 +1,9 @@ #pragma once +#include + +#include + #include struct IkarusObject { @@ -15,13 +19,6 @@ public: virtual ~IkarusObject() = default; public: - [[nodiscard]] struct IkarusProject * get_project(); - - [[nodiscard]] struct IkarusProject * get_project() const; - - [[nodiscard]] IkarusId get_id() const; - -private: - struct IkarusProject mutable * _project; - IkarusId _id; + struct IkarusProject * project; + IkarusId id; }; diff --git a/src/objects/object_helper.hpp b/src/objects/object_helper.hpp new file mode 100644 index 0000000..0fe9df7 --- /dev/null +++ b/src/objects/object_helper.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include + +#include + +#include +#include + +#include + +template F> +[[nodiscard]] cppbase::Result insert_object( + IkarusProject * project, FunctionContext * ctx, IkarusObjectType type, std::string_view name, F insert_function +) { + char const * object_type_str = ikarus_object_type_to_string(type); + + VTRY( + auto const id, + project->get_db() + ->transact([&](auto * db) -> cppbase::Result { + LOG_VERBOSE("creating {} in objects table", object_type_str); + + TRY(db->execute("INSERT INTO `objects` (`object_type`, `name`) VALUES(?, ?);", static_cast(type), name)); + + auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint); + + LOG_DEBUG("{} is {}", object_type_str, id); + + TRY(insert_function(db, id)); + + return cppbase::ok(id); + }) + .on_error([&](auto const& err) { + ctx->set_error( + fmt::format("unable to insert {} into database: {}", object_type_str, err), + true, + IkarusErrorInfo_Source_SubSystem, + IkarusErrorInfo_Type_SubSystem_Database + ); + }) + ); + + LOG_VERBOSE("successfully created blueprint"); + + return cppbase::ok(id); +} + +template +void delete_object(IkarusProject * project, FunctionContext * ctx, T * object) { + auto id = object->id; + auto object_type_str = ikarus_object_type_to_string(ikarus_id_get_object_type(id)); + + TRYRV(, project->get_db()->execute("DELETE FROM `objects` WHERE `id` = ?", id).on_error([&](auto const& err) { + ctx->set_error( + fmt::format("failed to delete {} from objects table: {}", object_type_str, err), + true, + IkarusErrorInfo_Source_SubSystem, + IkarusErrorInfo_Type_SubSystem_Database + ); + })); + + LOG_VERBOSE("{} was successfully deleted from database, freeing", object_type_str); + + project->uncache(object); + + LOG_VERBOSE("successfully deleted {}", object_type_str); +} diff --git a/src/objects/object_type.cpp b/src/objects/object_type.cpp new file mode 100644 index 0000000..fb7d825 --- /dev/null +++ b/src/objects/object_type.cpp @@ -0,0 +1,12 @@ +#include "ikarus/objects/object_type.h" + +char const * ikarus_object_type_to_string(IkarusObjectType type) { + switch (type) { + case IkarusObjectType_None: return "none"; + case IkarusObjectType_Entity: return "entity"; + case IkarusObjectType_Blueprint: return "blueprint"; + case IkarusObjectType_Property: return "property"; + } + + return "unknown"; +} diff --git a/src/objects/properties/property.cpp b/src/objects/properties/property.cpp index 00ab888..2abef0a 100644 --- a/src/objects/properties/property.cpp +++ b/src/objects/properties/property.cpp @@ -51,15 +51,15 @@ cppbase::Result IkarusProperty: IKA_API void ikarus_property_delete(IkarusProperty * property) { LOG_INFO("deleting property"); - LOG_VERBOSE("project={};property={}", property->get_project()->get_path().c_str(), property->get_id()); + LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id); - auto * ctx = property->get_project()->get_function_context(); + auto * ctx = property->project->get_function_context(); TRYRV( , - property->get_project() + property->project ->get_db() - ->execute("DELETE FROM `objects` WHERE `id` = ?", property->get_id()) + ->execute("DELETE FROM `objects` WHERE `id` = ?", property->id) .on_error([ctx](auto const& err) { ctx->set_error( fmt::format("failed to delete property from objects table: {}", err), @@ -72,7 +72,7 @@ IKA_API void ikarus_property_delete(IkarusProperty * property) { LOG_VERBOSE("property was successfully deleted from database, freeing"); - property->get_project()->uncache_property(property); + property->project->uncache(property); LOG_VERBOSE("successfully deleted property"); } @@ -80,23 +80,23 @@ IKA_API void ikarus_property_delete(IkarusProperty * property) { IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property) { LOG_VERBOSE("fetching property type"); - return IkarusProperty::get_property_type(property->get_project(), property->get_id()) + return IkarusProperty::get_property_type(property->project, property->id) .unwrap_value_or(IkarusPropertyType_Toggle); } IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property) { LOG_VERBOSE("fetching property source"); - LOG_VERBOSE("project={};property={}", property->get_project()->get_path().c_str(), property->get_id()); + LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id); - auto * ctx = property->get_project()->get_function_context(); + auto * ctx = property->project->get_function_context(); VTRYRV( auto const source, nullptr, - property->get_project() + property->project ->get_db() - ->query_one("SELECT `source` FROM `properties` WHERE `id` = ?", property->get_id()) + ->query_one("SELECT `source` FROM `properties` WHERE `id` = ?", property->id) .on_error([ctx](auto const& err) { ctx->set_error( fmt::format("failed to fetch property's source: {}", err), @@ -108,8 +108,8 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p ); switch (ikarus_id_get_object_type(source)) { - case IkarusObjectType_Blueprint: return new IkarusPropertySource{property->get_project()->get_blueprint(source)}; - case IkarusObjectType_Entity: return new IkarusPropertySource{property->get_project()->get_entity(source)}; + case IkarusObjectType_Blueprint: return new IkarusPropertySource{property->project->get_blueprint(source)}; + case IkarusObjectType_Entity: return new IkarusPropertySource{property->project->get_entity(source)}; default: { ctx->set_error( fmt::format("PropertySource is neither blueprint nor entity"), @@ -126,16 +126,16 @@ IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * p IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property) { LOG_VERBOSE("fetching property default value"); - LOG_VERBOSE("project={};property={}", property->get_project()->get_path().c_str(), property->get_id()); + LOG_VERBOSE("project={};property={}", property->project->get_path().c_str(), property->id); - auto * ctx = property->get_project()->get_function_context(); + auto * ctx = property->project->get_function_context(); VTRYRV( auto const value, nullptr, - property->get_project() + property->project ->get_db() - ->query_one("SELECT `default_value` FROM `properties` WHERE `id` = ?", property->get_id()) + ->query_one("SELECT `default_value` FROM `properties` WHERE `id` = ?", property->id) .on_error([ctx](auto const& err) { ctx->set_error( fmt::format("failed to fetch property's default value: {}", err), diff --git a/src/persistence/project.cpp b/src/persistence/project.cpp index d7d5e5e..163bc93 100644 --- a/src/persistence/project.cpp +++ b/src/persistence/project.cpp @@ -2,7 +2,10 @@ #include "ikarus/persistence/project.h" +#include +#include #include +#include #include #include #include @@ -31,7 +34,7 @@ IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) { return get_cached_object(id, this->_blueprints); } -auto IkarusProject::uncache_blueprint(IkarusBlueprint * blueprint) -> void { +auto IkarusProject::uncache(IkarusBlueprint * blueprint) -> void { remove_cached_object(blueprint, _blueprints); } @@ -39,7 +42,7 @@ auto IkarusProject::get_entity(IkarusId id) -> IkarusEntity * { return get_cached_object(id, this->_entities); } -auto IkarusProject::uncache_entity(IkarusEntity * entity) -> void { +auto IkarusProject::uncache(IkarusEntity * entity) -> void { remove_cached_object(entity, _entities); } @@ -60,6 +63,6 @@ auto IkarusProject::get_property(IkarusId id, IkarusPropertyType type) -> Ikarus return iter->second.get(); } -auto IkarusProject::uncache_property(IkarusProperty * property) -> void { +auto IkarusProject::uncache(IkarusProperty * property) -> void { remove_cached_object(property, _properties); } diff --git a/src/persistence/project.hpp b/src/persistence/project.hpp index d3fc6a1..2af1fff 100644 --- a/src/persistence/project.hpp +++ b/src/persistence/project.hpp @@ -11,10 +11,6 @@ #include #include -#include -#include -#include - constexpr inline auto MAXIMUM_ERROR_INFOS = 8; /// \private @@ -32,13 +28,13 @@ public: public: [[nodiscard]] auto get_blueprint(IkarusId id) -> struct IkarusBlueprint *; - auto uncache_blueprint(struct IkarusBlueprint * blueprint) -> void; + auto uncache(struct IkarusBlueprint * blueprint) -> void; [[nodiscard]] auto get_entity(IkarusId id) -> struct IkarusEntity *; - auto uncache_entity(struct IkarusEntity * entity) -> void; + auto uncache(struct IkarusEntity * entity) -> void; [[nodiscard]] auto get_property(IkarusId id, IkarusPropertyType type) -> struct IkarusProperty *; - auto uncache_property(struct IkarusProperty * property) -> void; + auto uncache(struct IkarusProperty * property) -> void; private: template @@ -54,7 +50,7 @@ private: template void remove_cached_object(T * object, std::unordered_map>& cache) { - cache.erase(object->get_id()); + cache.erase(object->id); } private: