add src/ikarus subdir and make names unique for objects per scope

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
folling 2024-01-30 09:31:08 +01:00 committed by Folling
parent ced123b628
commit 9f943cc6a2
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
51 changed files with 590 additions and 735 deletions

View file

@ -1,76 +0,0 @@
#pragma once
#include <boost/json.hpp>
#include <boost/variant2.hpp>
#include <cppbase/result.hpp>
#include <errors.hpp>
#include <persistence/project.hpp>
struct IkarusValue {
public:
using Data = boost::variant2::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *>;
constexpr static auto SMALL_VEC_VALUE_SIZE = 8;
public:
explicit IkarusValue(Data data);
IkarusValue(IkarusValue const &) = default;
IkarusValue(IkarusValue &&) noexcept = default;
IkarusValue & operator=(IkarusValue const &) = default;
IkarusValue & operator=(IkarusValue &&) noexcept = default;
virtual ~IkarusValue() = default;
public:
struct FromJsonError {};
[[nodiscard]] static cppbase::Result<IkarusValue *, FromJsonError> from_json(boost::json::value json);
[[nodiscard]] boost::json::value to_json() const;
public:
Data data;
};
template<>
struct fmt::formatter<IkarusValue::FromJsonError> {
template<typename FormatParseContext>
constexpr static auto parse(FormatParseContext & ctx) {
return ctx.end();
}
constexpr static auto format([[maybe_unused]]IkarusValue::FromJsonError const & error, fmt::format_context & ctx) {
return fmt::format_to(ctx.out(), "unable to parse ikarus value JSON");
}
};
template<typename... Args>
IkarusValue * fetch_value_from_db(IkarusProject * project, IkarusErrorData * error_out, std::string_view query, Args &&... args) {
IKARUS_VTRYRV_OR_FAIL(
auto const value_str,
nullptr,
"unable to fetch entity property value from database: {}",
IkarusErrorInfo_Database_QueryFailed,
project->db->query_one<std::string>(query, std::forward<Args>(args)...)
);
boost::json::error_code ec{};
boost::json::value json_value = boost::json::parse(value_str, ec);
if (ec) {
IKARUS_SET_ERROR(fmt::format("invalid json is stored in database: {}", ec.message()), IkarusErrorInfo_Database_InvalidState);
return nullptr;
}
IKARUS_VTRYRV_OR_FAIL(
auto const ret,
nullptr,
"unable to fetch entity property value: {}",
IkarusErrorInfo_LibIkarus_CannotPerformOperation,
IkarusValue::from_json(std::move(json_value))
);
return ret;
}