72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <ranges>
|
|
#include <stack>
|
|
#include <string>
|
|
|
|
#include <sqlitecpp/connection.hpp>
|
|
|
|
#include <ikarus/errors.h>
|
|
#include <ikarus/id.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 FunctionContext *;
|
|
|
|
public:
|
|
[[nodiscard]] auto get_blueprint(IkarusId id) -> struct IkarusBlueprint *;
|
|
auto uncache_blueprint(struct IkarusBlueprint * blueprint) -> void;
|
|
|
|
[[nodiscard]] auto get_entity(IkarusId id) -> struct IkarusEntity *;
|
|
auto uncache_entity(struct IkarusEntity * entity) -> void;
|
|
|
|
[[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) {
|
|
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();
|
|
}
|
|
|
|
return iter->second.get();
|
|
}
|
|
|
|
template<typename T>
|
|
void remove_cached_object(T * object, std::unordered_map<IkarusId, std::unique_ptr<T>>& cache) {
|
|
cache.erase(object->id);
|
|
}
|
|
|
|
private:
|
|
friend struct FunctionContext;
|
|
|
|
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::stack<FunctionContext> _function_contexts;
|
|
};
|