fixup compile errors and allow fetching property properly from cache

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2023-11-27 13:13:54 +01:00 committed by Folling
parent 549bad7aac
commit cc73cf000d
No known key found for this signature in database
21 changed files with 213 additions and 122 deletions

View file

@ -17,25 +17,15 @@ IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name) {
LOG_INFO("creating new blueprint");
if (project == nullptr) {
LOG_ERROR("project is nullptr");
return nullptr;
}
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
auto * ctx = project->get_function_context();
if (name == nullptr) {
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
return nullptr;
}
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;
}
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
VTRYRV(
auto const id,
nullptr,
@ -77,15 +67,10 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
LOG_INFO("deleting blueprint");
if (blueprint == nullptr) {
LOG_ERROR("blueprint is nullptr");
return;
}
LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id());
auto * ctx = blueprint->get_project()->get_function_context();
LOG_DEBUG("blueprint={}", blueprint->get_id());
TRYRV(
,
blueprint->get_project()
@ -101,7 +86,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
})
);
LOG_VERBOSE("blueprint was successfully deleted from database, freeing blueprint");
LOG_VERBOSE("blueprint was successfully deleted from database, freeing");
blueprint->get_project()->uncache_blueprint(blueprint);
@ -111,11 +96,6 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
LOG_VERBOSE("fetching blueprint property count");
if (blueprint == nullptr) {
LOG_ERROR("blueprint is nullptr");
return 0;
}
auto * ctx = blueprint->get_project()->get_function_context();
LOG_DEBUG("blueprint={}", blueprint->get_id());
@ -148,20 +128,15 @@ void ikarus_blueprint_get_properties(
) {
LOG_VERBOSE("fetching blueprint properties");
if (blueprint == nullptr) {
LOG_ERROR("blueprint is nullptr");
return;
}
LOG_DEBUG(
"project={};blueprint={};properties_out_size={}",
blueprint->get_project()->get_path().c_str(),
blueprint->get_id(),
properties_out_size
);
auto * ctx = blueprint->get_project()->get_function_context();
if (properties_out == nullptr) {
ctx->set_error("properties_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
return;
}
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->get_id(), properties_out_size);
IkarusId ids[properties_out_size];
TRYRV(
@ -187,8 +162,23 @@ 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) {
auto const id = ids[i];
VTRYRV(
auto const type,
,
IkarusProperty::get_property_type(blueprint->get_project(), id).on_error([ctx, id](auto const& err) {
ctx->set_error(
fmt::format("failed to fetch property {}'s type: {}", id, err),
true,
IkarusErrorInfo_Source_SubSystem,
IkarusErrorInfo_Type_SubSystem_Database
);
})
);
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
properties_out[i] = blueprint->get_project()->get_property(ids[i]);
properties_out[i] = blueprint->get_project()->get_property(id, type);
}
LOG_VERBOSE("successfully fetched blueprint properties");
@ -197,15 +187,10 @@ void ikarus_blueprint_get_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;
}
LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id());
auto * ctx = blueprint->get_project()->get_function_context();
LOG_DEBUG("blueprint={}", blueprint->get_id());
VTRYRV(
auto count,
0,
@ -234,20 +219,15 @@ void ikarus_blueprint_get_linked_entities(
) {
LOG_VERBOSE("fetching blueprint linked entities");
if (blueprint == nullptr) {
LOG_ERROR("blueprint is nullptr");
return;
}
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();
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->get_id(), entities_out_size);
IkarusId ids[entities_out_size];
TRYRV(
@ -281,22 +261,9 @@ void ikarus_blueprint_get_linked_entities(
}
IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint) {
return const_cast<IkarusObject *>(ikarus_blueprint_to_object_const(blueprint));
return static_cast<IkarusObject *>(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->get_id());
LOG_VERBOSE("successfully casted blueprint to object");
return static_cast<IkarusObject const *>(blueprint);
}