make object fields public and fixup compile errors
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
8a76573983
commit
5da995b47e
13 changed files with 258 additions and 216 deletions
|
|
@ -1,6 +1,6 @@
|
|||
Checks: >-
|
||||
-*,
|
||||
bugprone-*,
|
||||
bugprone-*, -bugprone-lambda-function-name,
|
||||
cppcoreguidelines-*, -cppcoreguidelines-owning-memory,
|
||||
clang-analyzer-*,
|
||||
google-*, -google-readability-todo,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
#include "ikarus/objects/blueprint.h"
|
||||
|
||||
#include "objects/blueprint.hpp"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
#include <cppbase/result.hpp>
|
||||
#include <cppbase/strings.hpp>
|
||||
|
||||
#include <ikarus/objects/blueprint.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/object_helper.hpp>
|
||||
#include <objects/properties/property.hpp>
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
|
|
@ -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<IkarusId, sqlitecpp::TransactionError> {
|
||||
LOG_VERBOSE("creating blueprint in objects table");
|
||||
|
||||
TRY(db->execute(
|
||||
"INSERT INTO `objects` (`object_type`, `name`) VALUES(?, ?);",
|
||||
static_cast<int>(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<int>("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<size_t>(count);
|
||||
delete_object(blueprint->project, ctx, blueprint);
|
||||
}
|
||||
|
||||
void ikarus_blueprint_get_properties(
|
||||
|
|
@ -130,24 +53,24 @@ void ikarus_blueprint_get_properties(
|
|||
|
||||
LOG_DEBUG(
|
||||
"project={}; blueprint={}; properties_out_size={}",
|
||||
blueprint->get_project()->get_path().c_str(),
|
||||
blueprint->get_id(),
|
||||
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<IkarusId>(
|
||||
"SELECT `id` FROM `properties` WHERE `source` = ?",
|
||||
static_cast<IkarusId *>(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<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->get_id())
|
||||
->query_one<int>("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<size_t>(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<IkarusId>(
|
||||
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||
static_cast<IkarusId *>(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<int>("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<size_t>(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<IkarusId>(
|
||||
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||
static_cast<IkarusId *>(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<IkarusObject *>(blueprint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
#include "entity.hpp"
|
||||
|
||||
#include <cppbase/strings.hpp>
|
||||
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
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
|
||||
}
|
||||
|
|
@ -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} {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <cppbase/result.hpp>
|
||||
|
||||
#include <sqlitecpp/errors.hpp>
|
||||
|
||||
#include <ikarus/id.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
68
src/objects/object_helper.hpp
Normal file
68
src/objects/object_helper.hpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
|
||||
#include <cppbase/result.hpp>
|
||||
|
||||
#include <ikarus/id.h>
|
||||
#include <ikarus/objects/object_type.h>
|
||||
|
||||
#include <persistence/function_context.hpp>
|
||||
|
||||
template<std::invocable<sqlitecpp::Connection *, IkarusId> F>
|
||||
[[nodiscard]] cppbase::Result<IkarusId, sqlitecpp::TransactionError> 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<IkarusId, sqlitecpp::TransactionError> {
|
||||
LOG_VERBOSE("creating {} in objects table", object_type_str);
|
||||
|
||||
TRY(db->execute("INSERT INTO `objects` (`object_type`, `name`) VALUES(?, ?);", static_cast<int>(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<typename T>
|
||||
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);
|
||||
}
|
||||
12
src/objects/object_type.cpp
Normal file
12
src/objects/object_type.cpp
Normal file
|
|
@ -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";
|
||||
}
|
||||
|
|
@ -51,15 +51,15 @@ cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> 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<int>("SELECT `source` FROM `properties` WHERE `id` = ?", property->get_id())
|
||||
->query_one<int>("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<int>("SELECT `default_value` FROM `properties` WHERE `id` = ?", property->get_id())
|
||||
->query_one<int>("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),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
#include "ikarus/persistence/project.h"
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/properties/number_property.hpp>
|
||||
#include <objects/properties/property.hpp>
|
||||
#include <objects/properties/text_property.hpp>
|
||||
#include <objects/properties/toggle_property.hpp>
|
||||
#include <persistence/function_context.hpp>
|
||||
|
|
@ -31,7 +34,7 @@ IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) {
|
|||
return get_cached_object<IkarusBlueprint>(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<IkarusEntity>(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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@
|
|||
#include <ikarus/id.h>
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
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<typename T>
|
||||
|
|
@ -54,7 +50,7 @@ private:
|
|||
|
||||
template<typename T>
|
||||
void remove_cached_object(T * object, std::unordered_map<IkarusId, std::unique_ptr<T>>& cache) {
|
||||
cache.erase(object->get_id());
|
||||
cache.erase(object->id);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue