intermediate commit
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
82e5309f80
commit
ea221cdf85
11 changed files with 175 additions and 175 deletions
|
|
@ -14,18 +14,12 @@ IKARUS_BEGIN_HEADER
|
||||||
enum IkarusObjectType {
|
enum IkarusObjectType {
|
||||||
/// \brief Not an object or no object.
|
/// \brief Not an object or no object.
|
||||||
IkarusObjectType_None = 0,
|
IkarusObjectType_None = 0,
|
||||||
/// \brief An IkarusBlueprint.
|
|
||||||
IkarusObjectType_Blueprint = 0b00000001,
|
|
||||||
/// \brief An IkarusProperty.
|
|
||||||
IkarusObjectType_Property = 0b00000010,
|
|
||||||
/// \brief An IkarusEntity.
|
/// \brief An IkarusEntity.
|
||||||
IkarusObjectType_Entity = 0b00000011,
|
IkarusObjectType_Entity = 0b00000011,
|
||||||
/// \brief An IkarusBlueprintFolder
|
/// \brief An IkarusProperty.
|
||||||
IkarusObjectType_BlueprintFolder = 0b01000001,
|
IkarusObjectType_Property = 0b00000010,
|
||||||
/// \brief An IkarusPropertyFolder
|
/// \brief An IkarusBlueprint.
|
||||||
IkarusObjectType_PropertyFolder = 0b01000010,
|
IkarusObjectType_Blueprint = 0b00000001,
|
||||||
/// \brief An IkarusEntityFolder
|
|
||||||
IkarusObjectType_EntityFolder = 0b01000011,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IKARUS_END_HEADER
|
IKARUS_END_HEADER
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ IKA_API void ikarus_property_settings_visit(
|
||||||
void * data
|
void * data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// \see ikarus_property_settings_visit
|
||||||
IKA_API void ikarus_property_settings_visit_const(
|
IKA_API void ikarus_property_settings_visit_const(
|
||||||
struct IkarusPropertySettings const * settings,
|
struct IkarusPropertySettings const * settings,
|
||||||
void (*toggle_property_visitor)(struct IkarusTogglePropertySettings const * settings, void * data),
|
void (*toggle_property_visitor)(struct IkarusTogglePropertySettings const * settings, void * data),
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@
|
||||||
uint64_t const IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
uint64_t const IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
||||||
uint64_t const IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
uint64_t const IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
||||||
|
|
||||||
auto ikarus_id_get_object_type(IkarusId id) -> IkarusObjectType {
|
auto from_data_and_type(int64_t data, IkarusObjectType type) -> IkarusId {
|
||||||
return static_cast<IkarusObjectType>(id >> IKARUS_ID_OBJECT_RANDOM_BITS);
|
return data | (static_cast<IkarusId>(type) << IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ikarus_id_is_equal(IkarusId left, IkarusId right) -> bool {
|
auto ikarus_id_get_object_type(IkarusId id) -> IkarusObjectType {
|
||||||
return left == right;
|
return static_cast<IkarusObjectType>(id >> IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("id_object_type", "[id]") {
|
TEST_CASE("id_object_type", "[id]") {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ IKARUS_BEGIN_HEADER
|
||||||
/// - last 56 bits: incremented counter generated by the database
|
/// - last 56 bits: incremented counter generated by the database
|
||||||
using IkarusId = int64_t;
|
using IkarusId = int64_t;
|
||||||
|
|
||||||
|
IKA_API IkarusId ikarus_id_from_data_and_type(int64_t data, IkarusObjectType type);
|
||||||
|
|
||||||
/// \brief Fetches the object type of the given id.
|
/// \brief Fetches the object type of the given id.
|
||||||
/// \param id The id to fetch the object type for.
|
/// \param id The id to fetch the object type for.
|
||||||
/// \return The object type of the given id.
|
/// \return The object type of the given id.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "blueprint.hpp"
|
#include <iterator>
|
||||||
|
|
||||||
#include <cppbase/logger.hpp>
|
#include <cppbase/logger.hpp>
|
||||||
#include <cppbase/result.hpp>
|
#include <cppbase/result.hpp>
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <ikarus/objects/blueprint.h>
|
#include <ikarus/objects/blueprint.h>
|
||||||
|
|
||||||
|
#include <objects/blueprint.hpp>
|
||||||
#include <objects/entity.hpp>
|
#include <objects/entity.hpp>
|
||||||
#include <objects/property.hpp>
|
#include <objects/property.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <persistence/project.hpp>
|
||||||
|
|
@ -18,7 +19,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ctx = project->function_context();
|
auto * ctx = project->function_context();
|
||||||
|
|
||||||
if (name == nullptr) {
|
if (name == nullptr) {
|
||||||
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
ctx->set_error("name is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||||
|
|
@ -30,7 +31,7 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_VERBOSE("project={}; name={}", project->path().c_str(), name);
|
LOG_DEBUG("project={}; name={}", project->path().c_str(), name);
|
||||||
|
|
||||||
VTRYRV(
|
VTRYRV(
|
||||||
auto id,
|
auto id,
|
||||||
|
|
@ -45,9 +46,9 @@ IkarusBlueprint * ikarus_blueprint_create(struct IkarusProject * project, char c
|
||||||
name
|
name
|
||||||
));
|
));
|
||||||
|
|
||||||
auto id = db->last_insert_rowid();
|
auto id = ikarus_id_from_data_and_type(db->last_insert_rowid(), IkarusObjectType_Blueprint);
|
||||||
|
|
||||||
LOG_VERBOSE("id is {}", id);
|
LOG_DEBUG("blueprint is {}", id);
|
||||||
|
|
||||||
LOG_VERBOSE("inserting blueprint into blueprints table");
|
LOG_VERBOSE("inserting blueprint into blueprints table");
|
||||||
|
|
||||||
|
|
@ -80,7 +81,7 @@ void ikarus_blueprint_delete(IkarusBlueprint * blueprint) {
|
||||||
|
|
||||||
auto * ctx = blueprint->project->function_context();
|
auto * ctx = blueprint->project->function_context();
|
||||||
|
|
||||||
LOG_VERBOSE("blueprint={}", blueprint->id);
|
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||||
|
|
||||||
TRYRV(
|
TRYRV(
|
||||||
,
|
,
|
||||||
|
|
@ -113,13 +114,13 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
||||||
|
|
||||||
auto * ctx = blueprint->project->function_context();
|
auto * ctx = blueprint->project->function_context();
|
||||||
|
|
||||||
LOG_VERBOSE("blueprint={}", blueprint->id);
|
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||||
|
|
||||||
VTRYRV(
|
VTRYRV(
|
||||||
auto count,
|
auto count,
|
||||||
0,
|
0,
|
||||||
blueprint->project->db()
|
blueprint->project->db()
|
||||||
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint_id` = ?;", blueprint->id)
|
->query_one<int>("SELECT COUNT(*) FROM `blueprint_properties` WHERE `blueprint` = ?;", blueprint->id)
|
||||||
.on_error([ctx](auto const& err) {
|
.on_error([ctx](auto const& err) {
|
||||||
ctx->set_error(
|
ctx->set_error(
|
||||||
fmt::format("failed to fetch blueprint property count: {}", err),
|
fmt::format("failed to fetch blueprint property count: {}", err),
|
||||||
|
|
@ -130,6 +131,10 @@ size_t ikarus_blueprint_get_property_count(IkarusBlueprint const * blueprint) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
LOG_DEBUG("blueprint property count: {}", count);
|
||||||
|
|
||||||
|
LOG_VERBOSE("successfully fetched blueprint property count");
|
||||||
|
|
||||||
return static_cast<size_t>(count);
|
return static_cast<size_t>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,11 +151,11 @@ void ikarus_blueprint_get_properties(
|
||||||
auto * ctx = blueprint->project->function_context();
|
auto * ctx = blueprint->project->function_context();
|
||||||
|
|
||||||
if (properties_out == nullptr) {
|
if (properties_out == nullptr) {
|
||||||
LOG_ERROR("properties_out is nullptr");
|
ctx->set_error("properties_out is null", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_VERBOSE("blueprint={}; properties_out_size={}", blueprint->id, properties_out_size);
|
LOG_DEBUG("blueprint={}; properties_out_size={}", blueprint->id, properties_out_size);
|
||||||
|
|
||||||
IkarusId ids[properties_out_size];
|
IkarusId ids[properties_out_size];
|
||||||
|
|
||||||
|
|
@ -173,6 +178,8 @@ 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) {
|
for (size_t i = 0; i < properties_out_size; ++i) {
|
||||||
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
properties_out[i] = blueprint->project->get_property(ids[i]);
|
properties_out[i] = blueprint->project->get_property(ids[i]);
|
||||||
|
|
@ -180,3 +187,108 @@ void ikarus_blueprint_get_properties(
|
||||||
|
|
||||||
LOG_VERBOSE("successfully fetched blueprint properties");
|
LOG_VERBOSE("successfully fetched blueprint 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto * ctx = blueprint->project->function_context();
|
||||||
|
|
||||||
|
LOG_DEBUG("blueprint={}", blueprint->id);
|
||||||
|
|
||||||
|
VTRYRV(
|
||||||
|
auto count,
|
||||||
|
0,
|
||||||
|
blueprint->project->db()
|
||||||
|
->query_one<int>("SELECT COUNT(*) FROM `entity_blueprint_links` WHERE `blueprint` = ?;", blueprint->id)
|
||||||
|
.on_error([ctx](auto const& err) {
|
||||||
|
ctx->set_error(
|
||||||
|
fmt::format("failed to fetch blueprint linked entity count: {}", err),
|
||||||
|
true,
|
||||||
|
IkarusErrorInfo_Source_SubSystem,
|
||||||
|
IkarusErrorInfo_Type_SubSystem_Database
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
LOG_DEBUG("blueprint linked entity count: {}", count);
|
||||||
|
|
||||||
|
LOG_VERBOSE("successfully fetched blueprint linked entity count: {}", count);
|
||||||
|
|
||||||
|
return static_cast<size_t>(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ikarus_blueprint_get_linked_entities(
|
||||||
|
IkarusBlueprint const * blueprint, struct IkarusEntity ** entities_out, size_t entities_out_size
|
||||||
|
) {
|
||||||
|
LOG_VERBOSE("fetching blueprint linked entities");
|
||||||
|
|
||||||
|
if (blueprint == nullptr) {
|
||||||
|
LOG_ERROR("blueprint is nullptr");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto * ctx = blueprint->project->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->id, entities_out_size);
|
||||||
|
|
||||||
|
IkarusId ids[entities_out_size];
|
||||||
|
|
||||||
|
TRYRV(
|
||||||
|
,
|
||||||
|
blueprint->project->db()
|
||||||
|
->query_many_buffered<IkarusId>(
|
||||||
|
"SELECT `entity` FROM `entity_blueprint_links` WHERE `blueprint` = ?",
|
||||||
|
static_cast<IkarusId *>(ids),
|
||||||
|
entities_out_size,
|
||||||
|
blueprint->id
|
||||||
|
)
|
||||||
|
.on_error([ctx](auto const& err) {
|
||||||
|
ctx->set_error(
|
||||||
|
fmt::format("failed to fetch blueprint linked entity ids: {}", err),
|
||||||
|
true,
|
||||||
|
IkarusErrorInfo_Source_SubSystem,
|
||||||
|
IkarusErrorInfo_Type_SubSystem_Database
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
LOG_DEBUG("blueprint linked entities: [{}]", fmt::join(ids, ids + entities_out_size, ", "));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < entities_out_size; ++i) {
|
||||||
|
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
entities_out[i] = blueprint->project->get_entity(ids[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_VERBOSE("successfully fetched blueprint linked entities");
|
||||||
|
}
|
||||||
|
|
||||||
|
IkarusObject * ikarus_blueprint_to_object(IkarusBlueprint * blueprint) {
|
||||||
|
return const_cast<IkarusObject *>(ikarus_blueprint_to_object_const(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->id);
|
||||||
|
|
||||||
|
LOG_VERBOSE("successfully casted blueprint to object");
|
||||||
|
|
||||||
|
return static_cast<IkarusObject const *>(blueprint);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,79 +9,5 @@
|
||||||
#include <objects/blueprint.hpp>
|
#include <objects/blueprint.hpp>
|
||||||
#include <objects/entity.hpp>
|
#include <objects/entity.hpp>
|
||||||
#include <objects/property.hpp>
|
#include <objects/property.hpp>
|
||||||
#include <objects/property_info.hpp>
|
|
||||||
#include <objects/property_source.hpp>
|
#include <objects/property_source.hpp>
|
||||||
#include <persistence/project.hpp>
|
#include <persistence/project.hpp>
|
||||||
|
|
||||||
IkarusProperty * ikarus_property_create(
|
|
||||||
struct IkarusProject * project,
|
|
||||||
char const * name,
|
|
||||||
struct IkarusPropertySource * property_source,
|
|
||||||
struct IkarusPropertyInfo * property_info
|
|
||||||
) {
|
|
||||||
LOG_INFO("creating new property");
|
|
||||||
|
|
||||||
if (project == nullptr) {
|
|
||||||
LOG_ERROR("project is nullptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ctx = project->function_context();
|
|
||||||
|
|
||||||
if (property_source == nullptr) {
|
|
||||||
ctx->set_error("property_source is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property_info == nullptr) {
|
|
||||||
ctx->set_error("property_info is nullptr", true, IkarusErrorInfo_Source_Client, IkarusErrorInfo_Type_Client_Input);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_VERBOSE(
|
|
||||||
"project={}; name={}; property_source={}; property_info={}",
|
|
||||||
project->path().c_str(),
|
|
||||||
name,
|
|
||||||
std::visit(
|
|
||||||
cppbase::overload{
|
|
||||||
[](IkarusBlueprint * blueprint) { return fmt::format("Blueprint({})", blueprint->id); },
|
|
||||||
[](IkarusEntity * entity) { return fmt::format("Entity({})", entity->id); }},
|
|
||||||
property_source->data
|
|
||||||
),
|
|
||||||
std::visit(
|
|
||||||
cppbase::overload{
|
|
||||||
[](IkarusTogglePropertyInfo * info) {
|
|
||||||
return fmt::format(
|
|
||||||
"Toggle(default_value={})",
|
|
||||||
cppbase::OwningString{ikarus_value_to_string(ikarus_toggle_value_to_entity_value(info->default_value))}
|
|
||||||
.data
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[](IkarusNumberPropertyInfo * info) {
|
|
||||||
return fmt::format(
|
|
||||||
"Number(default_value={})",
|
|
||||||
cppbase::OwningString{ikarus_value_to_string(ikarus_number_value_to_entity_value(info->default_value))}
|
|
||||||
.data
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[](IkarusTextPropertyInfo * info) {
|
|
||||||
return fmt::format(
|
|
||||||
"Text(default_value={})",
|
|
||||||
cppbase::OwningString{ikarus_value_to_string(ikarus_text_value_to_entity_value(info->default_value))}
|
|
||||||
.data
|
|
||||||
);
|
|
||||||
}},
|
|
||||||
property_info->data
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
#include <ikarus/objects/property_info.h>
|
|
||||||
|
|
||||||
#include <values/number_value.hpp>
|
|
||||||
#include <values/text_value.hpp>
|
|
||||||
#include <values/toggle_value.hpp>
|
|
||||||
|
|
||||||
// this looks a bit cursed, but there's reason to my madness:
|
|
||||||
// Let's go over the facts:
|
|
||||||
// 1. The client uses the concrete types (e.g. Ikarus"Toggle"PropertyInfo)
|
|
||||||
// 2. The API needs to accept a common type (i.e. IkarusPropertyInfo)
|
|
||||||
// 3. Casting between a concrete subtype and a common type is only defined behaviour if we use inheritance, otherwise an
|
|
||||||
// allocation is unavoidable
|
|
||||||
// 4. On the implementation side, we need to be able to distinguish between the concrete types
|
|
||||||
//
|
|
||||||
// There's a few ways to model this (using dynamic_casts, using an enum, a union, the visitor pattern, ...) but std::variant
|
|
||||||
// gives us the most type safety without any performance overhead
|
|
||||||
|
|
||||||
/// \private
|
|
||||||
struct IkarusPropertyInfo {
|
|
||||||
public:
|
|
||||||
using IkarusPropertyInfoData =
|
|
||||||
std::variant<struct IkarusTogglePropertyInfo *, struct IkarusNumberPropertyInfo *, struct IkarusTextPropertyInfo *>;
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline explicit IkarusPropertyInfo(
|
|
||||||
std::variant<struct IkarusTogglePropertyInfo *, struct IkarusNumberPropertyInfo *, struct IkarusTextPropertyInfo *> data
|
|
||||||
):
|
|
||||||
data{data} {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] inline IkarusPropertyInfoData const& get_data() const {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IkarusPropertyInfoData data;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \private
|
|
||||||
struct IkarusTogglePropertyInfo : public IkarusPropertyInfo {
|
|
||||||
public:
|
|
||||||
inline IkarusTogglePropertyInfo():
|
|
||||||
IkarusPropertyInfo{this} {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] IkarusToggleValue * get_default_value() const {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IkarusToggleValue * default_value{nullptr};
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \private
|
|
||||||
struct IkarusNumberPropertyInfo : public IkarusPropertyInfo {
|
|
||||||
public:
|
|
||||||
inline IkarusNumberPropertyInfo():
|
|
||||||
IkarusPropertyInfo{this} {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IkarusNumberValue * default_value{nullptr};
|
|
||||||
};
|
|
||||||
|
|
||||||
/// \private
|
|
||||||
struct IkarusTextPropertyInfo : public IkarusPropertyInfo {
|
|
||||||
public:
|
|
||||||
inline IkarusTextPropertyInfo():
|
|
||||||
IkarusPropertyInfo{this} {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IkarusTextValue * default_value{nullptr};
|
|
||||||
};
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include <ikarus/objects/property_source.h>
|
#include <ikarus/objects/properties/property_source.h>
|
||||||
|
|
||||||
/// \private
|
/// \private
|
||||||
struct IkarusPropertySource {
|
struct IkarusPropertySource {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ CREATE TABLE `entities`
|
||||||
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`id`) REFERENCES `objects` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE TABLE `entity_blueprints`
|
CREATE TABLE `entity_blueprint_links`
|
||||||
(
|
(
|
||||||
`entity` INT NOT NULL,
|
`entity` INT NOT NULL,
|
||||||
`blueprint` INT NOT NULL,
|
`blueprint` INT NOT NULL,
|
||||||
|
|
@ -50,7 +50,7 @@ CREATE TABLE `entity_blueprints`
|
||||||
FOREIGN KEY (`blueprint`) REFERENCES `blueprints` (`id`) ON DELETE CASCADE
|
FOREIGN KEY (`blueprint`) REFERENCES `blueprints` (`id`) ON DELETE CASCADE
|
||||||
) WITHOUT ROWID, STRICT;
|
) WITHOUT ROWID, STRICT;
|
||||||
|
|
||||||
CREATE INDEX `entity_blueprints_blueprint` ON `entity_blueprints` (`blueprint`);
|
CREATE INDEX `entity_blueprints_blueprint` ON `entity_blueprint_links` (`blueprint`);
|
||||||
|
|
||||||
CREATE TABLE `properties`
|
CREATE TABLE `properties`
|
||||||
(
|
(
|
||||||
|
|
|
||||||
31
src/values/value.cpp
Normal file
31
src/values/value.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include "ikarus/values/value.h"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <cppbase/templates.hpp>
|
||||||
|
|
||||||
|
#include <values/number_value.hpp>
|
||||||
|
#include <values/text_value.hpp>
|
||||||
|
#include <values/toggle_value.hpp>
|
||||||
|
#include <values/value.hpp>
|
||||||
|
|
||||||
|
bool ikarus_value_is_indeterminate(IkarusValue const * value) {
|
||||||
|
return value->indeterminate;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * ikarus_value_to_string(IkarusValue const * value) {
|
||||||
|
auto 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); },
|
||||||
|
},
|
||||||
|
value->data
|
||||||
|
);
|
||||||
|
|
||||||
|
char * ret = new char[str.size() + 1];
|
||||||
|
|
||||||
|
std::strncpy(ret, str.data(), str.size() + 1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
8
src/values/value.hpp
Normal file
8
src/values/value.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
struct IkarusValue {
|
||||||
|
bool indeterminate;
|
||||||
|
std::variant<struct IkarusToggleValue *, struct IkarusNumberValue *, struct IkarusTextValue *> data;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue