update sqlitecpp & merge property settings into properties

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
folling 2023-11-27 11:24:55 +01:00 committed by Folling
parent ff9bf0c14a
commit 88ca7769d1
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
39 changed files with 412 additions and 253 deletions

View file

@ -57,7 +57,7 @@ enum IkarusErrorInfo {
/// Example: A query takes longer than the timeout.
IkarusErrorInfo_Type_LibIkarus_Timeout = 0x0002000300000003,
/// \brief The type of error is unknown.
IkarusErrorInfo_Type_Unknown = 0xFFFFFFFF,
IkarusErrorInfo_Type_Unknown = 0xFFFFFFFFFFFFFFFF,
};
/// \brief Gets the name of an error info.

View file

@ -5,7 +5,7 @@
#include <ikarus/macros.h>
/// \addtogroup global Global
/// \defgroup global Global
/// \brief Information relevant to the entire library.
/// @{

View file

@ -8,12 +8,9 @@
/// \defgroup object Objects
/// \brief Objects are a compound type of all types of objects in the database.
/// \details The following objects currently exist:
/// - blueprints
/// - properties
/// - entities
/// - blueprint folders
/// - property folders
/// - entity folders
/// - \ref blueprint.h "Blueprints"
/// - \ref property.h "Properties"
/// - \ref entity.h "Entities"
/// @{
IKARUS_BEGIN_HEADER
@ -21,6 +18,16 @@ IKARUS_BEGIN_HEADER
/// \brief A generic object. Wraps all types of objects, including folders.
struct IkarusObject;
/// \brief Compares two objects for equality.
/// \details This neither compares the pointers nor does a deep copy. Instead it figures out if the objects _are_ the same
/// object.
/// \param lhs The left hand side object.
/// \pre \li Must not be null.
/// \param rhs The right hand side object.
/// \pre \li Must not be null.
/// \return True if the objects are equal, false otherwise.
IKA_API bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const * rhs);
/// \brief Visits an object. Calling the appropriate function for the object's type.
/// \param object The object to visit.
/// \param blueprint_visitor The function to call if the object is a blueprint. Skipped if null.
@ -55,4 +62,4 @@ IKA_API void ikarus_object_visit_const(
IKARUS_END_HEADER
// @}
/// @}

View file

@ -14,10 +14,27 @@ IKARUS_BEGIN_HEADER
struct IkarusNumberProperty;
IKA_API IkarusNumberProperty * ikarus_number_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusNumberSettings * settings
struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source
);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \remark The settings take ownership of the value, the caller must not free it.
IKA_API struct IkarusNumberValue * ikarus_number_property_get_default_value(struct IkarusNumberProperty * property);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between default values
/// and other settings.
IKA_API void ikarus_number_property_set_default_value(
struct IkarusNumberProperty * property, struct IkarusNumberValue * default_value
);
IKARUS_END_HEADER

View file

@ -29,8 +29,12 @@ IKARUS_BEGIN_HEADER
///
/// Every property has settings which can be used to customise the property further.
/// Two settings that are shared among all properties are the following:
/// - Multiple
/// - Allow undefined
/// - List
/// - May be undefined
///
/// Additionally, each property has a default value. If no default value is provided, a sensible default is chosen.
/// Setting a default value that isn't valid for the property is an error. Changing settings so that the current default value
/// becomes invalid is valid but unsets the custom default value.
///
/// The former transforms a property into a list. Instead of one number, you could then specify a series of numbers.
/// The latter allows you to specify an "unknown" value for a property.
@ -43,6 +47,7 @@ IKARUS_BEGIN_HEADER
///
/// We call properties within entities "Entity Properties" and properties within blueprints "Blueprint Properties".
///
///
/// \remark Properties are scoped to the blueprint or entity they are associated with.
/// \remark Values for properties are lazily created as space saving measure.
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
@ -65,17 +70,6 @@ IKA_API void ikarus_property_delete(IkarusProperty * property);
/// \remark Must be freed using #ikarus_free.
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property);
/// \brief Gets the settings of a property.
/// \param property The property to get the settings of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \return The settings of the property or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertySettings * ikarus_property_get_settings(IkarusProperty * property);
/// \see ikarus_property_get_settings
IKA_API struct IkarusPropertySettings const * ikarus_property_get_settings_const(IkarusProperty const * property);
/// \brief Gets the source of a property.
/// \param property The property to get the source of.
/// \pre \li Must not be null.

