fixup compile errors and allow fetching property properly from cache
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
92d97861e6
commit
78a15b759d
21 changed files with 213 additions and 122 deletions
|
|
@ -15,11 +15,11 @@ enum IkarusObjectType {
|
|||
/// \brief Not an object or no object.
|
||||
IkarusObjectType_None = 0,
|
||||
/// \brief An IkarusEntity.
|
||||
IkarusObjectType_Entity = 0b00000011,
|
||||
/// \brief An IkarusProperty.
|
||||
IkarusObjectType_Property = 0b00000010,
|
||||
IkarusObjectType_Entity = 0b00000001,
|
||||
/// \brief An IkarusBlueprint.
|
||||
IkarusObjectType_Blueprint = 0b00000001,
|
||||
IkarusObjectType_Blueprint = 0b00000010,
|
||||
/// \brief An IkarusProperty.
|
||||
IkarusObjectType_Property = 0b00000011,
|
||||
};
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
|||
/// \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.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ IKA_API IkarusTextProperty * ikarus_text_property_create(
|
|||
/// \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.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
|||
/// \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.
|
||||
|
|
|
|||
|
|
@ -17,25 +17,15 @@ IkarusBlueprint::IkarusBlueprint(IkarusProject * project, IkarusId id):
|
|||
IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char const * name) {
|
||||
LOG_INFO("creating new blueprint");
|
||||
|
||||
if (project == nullptr) {
|
||||
LOG_ERROR("project is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
auto * ctx = project->get_function_context();
|
||||
|
||||
if (name == nullptr) {
|
||||
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (cppbase::is_empty_or_blank(name)) {
|
||||
ctx->set_error("name is empty or blank", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LOG_DEBUG("project={}; name={}", project->get_path().c_str(), name);
|
||||
|
||||
VTRYRV(
|
||||
auto const id,
|
||||
nullptr,
|
||||
|
|
@ -77,15 +67,10 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
|||
void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
||||
LOG_INFO("deleting blueprint");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id());
|
||||
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
blueprint->get_project()
|
||||
|
|
@ -101,7 +86,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
})
|
||||
);
|
||||
|
||||
LOG_VERBOSE("blueprint was successfully deleted from database, freeing blueprint");
|
||||
LOG_VERBOSE("blueprint was successfully deleted from database, freeing");
|
||||
|
||||
blueprint->get_project()->uncache_blueprint(blueprint);
|
||||
|
||||
|
|
@ -111,11 +96,6 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
|||
size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
||||
LOG_VERBOSE("fetching blueprint property count");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
|
@ -148,20 +128,15 @@ void ikarus_blueprint_get_properties(
|
|||
) {
|
||||
LOG_VERBOSE("fetching blueprint properties");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG(
|
||||
"project={};blueprint={};properties_out_size={}",
|
||||
blueprint->get_project()->get_path().c_str(),
|
||||
blueprint->get_id(),
|
||||
properties_out_size
|
||||
);
|
||||
|
||||
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->get_id(), properties_out_size);
|
||||
|
||||
IkarusId ids[properties_out_size];
|
||||
|
||||
TRYRV(
|
||||
|
|
@ -187,8 +162,23 @@ void ikarus_blueprint_get_properties(
|
|||
LOG_DEBUG("blueprint properties: [{}]", fmt::join(ids, ids + properties_out_size, ", "));
|
||||
|
||||
for (size_t i = 0; i < properties_out_size; ++i) {
|
||||
auto const id = ids[i];
|
||||
|
||||
VTRYRV(
|
||||
auto const type,
|
||||
,
|
||||
IkarusProperty::get_property_type(blueprint->get_project(), id).on_error([ctx, id](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to fetch property {}'s type: {}", id, err),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
properties_out[i] = blueprint->get_project()->get_property(ids[i]);
|
||||
properties_out[i] = blueprint->get_project()->get_property(id, type);
|
||||
}
|
||||
|
||||
LOG_VERBOSE("successfully fetched blueprint properties");
|
||||
|
|
@ -197,15 +187,10 @@ void ikarus_blueprint_get_properties(
|
|||
size_t ikarus_blueprint_get_linked_entity_count(IkarusBlueprint const * blueprint) {
|
||||
LOG_VERBOSE("fetching blueprint linked entity count");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return 0;
|
||||
}
|
||||
LOG_DEBUG("project={};blueprint={}", blueprint->get_project()->get_path().c_str(), blueprint->get_id());
|
||||
|
||||
auto * ctx = blueprint->get_project()->get_function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
VTRYRV(
|
||||
auto count,
|
||||
0,
|
||||
|
|
@ -234,20 +219,15 @@ void ikarus_blueprint_get_linked_entities(
|
|||
) {
|
||||
LOG_VERBOSE("fetching blueprint linked entities");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return;
|
||||
}
|
||||
LOG_DEBUG(
|
||||
"project={};blueprint={};entities_out_size={}",
|
||||
blueprint->get_project()->get_path().c_str(),
|
||||
blueprint->get_id(),
|
||||
entities_out_size
|
||||
);
|
||||
|
||||
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->get_id(), entities_out_size);
|
||||
|
||||
IkarusId ids[entities_out_size];
|
||||
|
||||
TRYRV(
|
||||
|
|
@ -281,22 +261,9 @@ void ikarus_blueprint_get_linked_entities(
|
|||
}
|
||||
|
||||
IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint) {
|
||||
return const_cast<IkarusObject *>(ikarus_blueprint_to_object_const(blueprint));
|
||||
return static_cast<IkarusObject *>(blueprint);
|
||||
}
|
||||
|
||||
IkarusObject const * ikarus_blueprint_to_object_const(IkarusBlueprint const * blueprint) {
|
||||
LOG_VERBOSE("casting blueprint to object");
|
||||
|
||||
if (blueprint == nullptr) {
|
||||
LOG_ERROR("blueprint is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// auto * ctx = blueprint->project->function_context();
|
||||
|
||||
LOG_DEBUG("blueprint={}", blueprint->get_id());
|
||||
|
||||
LOG_VERBOSE("successfully casted blueprint to object");
|
||||
|
||||
return static_cast<IkarusObject const *>(blueprint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <objects/object.hpp>
|
||||
|
||||
struct IkarusBlueprint final : IkarusObject {
|
||||
inline IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||
IkarusBlueprint(struct IkarusProject * project, IkarusId id);
|
||||
|
||||
IkarusBlueprint(IkarusBlueprint const&) = default;
|
||||
IkarusBlueprint(IkarusBlueprint&&) = default;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#include "object.hpp"
|
||||
|
||||
IkarusObject::IkarusObject(IkarusProject * project, IkarusId id):
|
||||
_project{project},
|
||||
_id{id} {}
|
||||
|
||||
IkarusProject * IkarusObject::get_project() {
|
||||
return _project;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ public:
|
|||
virtual ~IkarusObject() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] inline struct IkarusProject * get_project();
|
||||
[[nodiscard]] struct IkarusProject * get_project();
|
||||
|
||||
[[nodiscard]] inline struct IkarusProject * get_project() const;
|
||||
[[nodiscard]] struct IkarusProject * get_project() const;
|
||||
|
||||
[[nodiscard]] inline IkarusId get_id() const;
|
||||
[[nodiscard]] IkarusId get_id() const;
|
||||
|
||||
private:
|
||||
struct IkarusProject mutable * _project;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#include "number_property.hpp"
|
||||
|
||||
IkarusNumberProperty::IkarusNumberProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
export module number_property.hpp;
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
struct IkarusNumberProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusNumberProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
#include "property.hpp"
|
||||
|
||||
#include <cppbase/logger.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <persistence/function_context.hpp>
|
||||
#include <persistence/project.hpp>
|
||||
|
||||
IkarusProperty::IkarusProperty(IkarusProject * project, IkarusId id, Data data):
|
||||
IkarusObject{project, id},
|
||||
_data{data} {}
|
||||
|
||||
cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> IkarusProperty::get_property_type(
|
||||
IkarusProject * project, IkarusId id
|
||||
) {
|
||||
LOG_DEBUG("fetching unboxed property type");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", project->get_path().c_str(), id);
|
||||
|
||||
VTRY(auto const type, project->get_db()->query_one<int>("SELECT `type` FROM `objects` WHERE `id` = ?", id));
|
||||
|
||||
return cppbase::ok(static_cast<IkarusPropertyType>(type));
|
||||
}
|
||||
|
||||
IKA_API void ikarus_property_delete(IkarusProperty * property) {
|
||||
LOG_INFO("deleting property");
|
||||
|
||||
LOG_VERBOSE("project={};property={}", property->get_project()->get_path().c_str(), property->get_id());
|
||||
|
||||
auto * ctx = property->get_project()->get_function_context();
|
||||
|
||||
TRYRV(
|
||||
,
|
||||
property->get_project()
|
||||
->get_db()
|
||||
->execute("DELETE FROM `objects` WHERE `id` = ?", property->get_id())
|
||||
.on_error([ctx](auto const& err) {
|
||||
ctx->set_error(
|
||||
fmt::format("failed to delete property from objects table: {}", err),
|
||||
true,
|
||||
IkarusErrorInfo_Source_SubSystem,
|
||||
IkarusErrorInfo_Type_SubSystem_Database
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
LOG_VERBOSE("property was successfully deleted from database, freeing");
|
||||
|
||||
property->get_project()->uncache_property(property);
|
||||
|
||||
LOG_VERBOSE("successfully deleted property");
|
||||
}
|
||||
|
||||
IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property) {
|
||||
LOG_DEBUG("fetching property type");
|
||||
}
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <cppbase/result.hpp>
|
||||
|
||||
#include <sqlitecpp/errors.hpp>
|
||||
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <objects/object.hpp>
|
||||
|
||||
struct IkarusProperty : IkarusObject {
|
||||
IkarusProperty(struct IkarusProject * project, IkarusId id);
|
||||
public:
|
||||
using Data = std::variant<struct IkarusToggleProperty *, struct IkarusNumberProperty *, struct IkarusTextProperty *>;
|
||||
|
||||
public:
|
||||
/// \brief Helper to fetch a type for a property that isn't yet wrapped in an object
|
||||
[[nodiscard]] static cppbase::Result<IkarusPropertyType, sqlitecpp::SingleQueryError> get_property_type(
|
||||
struct IkarusProject * project, IkarusId id
|
||||
);
|
||||
|
||||
public:
|
||||
IkarusProperty(struct IkarusProject * project, IkarusId id, Data data);
|
||||
|
||||
IkarusProperty(IkarusProperty const&) = default;
|
||||
IkarusProperty(IkarusProperty&&) = default;
|
||||
|
|
@ -12,4 +30,7 @@ struct IkarusProperty : IkarusObject {
|
|||
IkarusProperty& operator=(IkarusProperty&&) = default;
|
||||
|
||||
~IkarusProperty() override = default;
|
||||
|
||||
private:
|
||||
Data _data;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#include "text_property.hpp"
|
||||
|
||||
IkarusTextProperty::IkarusTextProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
//
|
||||
// Created by Jonathan Purol on 26.11.23.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef TEXT_PROPERTY_HPP
|
||||
#define TEXT_PROPERTY_HPP
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
#endif //TEXT_PROPERTY_HPP
|
||||
struct IkarusTextProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusTextProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
#include "toggle_property.hpp"
|
||||
|
||||
IkarusToggleProperty::IkarusToggleProperty(IkarusProject * project, IkarusId id):
|
||||
IkarusProperty{project, id, this} {
|
||||
|
||||
}
|
||||
|
|
@ -3,5 +3,6 @@
|
|||
#include <objects/properties/property.hpp>
|
||||
|
||||
struct IkarusToggleProperty final : IkarusProperty {
|
||||
public:
|
||||
IkarusToggleProperty(struct IkarusProject * project, IkarusId id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@ FunctionContext::~FunctionContext() {
|
|||
_project->error_infos = {};
|
||||
}
|
||||
|
||||
_project->_function_contexts.pop();
|
||||
_project->_function_contexts.pop_back();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#include "ikarus/persistence/project.h"
|
||||
|
||||
#include <objects/properties/number_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 {
|
||||
|
|
@ -21,11 +24,11 @@ auto IkarusProject::get_db() const -> sqlitecpp::Connection const * {
|
|||
}
|
||||
|
||||
auto IkarusProject::get_function_context() -> FunctionContext * {
|
||||
return &_function_contexts.emplace(this);
|
||||
return &_function_contexts.emplace_back(this);
|
||||
}
|
||||
|
||||
IkarusBlueprint * IkarusProject::get_blueprint(IkarusId id) {
|
||||
return get_cached_object(id, this->_blueprints);
|
||||
return get_cached_object<IkarusBlueprint>(id, this->_blueprints);
|
||||
}
|
||||
|
||||
auto IkarusProject::uncache_blueprint(IkarusBlueprint * blueprint) -> void {
|
||||
|
|
@ -33,15 +36,28 @@ auto IkarusProject::uncache_blueprint(IkarusBlueprint * blueprint) -> void {
|
|||
}
|
||||
|
||||
auto IkarusProject::get_entity(IkarusId id) -> IkarusEntity * {
|
||||
return get_cached_object(id, this->_entities);
|
||||
return get_cached_object<IkarusEntity>(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::get_property(IkarusId id, IkarusPropertyType type) -> IkarusProperty * {
|
||||
auto const iter = _properties.find(id);
|
||||
|
||||
if (iter == _properties.cend()) {
|
||||
switch (type) {
|
||||
case IkarusPropertyType_Toggle:
|
||||
return _properties.emplace(id, std::make_unique<IkarusToggleProperty>(this, id)).first->second.get();
|
||||
case IkarusPropertyType_Number:
|
||||
return _properties.emplace(id, std::make_unique<IkarusNumberProperty>(this, id)).first->second.get();
|
||||
case IkarusPropertyType_Text:
|
||||
return _properties.emplace(id, std::make_unique<IkarusTextProperty>(this, id)).first->second.get();
|
||||
}
|
||||
}
|
||||
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
auto IkarusProject::uncache_property(IkarusProperty * property) -> void {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@
|
|||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/id.h>
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/properties/property.hpp>
|
||||
|
||||
constexpr inline auto MAXIMUM_ERROR_INFOS = 8;
|
||||
|
||||
|
|
@ -32,18 +37,16 @@ public:
|
|||
[[nodiscard]] auto get_entity(IkarusId id) -> struct IkarusEntity *;
|
||||
auto uncache_entity(struct IkarusEntity * entity) -> void;
|
||||
|
||||
[[nodiscard]] auto get_property(IkarusId id) -> struct IkarusProperty *;
|
||||
[[nodiscard]] auto get_property(IkarusId id, IkarusPropertyType type) -> 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) {
|
||||
[[nodiscard]] T * get_cached_object(IkarusId id, auto& 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 cache.emplace(id, std::make_unique<T>(this, id)).first->second.get();
|
||||
}
|
||||
|
||||
return iter->second.get();
|
||||
|
|
@ -51,7 +54,7 @@ private:
|
|||
|
||||
template<typename T>
|
||||
void remove_cached_object(T * object, std::unordered_map<IkarusId, std::unique_ptr<T>>& cache) {
|
||||
cache.erase(object->id);
|
||||
cache.erase(object->get_id());
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -68,5 +71,5 @@ private:
|
|||
std::unordered_map<IkarusId, std::unique_ptr<IkarusProperty>> _properties;
|
||||
std::unordered_map<IkarusId, std::unique_ptr<IkarusEntity>> _entities;
|
||||
|
||||
std::stack<FunctionContext> _function_contexts;
|
||||
std::vector<FunctionContext> _function_contexts;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,25 @@
|
|||
#include <values/toggle_value.hpp>
|
||||
#include <values/value.hpp>
|
||||
|
||||
IkarusValue::IkarusValue(Data data):
|
||||
_data(data) {}
|
||||
|
||||
bool IkarusValue::is_interminate() const {
|
||||
return _indeterminate;
|
||||
}
|
||||
|
||||
void IkarusValue::set_intermediate(bool value) {
|
||||
_indeterminate = value;
|
||||
}
|
||||
|
||||
IkarusValue::Data& IkarusValue::get_data() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
IkarusValue::Data const& IkarusValue::get_data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool ikarus_value_is_indeterminate(IkarusValue const * value) {
|
||||
return value->is_interminate();
|
||||
}
|
||||
|
|
@ -20,9 +39,9 @@ void ikarus_value_set_indeterminate(IkarusValue * value, bool indeterminate) {
|
|||
char const * ikarus_value_to_string(IkarusValue const * value) {
|
||||
auto const str = std::visit(
|
||||
cppbase::overloaded{
|
||||
[](IkarusToggleValue const * toggle_value) -> std::string { return toggle_value->value ? "true" : "false"; },
|
||||
[](IkarusNumberValue const * number_value) -> std::string { return fmt::format("{}", number_value->value); },
|
||||
[](IkarusTextValue const * text_value) -> std::string { return fmt::format("{}", text_value->value); },
|
||||
[](IkarusToggleValue const * toggle_value) -> std::string { return toggle_value->get_value() ? "true" : "false"; },
|
||||
[](IkarusNumberValue const * number_value) -> std::string { return fmt::format("{}", number_value->get_value()); },
|
||||
[](IkarusTextValue const * text_value) -> std::string { return fmt::format("{}", text_value->get_value()); },
|
||||
},
|
||||
value->get_data()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
|
||||
struct IkarusValue {
|
||||
public:
|
||||
using Data = std::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *>::variant;
|
||||
using Data = std::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *>;
|
||||
|
||||
public:
|
||||
explicit IkarusValue(Data data):
|
||||
_data(data) {}
|
||||
explicit IkarusValue(Data data);
|
||||
|
||||
IkarusValue(IkarusValue const&) = default;
|
||||
IkarusValue(IkarusValue&&) noexcept = default;
|
||||
|
|
@ -16,24 +15,14 @@ public:
|
|||
IkarusValue& operator=(IkarusValue const&) = default;
|
||||
IkarusValue& operator=(IkarusValue&&) noexcept = default;
|
||||
|
||||
virtual ~IkarusValue();
|
||||
virtual ~IkarusValue() = default;
|
||||
|
||||
public:
|
||||
[[nodiscard]] inline bool is_interminate() const {
|
||||
return _indeterminate;
|
||||
}
|
||||
[[nodiscard]] bool is_interminate() const;
|
||||
void set_intermediate(bool value);
|
||||
|
||||
void set_intermediate(bool value) {
|
||||
_indeterminate = value;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline Data& get_data() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline Data const& get_data() const {
|
||||
return _data;
|
||||
}
|
||||
[[nodiscard]] Data& get_data();
|
||||
[[nodiscard]] Data const& get_data() const;
|
||||
|
||||
private:
|
||||
bool _indeterminate{false};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue