change error system & function signatures

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2024-01-02 15:14:39 +01:00 committed by Folling
parent 1367373819
commit e1bf97704a
No known key found for this signature in database
28 changed files with 633 additions and 651 deletions

View file

@ -1,18 +0,0 @@
#include "function_context.hpp"
IkarusFunctionContext::IkarusFunctionContext(IkarusProject * project):
_project{project} {}
IkarusFunctionContext::~IkarusFunctionContext() {
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_back();
}

View file

@ -1,49 +0,0 @@
#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 IkarusFunctionContext {
public:
explicit IkarusFunctionContext(struct IkarusProject * project);
IkarusFunctionContext(IkarusFunctionContext const &) noexcept = default;
IkarusFunctionContext(IkarusFunctionContext &&) noexcept = default;
auto operator=(IkarusFunctionContext const &) noexcept -> IkarusFunctionContext & = default;
auto operator=(IkarusFunctionContext &&) noexcept -> IkarusFunctionContext & = default;
~IkarusFunctionContext();
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

@ -8,27 +8,14 @@
#include <objects/properties/property.hpp>
#include <objects/properties/text_property.hpp>
#include <objects/properties/toggle_property.hpp>
#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() -> IkarusFunctionContext * {
return &_function_contexts.emplace_back(this);
}
IkarusProject::IkarusProject(std::string_view name, std::filesystem::path path):
name{name},
path{path},
db{nullptr},
_blueprints{},
_properties{},
_entities{} {}
IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) {
return get_cached_object<IkarusBlueprint>(id, this->_blueprints);

View file

@ -11,20 +11,10 @@
#include <ikarus/id.h>
#include <ikarus/objects/properties/property_type.h>
constexpr inline auto MAXIMUM_ERROR_INFOS = 8;
/// \private
struct IkarusProject {
public:
[[nodiscard]] auto get_name() const -> std::string_view;
[[nodiscard]] auto get_path() const -> std::filesystem::path const &;
[[nodiscard]] auto get_db() -> sqlitecpp::Connection *;
[[nodiscard]] auto get_db() const -> sqlitecpp::Connection const *;
public:
[[nodiscard]] auto get_function_context() -> struct IkarusFunctionContext *;
IkarusProject(std::string_view name, std::filesystem::path path);
public:
[[nodiscard]] auto get_blueprint(IkarusId id) -> struct IkarusBlueprint *;
@ -53,19 +43,13 @@ private:
cache.erase(object->id);
}
public:
std::string name;
std::filesystem::path path;
std::unique_ptr<sqlitecpp::Connection> db;
private:
friend struct IkarusFunctionContext;
std::string _name;
std::filesystem::path _path;
std::unique_ptr<sqlitecpp::Connection> _db;
std::array<IkarusErrorInfo, MAXIMUM_ERROR_INFOS> error_infos;
std::string error_message_buffer;
std::unordered_map<IkarusId, std::unique_ptr<IkarusBlueprint>> _blueprints;
std::unordered_map<IkarusId, std::unique_ptr<IkarusProperty>> _properties;
std::unordered_map<IkarusId, std::unique_ptr<IkarusEntity>> _entities;
std::vector<IkarusFunctionContext> _function_contexts;
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusBlueprint>> _blueprints;
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusProperty>> _properties;
std::unordered_map<IkarusId, std::unique_ptr<struct IkarusEntity>> _entities;
};