add flatbuffers support and initial rewrite

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2024-05-12 14:15:42 +02:00 committed by Folling
parent 7e883d24eb
commit 98cb7a44ef
No known key found for this signature in database
72 changed files with 3929 additions and 1403 deletions

View file

@ -6,18 +6,12 @@
#include <ikarus/errors.h>
#include <ikarus/errors.hpp>
#include <ikarus/objects/blueprint.hpp>
#include <ikarus/objects/entity.hpp>
#include <ikarus/objects/object.hpp>
#include <ikarus/objects/properties/property.h>
#include <ikarus/objects/properties/property.hpp>
#include <ikarus/objects/properties/property_scope.hpp>
#include <ikarus/persistence/project.hpp>
namespace ikarus::util {
template<typename O>
[[nodiscard]] IkarusId object_get_id(O const * object, IkarusErrorData * error_out) {
[[nodiscard]] int64_t object_get_id(O const * object, IkarusErrorData * error_out) {
IKARUS_FAIL_IF_NULL(object, 0);
IKARUS_FAIL_IF_OBJECT_MISSING(object, 0);
@ -49,81 +43,14 @@ template<typename O>
return strdup(ret.data());
}
[[nodiscard]] inline bool name_is_unique(
IkarusProject const * project,
std::string_view name,
[[maybe_unused]] IkarusBlueprint const * blueprint,
IkarusErrorData * error_out
) {
IKARUS_VTRYRV_OR_FAIL(
bool const exists,
false,
"unable to check if blueprint name is unique",
IkarusErrorInfo_Database_QueryFailed,
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `blueprints` WHERE `name` = ?)", name)
);
return !exists;
}
[[nodiscard]] inline bool name_is_unique(
IkarusProject const * project,
std::string_view name,
[[maybe_unused]] IkarusEntity const * entity,
IkarusErrorData * error_out
) {
IKARUS_VTRYRV_OR_FAIL(
bool const exists,
false,
"unable to check if entity name is unique",
IkarusErrorInfo_Database_QueryFailed,
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `entities` WHERE `name` = ?)", name)
);
return !exists;
}
[[nodiscard]] inline bool
name_is_unique(IkarusProject const * project, std::string_view name, IkarusPropertyScope const * scope, IkarusErrorData * error_out) {
IKARUS_VTRYRV_OR_FAIL(
bool const exists,
false,
"unable to check if property name is unique",
IkarusErrorInfo_Database_QueryFailed,
project->db->query_one<bool>("SELECT EXISTS(SELECT 1 FROM `properties` WHERE `name` = ? AND `scope` = ?)", name, scope->get_id())
);
return !exists;
}
[[nodiscard]] inline bool
name_is_unique(IkarusProject const * project, std::string_view name, IkarusProperty const * property, IkarusErrorData * error_out) {
std::unique_ptr<IkarusPropertyScope const> scope{ikarus_property_get_scope(property, error_out)};
IKARUS_FAIL_IF_ERROR(false);
return name_is_unique(project, name, scope.get(), error_out);
}
#define IKARUS_FAIL_IF_NAME_INVALID(name, ret) \
IKARUS_FAIL_IF_NULL(name, ret); \
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), ret, "name must not be empty", IkarusErrorInfo_Client_InvalidInput);
#define IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, project, object, ret, ...) \
IKARUS_FAIL_IF_NAME_INVALID(name, ret); \
IKARUS_FAIL_IF( \
!ikarus::util::name_is_unique(project, name, object, error_out), \
ret, \
"name must be unique", \
IkarusErrorInfo_Client_InvalidInput \
); \
IKARUS_FAIL_IF_ERROR(ret);
#define IKARUS_FAIL_IF_NAME_INVALID(name, ret) IKARUS_FAIL_IF_NULL(name, ret);
template<typename O>
void object_set_name(O * object, char const * name, IkarusErrorData * error_out) {
IKARUS_FAIL_IF_NULL(object, );
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
IKARUS_FAIL_IF_NULL(name, );
IKARUS_FAIL_IF_NAME_INVALID_OR_DUPLICATE(name, object->project, object, );
IKARUS_FAIL_IF_NAME_INVALID(name, );
IKARUS_TRYRV_OR_FAIL(
,