fixup compile errors and allow fetching property properly from cache
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
549bad7aac
commit
cc73cf000d
21 changed files with 213 additions and 122 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <objects/object.hpp>
|
||||
|
||||
struct IkarusBlueprint final : IkarusObject {
|
||||
inline IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||
IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||
|
||||
IkarusBlueprint(IkarusBlueprint const&) = default;
|
||||
IkarusBlueprint(IkarusBlueprint&&) = default;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#include "object.hpp"
|
||||
|
||||
IkarusObject::IkarusObject(IkarusProject * project, IkarusId id):
|
||||
_project{project},
|
||||
_id{id} {}
|
||||
|
||||
IkarusProject * IkarusObject::get_project() {
|
||||
return _project;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ public:
|
|||
virtual ~IkarusObject() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] inline struct IkarusProject * get_project();
|
||||
[[nodiscard]] struct IkarusProject * get_project();
|
||||
|
||||
[[nodiscard]] inline struct IkarusProject * get_project() const;
|
||||
[[nodiscard]] struct IkarusProject * get_project() const;
|
||||
|
||||
[[nodiscard]] inline IkarusId get_id() const;
|
||||
[[nodiscard]] IkarusId get_id() const;
|
||||
|
||||
private:
|
||||
struct IkarusProject mutable * _project;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#include "number_property.hpp"
|
||||
|
||||
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
export module number_property.hpp;
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
struct IkarusNumberProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusNumberProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
#include "property.hpp"
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
||||
IkarusObject{project, id},
|
||||
_data{data} {}
|
||||
|
||||
cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> IkarusProperty::get_property_type(
|
||||
IkarusProject * project, IkarusId id
|
||||
) {
|
||||
LOG_DEBUG("fetching unboxed property type");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", project->get_path().c_str(), id);
|
||||
|
||||
VTRY(auto const type, project->get_db()->query_one<int>("SELECT `type` FROM `objects` WHERE `id` = ?", id));
|
||||
|
||||
return cppbase::ok(static_cast<IkarusPropertyType>(type));
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
auto * ctx = property->get_project()->get_function_context();
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
property->get_project()
|
||||
->get_db()
|
||||
->execute("DELETE FROM `objects` WHERE `id` = ?", property->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to delete property from objects table: {}", err),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
LOG_VERBOSE("property was successfully deleted from database, freeing");
|
||||
|
||||
property->get_project()->uncache_property(property);
|
||||
|
||||
LOG_VERBOSE("successfully deleted property");
|
||||
}
|
||||
|
||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property) {
|
||||
LOG_DEBUG("fetching property type");
|
||||
}
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <cppbase/result.hpp>
|
||||
|
||||
#include <sqlitecpp/errors.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
struct IkarusProperty : IkarusObject {
|
||||
IkarusProperty(struct IkarusProject * project, IkarusId id);
|
||||
public:
|
||||
using Data = std::variant<struct IkarusToggleProperty *, struct IkarusNumberProperty *, struct IkarusTextProperty *>;
|
||||
|
||||
public:
|
||||
/// \brief Helper to fetch a type for a property that isn't yet wrapped in an object
|
||||
[[nodiscard]] static cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> get_property_type(
|
||||
struct IkarusProject * project, IkarusId id
|
||||
);
|
||||
|
||||
public:
|
||||
IkarusProperty(struct IkarusProject * project, IkarusId id, Data data);
|
||||
|
||||
IkarusProperty(IkarusProperty const&) = default;
|
||||
IkarusProperty(IkarusProperty&&) = default;
|
||||
|
|
@ -12,4 +30,7 @@ struct IkarusProperty : IkarusObject {
|
|||
IkarusProperty& operator=(IkarusProperty&&) = default;
|
||||
|
||||
~IkarusProperty() override = default;
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#include "text_property.hpp"
|
||||
|
||||
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef TEXT_PROPERTY_HPP
|
||||
#define TEXT_PROPERTY_HPP
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
#endif //TEXT_PROPERTY_HPP
|
||||
struct IkarusTextProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusTextProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
#include "toggle_property.hpp"
|
||||
|
||||
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {
|
||||
|
||||
}
|
||||
|
|
@ -3,5 +3,6 @@
|
|||
#include <objects/properties/property.hpp>
|
||||
|
||||
struct IkarusToggleProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue