intermediate commit
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
82e5309f80
commit
ea221cdf85
11 changed files with 175 additions and 175 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "blueprint.hpp"
|
||||
#include <iterator>
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
#include <cppbase/result.hpp>
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <ikarus/objects/blueprint.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/property.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
|
@ -18,7 +19,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto ctx = project->function_context();
|
||||
auto * ctx = project->function_context();
|
||||
|
||||
if (name == nullptr) {
|
||||
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
|
|
@ -30,7 +31,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
LOG_VERBOSE("project={}; name={}", project->path().c_str(), name);
|
||||
LOG_DEBUG("project={}; name={}", project->path().c_str(), name);
|
||||
|
||||
VTRYRV(
|
||||
auto id,
|
||||
|
|
@ -45,9 +46,9 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
name
|
||||
));
|
||||
|
||||
auto id = db->last_insert_rowid();
|
||||
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint);
|
||||
|
||||
LOG_VERBOSE("id is {}", id);
|
||||
LOG_DEBUG("blueprint is {}", id);
|
||||
|
||||
LOG_VERBOSE("inserting blueprint into blueprints table");
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_VERBOSE("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
|
|
@ -113,13 +114,13 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
|||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_VERBOSE("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint_id` = ?;", blueprint->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),
|
||||
|
|
@ -130,6 +131,10 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
|||
})
|
||||
);
|
||||
|
||||
LOG_DEBUG("blueprint property count: {}", count);
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint property count");
|
||||
|
||||
return static_cast<size_t>(count);
|
||||
}
|
||||
|
||||
|
|
@ -146,11 +151,11 @@ void ikarus_blueprint_get_properties(
|
|||
auto * ctx = blueprint->project->function_context();
|
||||
|
||||
if (properties_out == nullptr) {
|
||||
LOG_ERROR("properties_out is nullptr");
|
||||
ctx->set_error("properties_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_VERBOSE("blueprint={}; properties_out_size={}", blueprint->id, properties_out_size);
|
||||
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->id, properties_out_size);
|
||||
|
||||
IkarusId ids[properties_out_size];
|
||||
|
||||
|
|
@ -173,6 +178,8 @@ void ikarus_blueprint_get_properties(
|
|||
})
|
||||
);
|
||||
|
||||
LOG_DEBUG("blueprint properties: [{}]", fmt::join(ids, ids + properties_out_size, ", "));
|
||||
|
||||
for (size_t i = 0; i < properties_out_size; ++i) {
|
||||
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
properties_out[i] = blueprint->project->get_property(ids[i]);
|
||||
|
|
@ -180,3 +187,108 @@ void ikarus_blueprint_get_properties(
|
|||
|
||||
LOG_VERBOSE("successfully fetched blueprint properties");
|
||||
}
|
||||
|
||||
size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint) {
|
||||
LOG_VERBOSE("fetching blueprint linked entity count");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->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),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
LOG_DEBUG("blueprint linked entity count: {}", count);
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint linked entity count: {}", 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");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
|
||||
if (entities_out == nullptr) {
|
||||
ctx->set_error("entities_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DEBUG("blueprint={}; entities_out_size={}", blueprint->id, entities_out_size);
|
||||
|
||||
IkarusId ids[entities_out_size];
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->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");
|
||||
}
|
||||
|
||||
IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint) {
|
||||
return const_cast<IkarusObject *>(ikarus_blueprint_to_object_const(blueprint));
|
||||
}
|
||||
|
||||
IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * blueprint) {
|
||||
LOG_VERBOSE("casting blueprint to object");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
|
||||
LOG_VERBOSE("successfully casted blueprint to object");
|
||||
|
||||
return static_cast<IkarusObject const *>(blueprint);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue