update sqlitecpp & merge property settings into properties
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
ff9bf0c14a
commit
88ca7769d1
39 changed files with 412 additions and 253 deletions
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
char const * get_error_info_name(IkarusErrorInfo info) {
|
||||
switch (info) {
|
||||
case IkarusErrorInfo_Source_None: return "IkarusErrorSource_None";
|
||||
case IkarusErrorInfo_Source_Client: return "IkarusErrorSource_Client";
|
||||
case IkarusErrorInfo_Source_SubSystem: return "IkarusErrorSource_SubSystem";
|
||||
case IkarusErrorInfo_Source_LibIkarus: return "IkarusErrorSource_LibIkarus";
|
||||
case IkarusErrorInfo_Source_Unknown: return "IkarusErrorSource_Unknown";
|
||||
case IkarusErrorInfo_Type_None: return "IkarusErrorType_None";
|
||||
case IkarusErrorInfo_Type_Client_Misuse: return "IkarusErrorType_Client_Misuse";
|
||||
case IkarusErrorInfo_Type_Client_Input: return "IkarusErrorType_Client_Input";
|
||||
case IkarusErrorInfo_Type_SubSystem_Dependency: return "IkarusErrorType_SubSystem_Dependency";
|
||||
case IkarusErrorInfo_Type_SubSystem_Database: return "IkarusErrorType_SubSystem_Database";
|
||||
case IkarusErrorInfo_Type_SubSystem_Filesystem: return "IkarusErrorType_SubSystem_Filesystem";
|
||||
case IkarusErrorInfo_Type_LibIkarus_InvalidState: return "IkarusErrorType_LibIkarus_InvalidState";
|
||||
case IkarusErrorInfo_Type_LibIkarus_CannotPerformOperation: return "IkarusErrorType_LibIkarus_CannotPerformOperation";
|
||||
case IkarusErrorInfo_Type_LibIkarus_Timeout: return "IkarusErrorType_LibIkarus_Timeout";
|
||||
case IkarusErrorInfo_Type_Unknown: return "IkarusErrorType_Unknown";
|
||||
case IkarusErrorInfo_Source_None: return "IkarusErrorInfo_Source_None";
|
||||
case IkarusErrorInfo_Source_Client: return "IkarusErrorInfo_Source_Client";
|
||||
case IkarusErrorInfo_Source_SubSystem: return "IkarusErrorInfo_Source_SubSystem";
|
||||
case IkarusErrorInfo_Source_LibIkarus: return "IkarusErrorInfo_Source_LibIkarus";
|
||||
case IkarusErrorInfo_Source_Unknown: return "IkarusErrorInfo_Source_Unknown";
|
||||
case IkarusErrorInfo_Type_None: return "IkarusErrorInfo_Type_None";
|
||||
case IkarusErrorInfo_Type_Client_Misuse: return "IkarusErrorInfo_Type_Client_Misuse";
|
||||
case IkarusErrorInfo_Type_Client_Input: return "IkarusErrorInfo_Type_Client_Input";
|
||||
case IkarusErrorInfo_Type_SubSystem_Dependency: return "IkarusErrorInfo_Type_SubSystem_Dependency";
|
||||
case IkarusErrorInfo_Type_SubSystem_Database: return "IkarusErrorInfo_Type_SubSystem_Database";
|
||||
case IkarusErrorInfo_Type_SubSystem_Filesystem: return "IkarusErrorInfo_Type_SubSystem_Filesystem";
|
||||
case IkarusErrorInfo_Type_LibIkarus_InvalidState: return "IkarusErrorInfo_Type_LibIkarus_InvalidState";
|
||||
case IkarusErrorInfo_Type_LibIkarus_CannotPerformOperation: return "IkarusErrorInfo_Type_LibIkarus_CannotPerformOperation";
|
||||
case IkarusErrorInfo_Type_LibIkarus_Timeout: return "IkarusErrorInfo_Type_LibIkarus_Timeout";
|
||||
case IkarusErrorInfo_Type_Unknown: return "IkarusErrorInfo_Type_Unknown";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
src/id.cpp
24
src/id.cpp
|
|
@ -1,32 +1,16 @@
|
|||
#include "id.hpp"
|
||||
#include "ikarus/id.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/object_type.h>
|
||||
|
||||
uint64_t const IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
||||
uint64_t const IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
||||
constexpr uint64_t IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
||||
constexpr uint64_t IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
||||
|
||||
auto from_data_and_type(int64_t data, IkarusObjectType type) -> IkarusId {
|
||||
auto ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type) -> IkarusId {
|
||||
return data | (static_cast<IkarusId>(type) << IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||
}
|
||||
|
||||
auto ikarus_id_get_object_type(IkarusId id) -> IkarusObjectType {
|
||||
return static_cast<IkarusObjectType>(id >> IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||
}
|
||||
|
||||
TEST_CASE("id_object_type", "[id]") {
|
||||
// NOLINTNEXTLINE(readability-magic-numbers)
|
||||
auto id = static_cast<uint64_t>(IkarusObjectType_Blueprint) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
|
||||
REQUIRE(ikarus_id_get_object_type(id) == IkarusObjectType_Blueprint);
|
||||
}
|
||||
|
||||
TEST_CASE("id_equal", "[id]") {
|
||||
auto id = static_cast<uint64_t>(IkarusObjectType_Blueprint) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
auto copy = id;
|
||||
auto third = static_cast<uint64_t>(IkarusObjectType_Property) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
|
||||
REQUIRE(ikarus_id_is_equal(id, copy));
|
||||
REQUIRE(!ikarus_id_is_equal(id, third));
|
||||
}
|
||||
|
|
|
|||
42
src/id.hpp
42
src/id.hpp
|
|
@ -1,42 +0,0 @@
|
|||
// IMPLEMENTATION_DETAIL_DATABASE
|
||||
|
||||
/// \file id.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
/// \privatesection
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/object_type.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \defgroup id Ids
|
||||
/// \brief Ids are used to identify objects in the database.
|
||||
/// \details They are stored as 64 bit integers with the following layout:
|
||||
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
||||
/// - next 7 bits: #IkarusObjectType
|
||||
/// - last 56 bits: incremented counter generated by the database
|
||||
/// @{
|
||||
|
||||
/// \brief A wrapper around a 64 bit integer that represents the id of an object.
|
||||
/// \details They are stored as 64 bit integers with the following layout:
|
||||
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
||||
/// - next 7 bits: #IkarusObjectType
|
||||
/// - last 56 bits: incremented counter generated by the database
|
||||
using IkarusId = int64_t;
|
||||
|
||||
IKA_API IkarusId ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type);
|
||||
|
||||
/// \brief Fetches the object type of the given id.
|
||||
/// \param id The id to fetch the object type for.
|
||||
/// \return The object type of the given id.
|
||||
IKA_API IkarusObjectType ikarus_id_get_object_type(IkarusId id);
|
||||
|
||||
/// @}
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
|
@ -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;
|
||||
};
|
||||
18
src/persistence/function_context.cpp
Normal file
18
src/persistence/function_context.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "function_context.hpp"
|
||||
|
||||
FunctionContext::FunctionContext(IkarusProject * project):
|
||||
_project{project} {}
|
||||
|
||||
FunctionContext::~FunctionContext() {
|
||||
if (_project->_function_contexts.size() == 1) {
|
||||
if (_project->error_message_buffer.empty()) {
|
||||
_project->error_message_buffer.push_back('\0');
|
||||
} else {
|
||||
_project->error_message_buffer[0] = '\0';
|
||||
}
|
||||
|
||||
_project->error_infos = {};
|
||||
}
|
||||
|
||||
_project->_function_contexts.pop();
|
||||
}
|
||||
53
src/persistence/function_context.hpp
Normal file
53
src/persistence/function_context.hpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <ranges>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
struct FunctionContext {
|
||||
public:
|
||||
explicit FunctionContext(struct IkarusProject * project);
|
||||
|
||||
FunctionContext(FunctionContext const&) noexcept = default;
|
||||
FunctionContext(FunctionContext&&) noexcept = default;
|
||||
|
||||
auto operator=(FunctionContext const&) noexcept -> FunctionContext& = default;
|
||||
auto operator=(FunctionContext&&) noexcept -> FunctionContext& = default;
|
||||
|
||||
~FunctionContext();
|
||||
|
||||
public:
|
||||
template<typename... Infos>
|
||||
requires(std::is_same_v<IkarusErrorInfo, Infos> && ...) && (sizeof...(Infos) <= MAXIMUM_ERROR_INFOS)
|
||||
auto set_error(std::string_view error_message, bool log_error, Infos... infos) -> void {
|
||||
if (error_message.size() > _project->error_message_buffer.size()) {
|
||||
_project->error_message_buffer.resize(error_message.size() + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < error_message.size(); ++i) {
|
||||
_project->error_message_buffer[i] = error_message[i];
|
||||
}
|
||||
|
||||
_project->error_message_buffer[error_message.size()] = '\0';
|
||||
_project->error_infos = {infos...};
|
||||
|
||||
if (log_error) {
|
||||
LOG_ERROR(
|
||||
"Error({}): {}",
|
||||
fmt::join(_project->error_infos | std::views::transform(get_error_info_name), ", "),
|
||||
error_message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct IkarusProject * _project;
|
||||
};
|
||||
49
src/persistence/project.cpp
Normal file
49
src/persistence/project.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include "project.hpp"
|
||||
|
||||
#include "ikarus/persistence/project.h"
|
||||
|
||||
#include <persistence/function_context.hpp>
|
||||
|
||||
auto IkarusProject::get_name() const -> std::string_view {
|
||||
return _name;
|
||||
}
|
||||
|
||||
auto IkarusProject::get_path() const -> std::filesystem::path const& {
|
||||
return _path;
|
||||
}
|
||||
|
||||
auto IkarusProject::get_db() -> sqlitecpp::Connection * {
|
||||
return _db.get();
|
||||
}
|
||||
|
||||
auto IkarusProject::get_db() const -> sqlitecpp::Connection const * {
|
||||
return _db.get();
|
||||
}
|
||||
|
||||
auto IkarusProject::get_function_context() -> FunctionContext * {
|
||||
return &_function_contexts.emplace(this);
|
||||
}
|
||||
|
||||
IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) {
|
||||
return get_cached_object(id, this->_blueprints);
|
||||
}
|
||||
|
||||
auto IkarusProject::uncache_blueprint(IkarusBlueprint * blueprint) -> void {
|
||||
remove_cached_object(blueprint, _blueprints);
|
||||
}
|
||||
|
||||
auto IkarusProject::get_entity(IkarusId id) -> IkarusEntity * {
|
||||
return get_cached_object(id, this->_entities);
|
||||
}
|
||||
|
||||
auto IkarusProject::uncache_entity(IkarusEntity * entity) -> void {
|
||||
remove_cached_object(entity, _entities);
|
||||
}
|
||||
|
||||
auto IkarusProject::get_property(IkarusId id) -> IkarusProperty * {
|
||||
return get_cached_object(id, this->_properties);
|
||||
}
|
||||
|
||||
auto IkarusProject::uncache_property(IkarusProperty * property) -> void {
|
||||
remove_cached_object(property, _properties);
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <filesystem>
|
||||
#include <ranges>
|
||||
#include <stack>
|
||||
|
|
@ -9,83 +8,45 @@
|
|||
#include <sqlitecpp/connection.hpp>
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/id.h>
|
||||
|
||||
constexpr inline size_t MAXIMUM_ERROR_INFOS = 8;
|
||||
constexpr inline size_t MAXIMUM_ERROR_MESSAGE_LENGTH = 256;
|
||||
|
||||
/// \private
|
||||
class FunctionContext {
|
||||
public:
|
||||
explicit FunctionContext(struct IkarusProject * project);
|
||||
FunctionContext(FunctionContext const&) noexcept = default;
|
||||
FunctionContext(FunctionContext&&) noexcept = default;
|
||||
|
||||
auto operator=(FunctionContext const&) noexcept -> FunctionContext& = default;
|
||||
auto operator=(FunctionContext&&) noexcept -> FunctionContext& = default;
|
||||
|
||||
~FunctionContext();
|
||||
|
||||
template<typename... Infos>
|
||||
requires(std::is_same_v<IkarusErrorInfo, Infos> && ...) && (sizeof...(Infos) <= MAXIMUM_ERROR_INFOS)
|
||||
auto set_error(std::string_view error_message, bool log_error, Infos... infos) -> void;
|
||||
|
||||
private:
|
||||
struct IkarusProject * _project;
|
||||
};
|
||||
constexpr inline auto MAXIMUM_ERROR_INFOS = 8;
|
||||
|
||||
/// \private
|
||||
struct IkarusProject {
|
||||
public:
|
||||
[[nodiscard]] inline auto name() const -> std::string_view {
|
||||
return _name;
|
||||
}
|
||||
[[nodiscard]] auto get_name() const -> std::string_view;
|
||||
|
||||
[[nodiscard]] inline auto path() const -> std::filesystem::path const& {
|
||||
return _path;
|
||||
}
|
||||
[[nodiscard]] auto get_path() const -> std::filesystem::path const&;
|
||||
|
||||
[[nodiscard]] inline auto db() -> sqlitecpp::Connection * {
|
||||
return _db.get();
|
||||
}
|
||||
[[nodiscard]] auto get_db() -> sqlitecpp::Connection *;
|
||||
[[nodiscard]] auto get_db() const -> sqlitecpp::Connection const *;
|
||||
|
||||
inline auto function_context() -> FunctionContext * {
|
||||
return &_function_contexts.emplace(this);
|
||||
}
|
||||
public:
|
||||
[[nodiscard]] auto get_function_context() -> struct FunctionContext *;
|
||||
|
||||
[[nodiscard]] IkarusBlueprint * get_blueprint(IkarusId id) {
|
||||
return get_cached_object(id, this->_blueprints);
|
||||
}
|
||||
public:
|
||||
[[nodiscard]] auto get_blueprint(IkarusId id) -> struct IkarusBlueprint *;
|
||||
auto uncache_blueprint(struct IkarusBlueprint * blueprint) -> void;
|
||||
|
||||
auto remove_blueprint(IkarusBlueprint * blueprint) -> void {
|
||||
remove_cached_object(blueprint, _blueprints);
|
||||
}
|
||||
[[nodiscard]] auto get_entity(IkarusId id) -> struct IkarusEntity *;
|
||||
auto uncache_entity(struct IkarusEntity * entity) -> void;
|
||||
|
||||
[[nodiscard]] auto get_entity(IkarusId id) -> IkarusEntity * {
|
||||
return get_cached_object(id, this->_entities);
|
||||
}
|
||||
|
||||
auto remove_entity(IkarusEntity * entity) -> void {
|
||||
remove_cached_object(entity, _entities);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_property(IkarusId id) -> IkarusProperty * {
|
||||
return get_cached_object(id, this->_properties);
|
||||
}
|
||||
|
||||
auto remove_property(IkarusProperty * property) -> void {
|
||||
remove_cached_object(property, _properties);
|
||||
}
|
||||
[[nodiscard]] auto get_property(IkarusId id) -> struct IkarusProperty *;
|
||||
auto uncache_property(struct IkarusProperty * property) -> void;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
[[nodiscard]] T * get_cached_object(IkarusId id, std::unordered_map<IkarusId, std::unique_ptr<T>>& cache) {
|
||||
if (auto iter = cache.find(id); iter == cache.cend()) {
|
||||
auto const iter = cache.find(id);
|
||||
|
||||
if (iter == cache.cend()) {
|
||||
auto [ret_iter, _] = cache.emplace(id, std::make_unique<T>(this, id));
|
||||
|
||||
return ret_iter->second.get();
|
||||
} else {
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
@ -94,7 +55,7 @@ private:
|
|||
}
|
||||
|
||||
private:
|
||||
friend class FunctionContext;
|
||||
friend struct FunctionContext;
|
||||
|
||||
std::string _name;
|
||||
std::filesystem::path _path;
|
||||
|
|
@ -109,41 +70,3 @@ private:
|
|||
|
||||
std::stack<FunctionContext> _function_contexts;
|
||||
};
|
||||
|
||||
FunctionContext::FunctionContext(struct IkarusProject * project):
|
||||
_project{project} {}
|
||||
|
||||
FunctionContext::~FunctionContext() {
|
||||
if (_project->_function_contexts.size() == 1) {
|
||||
if (_project->error_message_buffer.empty()) {
|
||||
_project->error_message_buffer.push_back('\0');
|
||||
} else {
|
||||
_project->error_message_buffer[0] = '\0';
|
||||
}
|
||||
|
||||
_project->error_infos = {};
|
||||
}
|
||||
|
||||
_project->_function_contexts.pop();
|
||||
}
|
||||
|
||||
template<typename... Infos>
|
||||
requires(std::is_same_v<IkarusErrorInfo, Infos> && ...) && (sizeof...(Infos) <= MAXIMUM_ERROR_INFOS)
|
||||
auto FunctionContext::set_error(std::string_view error_message, bool log_error, Infos... infos) -> void {
|
||||
if (error_message.size() > _project->error_message_buffer.size()) {
|
||||
_project->error_message_buffer.resize(error_message.size() + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < error_message.size(); ++i) {
|
||||
_project->error_message_buffer[i] = error_message[i];
|
||||
}
|
||||
|
||||
_project->error_message_buffer[error_message.size()] = '\0';
|
||||
_project->error_infos = {infos...};
|
||||
|
||||
if (log_error) {
|
||||
LOG_ERROR(
|
||||
"Error({}): {}", fmt::join(_project->error_infos | std::views::transform(get_error_info_name), ", "), error_message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue