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 aa6f711251
commit f9de016dfe
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
21 changed files with 213 additions and 122 deletions

View file

@ -0,0 +1,4 @@
#include "number_property.hpp"
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
IkarusProperty{project, id, this} {}

View file

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

View file

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

View file

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

View file

@ -0,0 +1,4 @@
#include "text_property.hpp"
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
IkarusProperty{project, id, this} {}

View file

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

View file

@ -0,0 +1,6 @@
#include "toggle_property.hpp"
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
IkarusProperty{project, id, this} {
}

View file

@ -3,5 +3,6 @@
#include <objects/properties/property.hpp>
struct IkarusToggleProperty final : IkarusProperty {
public:
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
};