View file

@ -22,12 +22,6 @@ enum IkarusPropertyType {
IkarusPropertyType_Text,
};
/// \brief Fetches the default value for a property type.
/// \remark Not to be confused with the default value of a property. See ikarus_property_get_default_value
/// \param type The property type.
/// \return The default value for the property type or null if an error occurs.
IKA_API struct IkarusValue * ikarus_property_type_get_default_default_value(IkarusPropertyType type);
IKARUS_END_HEADER
/// @}

View file

@ -14,10 +14,27 @@ IKARUS_BEGIN_HEADER
struct IkarusTextProperty;
IKA_API IkarusTextProperty * ikarus_text_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusTextSettings * settings
struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source
);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \remark The settings take ownership of the value, the caller must not free it.
IKA_API struct IkarusTextValue * ikarus_text_property_get_default_value(struct IkarusTextProperty * property);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between default values
/// and other settings.
IKA_API void ikarus_text_property_set_default_value(
struct IkarusTextProperty * property, struct IkarusTextValue * default_value
);
IKARUS_END_HEADER

View file

@ -14,10 +14,27 @@ IKARUS_BEGIN_HEADER
struct IkarusToggleProperty;
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusToggleSettings * settings
struct IkarusProject * project, char const * name, struct IkarusPropertySource * property_source
);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \remark The settings take ownership of the value, the caller must not free it.
IKA_API struct IkarusToggleValue * ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between default values
/// and other settings.
IKA_API void ikarus_toggle_property_set_default_value(
struct IkarusToggleProperty * property, struct IkarusToggleValue * default_value
);
IKARUS_END_HEADER

View file

@ -5,7 +5,7 @@
#include <ikarus/macros.h>
/// \addtogroup entity_value Entity Values
/// \addtogroup values Values
/// @{
IKARUS_BEGIN_HEADER
@ -42,3 +42,5 @@ IKA_API void ikarus_number_value_set(IkarusNumberValue * value, bool new_value);
IKA_API struct IkarusValue * ikarus_number_value_to_value(IkarusNumberValue * number_value);
IKARUS_END_HEADER
/// @}

View file

@ -5,7 +5,7 @@
#include <ikarus/macros.h>
/// \addtogroup entity_value Entity Values
/// \addtogroup values Values
/// @{
IKARUS_BEGIN_HEADER
@ -43,3 +43,5 @@ IKA_API void ikarus_text_value_set(IkarusTextValue * value, bool new_value);
IKA_API struct IkarusValue * ikarus_text_value_to_value(IkarusTextValue * text_value);
IKARUS_END_HEADER
/// @}

View file

@ -5,7 +5,7 @@
#include <ikarus/macros.h>
/// \addtogroup entity_value Entity Values
/// \addtogroup values Values
/// @{
IKARUS_BEGIN_HEADER
@ -42,3 +42,5 @@ IKA_API void ikarus_toggle_value_set(IkarusToggleValue * value, bool new_value);
IKA_API struct IkarusValue * ikarus_toggle_value_to_value(IkarusToggleValue * toggle_value);
IKARUS_END_HEADER
/// @}

View file

@ -5,7 +5,7 @@
#include <ikarus/macros.h>
/// \defgroup entity_value Entity Values
/// \defgroup values Values
/// \brief The values stored in entities.
/// \details Each entity has a value for each property it is associated with.
/// The value is of the type specified by the property and constrained by the property's settings.

View file

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

View file

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

View file

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

View file

@ -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
View file

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

View file

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

View file

@ -0,0 +1,5 @@
//
// Created by Jonathan Purol on 26.11.23.
//
export module number_property.hpp;

View file

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

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

View file

View 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

View file

@ -0,0 +1,7 @@
#pragma once
#include <objects/properties/property.hpp>
struct IkarusToggleProperty final : IkarusProperty {
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
};

View file

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

View file

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

View file

@ -1,10 +0,0 @@
#pragma once
#include <variant>
#include <ikarus/objects/properties/property_source.h>
/// \private
struct IkarusPropertySource {
std::variant<IkarusBlueprint *, IkarusEntity *> data;
};

View 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();
}

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

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

View file

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

2
vendor/sqlitecpp vendored

@ -1 +1 @@
Subproject commit 3057656ff277294ab424af90e553e630c2a5e8f7
Subproject commit 538616d8ced2d3f04659261ccae3b039d65da004