update sqlitecpp & merge property settings into properties
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
3dd30d74c5
commit
7a7f7462a4
39 changed files with 412 additions and 253 deletions
|
|
@ -8,9 +8,12 @@
|
|||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/property.hpp>
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
||||
IkarusObject{project, id} {}
|
||||
|
||||
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name) {
|
||||
LOG_INFO("creating new blueprint");
|
||||
|
||||
|
|
@ -19,7 +22,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto * ctx = project->function_context();
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
if (name == nullptr) {
|
||||
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
|
|
@ -31,12 +34,12 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
LOG_DEBUG("project={}; name={}", project->path().c_str(), name);
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
VTRYRV(
|
||||
auto id,
|
||||
auto const id,
|
||||
nullptr,
|
||||
project->db()
|
||||
project->get_db()
|
||||
->transact([name](auto * db) -> cppbase::Result<IkarusId, sqlitecpp::TransactionError> {
|
||||
LOG_VERBOSE("creating blueprint in objects table");
|
||||
|
||||
|
|
@ -79,14 +82,15 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
->execute("DELETE FROM `objects` WHERE `id` = ?", blueprint->id)
|
||||
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),
|
||||
|
|
@ -99,7 +103,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
|
||||
LOG_VERBOSE("blueprint was successfully deleted from database, freeing blueprint");
|
||||
|
||||
blueprint->project->remove_blueprint(blueprint);
|
||||
blueprint->get_project()->uncache_blueprint(blueprint);
|
||||
|
||||
LOG_VERBOSE("successfully deleted blueprint");
|
||||
}
|
||||
|
|
@ -112,15 +116,16 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->id)
|
||||
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),
|
||||
|
|
@ -148,25 +153,26 @@ void ikarus_blueprint_get_properties(
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
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->id, properties_out_size);
|
||||
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->get_id(), properties_out_size);
|
||||
|
||||
IkarusId ids[properties_out_size];
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_many_buffered<IkarusId>(
|
||||
"SELECT `id` FROM `properties` WHERE `source` = ?",
|
||||
static_cast<IkarusId *>(ids),
|
||||
properties_out_size,
|
||||
blueprint->id
|
||||
blueprint->get_id()
|
||||
)
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
|
|
@ -182,7 +188,7 @@ void ikarus_blueprint_get_properties(
|
|||
|
||||
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]);
|
||||
properties_out[i] = blueprint->get_project()->get_property(ids[i]);
|
||||
}
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint properties");
|
||||
|
|
@ -196,15 +202,16 @@ size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprin
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
blueprint->project->db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->id)
|
||||
blueprint->get_project()
|
||||
->get_db()
|
||||
->query_one<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to fetch blueprint linked entity count: {}", err),
|
||||
|
|
@ -232,25 +239,26 @@ void ikarus_blueprint_get_linked_entities(
|
|||
return;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->project->function_context();
|
||||
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->id, entities_out_size);
|
||||
LOG_DEBUG("blueprint={}; entities_out_size={}", blueprint->get_id(), entities_out_size);
|
||||
|
||||
IkarusId ids[entities_out_size];
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->project->db()
|
||||
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->id
|
||||
blueprint->get_id()
|
||||
)
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
|
|
@ -266,7 +274,7 @@ void ikarus_blueprint_get_linked_entities(
|
|||
|
||||
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]);
|
||||
entities_out[i] = blueprint->get_project()->get_entity(ids[i]);
|
||||
}
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint linked entities");
|
||||
|
|
@ -286,7 +294,7 @@ IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * bl
|
|||
|
||||
// auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
LOG_VERBOSE("successfully casted blueprint to object");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,14 @@
|
|||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusBlueprint : public IkarusObject {
|
||||
inline IkarusBlueprint(struct IkarusProject * project, IkarusId id):
|
||||
IkarusObject{project, id} {}
|
||||
struct IkarusBlueprint final : IkarusObject {
|
||||
inline IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||
|
||||
IkarusBlueprint(IkarusBlueprint const&) = default;
|
||||
IkarusBlueprint(IkarusBlueprint&&) = default;
|
||||
|
||||
IkarusBlueprint& operator=(IkarusBlueprint const&) = default;
|
||||
IkarusBlueprint& operator=(IkarusBlueprint&&) = default;
|
||||
|
||||
~IkarusBlueprint() override = default;
|
||||
};
|
||||
|
|
|
|||
0
src/objects/entity.cpp
Normal file
0
src/objects/entity.cpp
Normal file
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusEntity : public IkarusObject {
|
||||
struct IkarusEntity final : IkarusObject {
|
||||
inline IkarusEntity(struct IkarusProject * project, IkarusId id):
|
||||
IkarusObject{project, id} {}
|
||||
|
||||
IkarusEntity(IkarusEntity const&) = default;
|
||||
IkarusEntity(IkarusEntity&&) = default;
|
||||
|
||||
IkarusEntity& operator=(IkarusEntity const&) = default;
|
||||
IkarusEntity& operator=(IkarusEntity&&) = default;
|
||||
|
||||
~IkarusEntity() override = default;
|
||||
};
|
||||
|
|
|
|||
13
src/objects/object.cpp
Normal file
13
src/objects/object.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "object.hpp"
|
||||
|
||||
IkarusProject * IkarusObject::get_project() {
|
||||
return _project;
|
||||
}
|
||||
|
||||
IkarusProject * IkarusObject::get_project() const {
|
||||
return _project;
|
||||
}
|
||||
|
||||
IkarusId IkarusObject::get_id() const {
|
||||
return _id;
|
||||
}
|
||||
|
|
@ -1,14 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <id.hpp>
|
||||
#include <ikarus/id.h>
|
||||
|
||||
struct IkarusObject {
|
||||
struct IkarusProject * project;
|
||||
IkarusId id;
|
||||
public:
|
||||
IkarusObject(struct IkarusProject * project, IkarusId id);
|
||||
|
||||
inline IkarusObject(struct IkarusProject * project, IkarusId id):
|
||||
project{project},
|
||||
id{id} {}
|
||||
IkarusObject(IkarusObject const&) = default;
|
||||
IkarusObject(IkarusObject&&) = default;
|
||||
|
||||
IkarusObject& operator=(IkarusObject const&) = default;
|
||||
IkarusObject& operator=(IkarusObject&&) = default;
|
||||
|
||||
virtual ~IkarusObject() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] inline struct IkarusProject * get_project();
|
||||
|
||||
[[nodiscard]] inline struct IkarusProject * get_project() const;
|
||||
|
||||
[[nodiscard]] inline IkarusId get_id() const;
|
||||
|
||||
private:
|
||||
struct IkarusProject mutable * _project;
|
||||
IkarusId _id;
|
||||
};
|
||||
|
|
|
|||
0
src/objects/properties/number_property.cpp
Normal file
0
src/objects/properties/number_property.cpp
Normal file
5
src/objects/properties/number_property.hpp
Normal file
5
src/objects/properties/number_property.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
|
||||
export module number_property.hpp;
|
||||
0
src/objects/properties/property.cpp
Normal file
0
src/objects/properties/property.cpp
Normal file
15
src/objects/properties/property.hpp
Normal file
15
src/objects/properties/property.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
struct IkarusProperty : IkarusObject {
|
||||
IkarusProperty(struct IkarusProject * project, IkarusId id);
|
||||
|
||||
IkarusProperty(IkarusProperty const&) = default;
|
||||
IkarusProperty(IkarusProperty&&) = default;
|
||||
|
||||
IkarusProperty& operator=(IkarusProperty const&) = default;
|
||||
IkarusProperty& operator=(IkarusProperty&&) = default;
|
||||
|
||||
~IkarusProperty() override = default;
|
||||
};
|
||||
0
src/objects/properties/property_source.cpp
Normal file
0
src/objects/properties/property_source.cpp
Normal file
30
src/objects/properties/property_source.hpp
Normal file
30
src/objects/properties/property_source.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <ikarus/objects/properties/property_source.h>
|
||||
|
||||
struct IkarusPropertySource {
|
||||
public:
|
||||
using Data = std::variant<IkarusBlueprint *, IkarusEntity *>;
|
||||
|
||||
public:
|
||||
inline explicit IkarusPropertySource(Data data):
|
||||
_data{data} {}
|
||||
|
||||
IkarusPropertySource(IkarusPropertySource const&) = default;
|
||||
IkarusPropertySource(IkarusPropertySource&&) = default;
|
||||
|
||||
IkarusPropertySource& operator=(IkarusPropertySource const&) = default;
|
||||
IkarusPropertySource& operator=(IkarusPropertySource&&) = default;
|
||||
|
||||
~IkarusPropertySource() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] inline Data const& get_data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::variant<IkarusBlueprint *, IkarusEntity *> _data;
|
||||
};
|
||||
0
src/objects/properties/text_property.cpp
Normal file
0
src/objects/properties/text_property.cpp
Normal file
8
src/objects/properties/text_property.hpp
Normal file
8
src/objects/properties/text_property.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
|
||||
#ifndef TEXT_PROPERTY_HPP
|
||||
#define TEXT_PROPERTY_HPP
|
||||
|
||||
#endif //TEXT_PROPERTY_HPP
|
||||
0
src/objects/properties/toggle_property.cpp
Normal file
0
src/objects/properties/toggle_property.cpp
Normal file
7
src/objects/properties/toggle_property.hpp
Normal file
7
src/objects/properties/toggle_property.hpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
struct IkarusToggleProperty final : IkarusProperty {
|
||||
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#include "property.hpp"
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
#include <cppbase/result.hpp>
|
||||
#include <cppbase/strings.hpp>
|
||||
|
||||
#include <ikarus/values/value.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/property.hpp>
|
||||
#include <objects/property_source.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
/// \private
|
||||
struct IkarusProperty : public IkarusObject {
|
||||
inline IkarusProperty(struct IkarusProject * project, IkarusId id):
|
||||
IkarusObject{project, id} {}
|
||||
};
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <ikarus/objects/properties/property_source.h>
|
||||
|
||||
/// \private
|
||||
struct IkarusPropertySource {
|
||||
std::variant<IkarusBlueprint *, IkarusEntity *> data;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue