make object fields public and fixup compile errors

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2023-12-26 13:09:41 +01:00 committed by Folling
parent 8a76573983
commit 5da995b47e
No known key found for this signature in database
13 changed files with 258 additions and 216 deletions

View file

@ -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(
@ -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<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);
}