finalise interface & documentation
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
c5157bd849
commit
52580a4382
56 changed files with 2074 additions and 780 deletions
|
|
@ -1,6 +1,7 @@
|
|||
file(
|
||||
GLOB_RECURSE
|
||||
FILES
|
||||
"*.hpp"
|
||||
"*.cpp"
|
||||
)
|
||||
|
||||
|
|
|
|||
8
src/folders/blueprint_folder.hpp
Normal file
8
src/folders/blueprint_folder.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/folders/blueprint_folder.h>
|
||||
|
||||
struct IkarusBlueprintFolder {
|
||||
IkarusId id;
|
||||
std::string name_buffer;
|
||||
};
|
||||
8
src/folders/entity_folder.hpp
Normal file
8
src/folders/entity_folder.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/folders/entity_folder.h>
|
||||
|
||||
struct IkarusEntityFolder {
|
||||
IkarusId id;
|
||||
std::string name_buffer;
|
||||
};
|
||||
13
src/folders/folder.hpp
Normal file
13
src/folders/folder.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <ikarus/folders/folder.h>
|
||||
|
||||
#include <folders/blueprint_folder.hpp>
|
||||
#include <folders/entity_folder.hpp>
|
||||
#include <folders/property_folder.hpp>
|
||||
|
||||
struct IkarusEntityFolder {
|
||||
std::variant<IkarusBlueprintFolder, IkarusPropertyFolder, IkarusEntityFolder> data;
|
||||
};
|
||||
8
src/folders/property_folder.hpp
Normal file
8
src/folders/property_folder.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/folders/property_folder.h>
|
||||
|
||||
struct IkarusPropertyFolder {
|
||||
IkarusId id;
|
||||
std::string name_buffer;
|
||||
};
|
||||
26
src/id.cpp
26
src/id.cpp
|
|
@ -4,28 +4,28 @@
|
|||
|
||||
#include <ikarus/objects/object_type.h>
|
||||
|
||||
IkarusId ikarus_id_from_data(int64_t data) {
|
||||
return IkarusId{.data = data};
|
||||
uint64_t const IKARUS_ID_OBJECT_TYPE_BITS = 8;
|
||||
uint64_t const IKARUS_ID_OBJECT_RANDOM_BITS = sizeof(IkarusId) - IKARUS_ID_OBJECT_TYPE_BITS;
|
||||
|
||||
auto ikarus_id_get_object_type(IkarusId id) -> IkarusObjectType {
|
||||
return static_cast<IkarusObjectType>(id >> IKARUS_ID_OBJECT_RANDOM_BITS);
|
||||
}
|
||||
|
||||
IkarusObjectType ikarus_id_get_object_type(IkarusId id) {
|
||||
return static_cast<IkarusObjectType>(id.data >> 56);
|
||||
auto ikarus_id_is_equal(IkarusId left, IkarusId right) -> bool {
|
||||
return left == right;
|
||||
}
|
||||
|
||||
bool ikarus_id_is_equal(IkarusId left, IkarusId right) {
|
||||
return left.data == right.data;
|
||||
}
|
||||
|
||||
bool ikarus_id_is_none(IkarusId id) {
|
||||
auto ikarus_id_is_none(IkarusId id) -> bool {
|
||||
return ikarus_id_is_equal(id, IKARUS_ID_NONE);
|
||||
}
|
||||
|
||||
bool ikarus_id_is_unspecified(IkarusId id) {
|
||||
auto ikarus_id_is_unspecified(IkarusId id) -> bool {
|
||||
return ikarus_id_is_equal(id, IKARUS_ID_UNSPECIFIED);
|
||||
}
|
||||
|
||||
TEST_CASE("id_object_type", "[id]") {
|
||||
auto id = ikarus_id_from_data(static_cast<uint64_t>(IkarusObjectType_Blueprint) << 56);
|
||||
// NOLINTNEXTLINE(readability-magic-numbers)
|
||||
auto id = static_cast<uint64_t>(IkarusObjectType_Blueprint) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
|
||||
REQUIRE(ikarus_id_get_object_type(id) == IkarusObjectType_Blueprint);
|
||||
REQUIRE(!ikarus_id_is_none(id) == IkarusObjectType_Blueprint);
|
||||
|
|
@ -33,9 +33,9 @@ TEST_CASE("id_object_type", "[id]") {
|
|||
}
|
||||
|
||||
TEST_CASE("id_equal", "[id]") {
|
||||
auto id = ikarus_id_from_data(static_cast<uint64_t>(IkarusObjectType_Blueprint) << 56);
|
||||
auto id = static_cast<uint64_t>(IkarusObjectType_Blueprint) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
auto copy = id;
|
||||
auto third = ikarus_id_from_data(static_cast<uint64_t>(IkarusObjectType_Property) << 56);
|
||||
auto third = static_cast<uint64_t>(IkarusObjectType_Property) << IKARUS_ID_OBJECT_RANDOM_BITS;
|
||||
|
||||
REQUIRE(ikarus_id_is_equal(id, copy));
|
||||
REQUIRE(!ikarus_id_is_equal(id, third));
|
||||
|
|
|
|||
40
src/id.hpp
Normal file
40
src/id.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// IMPLEMENTATION_DETAIL_DATABASE
|
||||
|
||||
/// \file id.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
/// \privatesection
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/object_type.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \defgroup id Ids
|
||||
/// \brief Ids are used to identify objects in the database.
|
||||
/// \details They are stored as 64 bit integers with the following layout:
|
||||
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
||||
/// - next 7 bits: #IkarusObjectType
|
||||
/// - last 56 bits: incremented counter generated by the database
|
||||
/// @{
|
||||
|
||||
/// \brief A wrapper around a 64 bit integer that represents the id of an object.
|
||||
/// \details They are stored as 64 bit integers with the following layout:
|
||||
/// - first bit: ignored, technically we could use it, but SQLite doesn't support u64 integers.
|
||||
/// To avoid ordering fiascos and potential index performance degradation we just skip the first bit.
|
||||
/// - next 7 bits: #IkarusObjectType
|
||||
/// - last 56 bits: incremented counter generated by the database
|
||||
using IkarusId = int64_t;
|
||||
|
||||
/// \brief Fetches the object type of the given id.
|
||||
/// \param id The id to fetch the object type for.
|
||||
/// \return The object type of the given id.
|
||||
IKA_API IkarusObjectType ikarus_id_get_object_type(IkarusId id);
|
||||
|
||||
/// @}
|
||||
|
||||
IKARUS_END_HEADER
|
||||
8
src/objects/blueprint.hpp
Normal file
8
src/objects/blueprint.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/objects/blueprint.h>
|
||||
|
||||
/// \private
|
||||
struct IkarusBlueprint {
|
||||
IkarusId id;
|
||||
};
|
||||
8
src/objects/entity.hpp
Normal file
8
src/objects/entity.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/objects/entity.h>
|
||||
|
||||
/// \private
|
||||
struct IkarusEntity {
|
||||
IkarusId id;
|
||||
};
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
#include "ikarus/objects/object.h"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/object_type.h>
|
||||
#include <objects/object.hpp>
|
||||
|
||||
IkarusObjectType ikarus_object_get_type(IkarusObject object) {
|
||||
return object.type;
|
||||
IkarusObjectType ikarus_object_get_type(IkarusObject const * object) {
|
||||
return object->type;
|
||||
}
|
||||
|
||||
TEST_CASE("object_type", "[object]") {
|
||||
|
|
@ -22,6 +20,6 @@ TEST_CASE("object_type", "[object]") {
|
|||
|
||||
for (auto type : types) {
|
||||
auto object = IkarusObject{.type = type};
|
||||
REQUIRE(ikarus_object_get_type(object) == type);
|
||||
REQUIRE(ikarus_object_get_type(&object) == type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/objects/object.hpp
Normal file
15
src/objects/object.hpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <folders/blueprint_folder.hpp>
|
||||
#include <folders/entity_folder.hpp>
|
||||
#include <folders/property_folder.hpp>
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <objects/property.hpp>
|
||||
|
||||
struct IkarusObject {
|
||||
std::variant<IkarusBlueprint, IkarusProperty, IkarusEntity, IkarusBlueprintFolder, IkarusPropertyFolder, IkarusEntityFolder>
|
||||
data;
|
||||
};
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include "ikarus/objects/object_type.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/folders/folder_type.h>
|
||||
|
||||
IkarusObjectType ikarus_folder_type_to_object_type(IkarusFolderType type) {
|
||||
return static_cast<IkarusObjectType>(type);
|
||||
}
|
||||
|
||||
TEST_CASE("folder_to_object_type_conversion", "[object_type]") {
|
||||
REQUIRE(ikarus_folder_type_to_object_type(IkarusFolderType_None) == IkarusObjectType_None);
|
||||
REQUIRE(ikarus_folder_type_to_object_type(IkarusFolderType_BlueprintFolder) == IkarusObjectType_BlueprintFolder);
|
||||
REQUIRE(ikarus_folder_type_to_object_type(IkarusFolderType_PropertyFolder) == IkarusObjectType_PropertyFolder);
|
||||
REQUIRE(ikarus_folder_type_to_object_type(IkarusFolderType_EntityFolder) == IkarusObjectType_EntityFolder);
|
||||
}
|
||||
8
src/objects/property.hpp
Normal file
8
src/objects/property.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/objects/property.h>
|
||||
|
||||
/// \private
|
||||
struct IkarusProperty {
|
||||
IkarusId id;
|
||||
};
|
||||
10
src/projects/project.hpp
Normal file
10
src/projects/project.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "ikarus/project/project.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
/// \private
|
||||
struct IkarusProject {
|
||||
std::string name;
|
||||
std::filesystem::path path;
|
||||
};
|
||||
12
src/scopes/blueprint_scope.cpp
Normal file
12
src/scopes/blueprint_scope.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "ikarus/scopes/blueprint_scope.h"
|
||||
|
||||
#include <scopes/blueprint_scope.hpp>
|
||||
#include <scopes/object_scope.hpp>
|
||||
|
||||
IkarusBlueprintScope * ikarus_blueprint_scope_create() {
|
||||
return new IkarusBlueprintScope{};
|
||||
}
|
||||
|
||||
struct IkarusObjectScope * ikarus_blueprint_scope_to_object_scope(IkarusBlueprintScope const * scope) {
|
||||
return new IkarusObjectScope{.data = *scope};
|
||||
}
|
||||
5
src/scopes/blueprint_scope.hpp
Normal file
5
src/scopes/blueprint_scope.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/scopes/blueprint_scope.h>
|
||||
|
||||
struct IkarusBlueprintScope {};
|
||||
12
src/scopes/entity_scope.cpp
Normal file
12
src/scopes/entity_scope.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "ikarus/scopes/entity_scope.h"
|
||||
|
||||
#include <scopes/entity_scope.hpp>
|
||||
#include <scopes/object_scope.hpp>
|
||||
|
||||
IkarusEntityScope * ikarus_entity_scope_create() {
|
||||
return new IkarusEntityScope{};
|
||||
}
|
||||
|
||||
IkarusObjectScope * ikarus_entity_scope_to_object_scope(IkarusEntityScope const * scope) {
|
||||
return new IkarusObjectScope{.data = *scope};
|
||||
}
|
||||
5
src/scopes/entity_scope.hpp
Normal file
5
src/scopes/entity_scope.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/scopes/entity_scope.h>
|
||||
|
||||
struct IkarusEntityScope {};
|
||||
|
|
@ -2,194 +2,81 @@
|
|||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/blueprint.h>
|
||||
#include <ikarus/objects/entity.h>
|
||||
#include <cppbase/templates.hpp>
|
||||
|
||||
#include <ikarus/scopes/blueprint_scope.h>
|
||||
#include <ikarus/scopes/entity_scope.h>
|
||||
#include <ikarus/scopes/property_scope.h>
|
||||
|
||||
IkarusBlueprintScope ikarus_blueprint_scope_create() {
|
||||
return IkarusBlueprintScope{._dummy = 0};
|
||||
}
|
||||
#include <scopes/object_scope.hpp>
|
||||
|
||||
IkarusObjectScope ikarus_blueprint_scope_to_object_scope(IkarusBlueprintScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._blueprint = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Blueprint, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScope ikarus_property_scope_create_blueprint(IkarusBlueprint blueprint) {
|
||||
IkarusPropertyScopeData data{};
|
||||
data._blueprint = blueprint;
|
||||
return IkarusPropertyScope{._type = IkarusPropertyScopeType_Blueprint, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScope ikarus_property_scope_create_entity(IkarusEntity entity) {
|
||||
IkarusPropertyScopeData data{};
|
||||
data._entity = entity;
|
||||
return IkarusPropertyScope{._type = IkarusPropertyScopeType_Entity, ._data = data};
|
||||
}
|
||||
|
||||
IkarusObjectScope ikarus_property_scope_to_object_scope(IkarusPropertyScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._property = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Property, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScopeType ikarus_property_scope_get_type(IkarusPropertyScope scope) {
|
||||
return scope._type;
|
||||
}
|
||||
|
||||
void ikarus_property_scope_visit(
|
||||
IkarusPropertyScope scope, void(blueprint)(IkarusBlueprint, void *), void(entity)(IkarusEntity, void *), void * data
|
||||
) {
|
||||
switch (scope._type) {
|
||||
case IkarusPropertyScopeType_Blueprint: blueprint(scope._data._blueprint, data); break;
|
||||
case IkarusPropertyScopeType_Entity: entity(scope._data._entity, data); break;
|
||||
}
|
||||
}
|
||||
|
||||
IkarusEntityScope ikarus_entity_scope_create() {
|
||||
return IkarusEntityScope{._dummy = 0};
|
||||
}
|
||||
|
||||
IkarusObjectScope ikarus_entity_scope_to_object_scope(IkarusEntityScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._entity = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Entity, ._data = data};
|
||||
}
|
||||
|
||||
IkarusObjectScopeType ikarus_object_scope_get_type(IkarusObjectScope scope) {
|
||||
return scope._type;
|
||||
IkarusObjectScopeType ikarus_object_scope_get_type(IkarusObjectScope * scope) {
|
||||
return std::visit(
|
||||
cppbase::overloaded{
|
||||
[]([[maybe_unused]] IkarusBlueprintScope const& scope) { return IkarusObjectScopeType_Blueprint; },
|
||||
[]([[maybe_unused]] IkarusPropertyScope const& scope) { return IkarusObjectScopeType_Property; },
|
||||
[]([[maybe_unused]] IkarusEntityScope const& scope) { return IkarusObjectScopeType_Entity; }},
|
||||
scope->data
|
||||
);
|
||||
}
|
||||
|
||||
void ikarus_object_scope_visit(
|
||||
IkarusObjectScope scope,
|
||||
void(blueprint)(IkarusBlueprintScope, void *),
|
||||
void(property)(IkarusPropertyScope, void *),
|
||||
void(entity)(IkarusEntityScope, void *),
|
||||
IkarusObjectScope * scope,
|
||||
void(blueprint_visitor)(IkarusBlueprintScope *, void *),
|
||||
void(property_visitor)(IkarusPropertyScope *, void *),
|
||||
void(entity_visitor)(IkarusEntityScope *, void *),
|
||||
void * data
|
||||
) {
|
||||
switch (scope._type) {
|
||||
case IkarusObjectScopeType_Blueprint: {
|
||||
if (blueprint != nullptr) {
|
||||
blueprint(scope._data._blueprint, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusObjectScopeType_Property: {
|
||||
if (property != nullptr) {
|
||||
property(scope._data._property, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusObjectScopeType_Entity: {
|
||||
if (entity != nullptr) {
|
||||
entity(scope._data._entity, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::visit(
|
||||
cppbase::overloaded{
|
||||
[blueprint_visitor, data](IkarusBlueprintScope& scope) { blueprint_visitor(&scope, data); },
|
||||
[property_visitor, data](IkarusPropertyScope& scope) { property_visitor(&scope, data); },
|
||||
[entity_visitor, data](IkarusEntityScope& scope) { entity_visitor(&scope, data); }},
|
||||
scope->data
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("blueprint_object_scope_conversion", "[object_scope]") {
|
||||
auto blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
REQUIRE(blueprint_object_scope._type == IkarusObjectScopeType_Blueprint);
|
||||
}
|
||||
|
||||
TEST_CASE("property_scope_type", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
auto entity = IkarusEntity{};
|
||||
|
||||
auto property_blueprint_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto property_entity_scope = ikarus_property_scope_create_entity(entity);
|
||||
|
||||
REQUIRE(ikarus_property_scope_get_type(property_blueprint_scope) == IkarusPropertyScopeType_Blueprint);
|
||||
REQUIRE(ikarus_property_scope_get_type(property_entity_scope) == IkarusPropertyScopeType_Entity);
|
||||
auto * blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto * blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
REQUIRE(ikarus_object_scope_get_type(blueprint_object_scope) == IkarusObjectScopeType_Blueprint);
|
||||
}
|
||||
|
||||
TEST_CASE("property_object_scope_conversion", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
auto entity = IkarusEntity{};
|
||||
auto * blueprint = ikarus_blueprint_create();
|
||||
auto * entity = ikarus_entity_create();
|
||||
|
||||
auto property_blueprint_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto property_blueprint_object_scope = ikarus_property_scope_to_object_scope(property_blueprint_scope);
|
||||
auto * property_blueprint_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto * property_blueprint_object_scope = ikarus_property_scope_to_object_scope(property_blueprint_scope);
|
||||
|
||||
REQUIRE(property_blueprint_object_scope._type == IkarusObjectScopeType_Property);
|
||||
REQUIRE(ikarus_object_scope_get_type(property_blueprint_object_scope) == IkarusObjectScopeType_Property);
|
||||
|
||||
auto property_entity_scope = ikarus_property_scope_create_entity(entity);
|
||||
auto property_entity_object_scope = ikarus_property_scope_to_object_scope(property_entity_scope);
|
||||
auto * property_entity_scope = ikarus_property_scope_create_entity(entity);
|
||||
auto * property_entity_object_scope = ikarus_property_scope_to_object_scope(property_entity_scope);
|
||||
|
||||
REQUIRE(property_entity_object_scope._type == IkarusObjectScopeType_Property);
|
||||
}
|
||||
|
||||
TEST_CASE("property_scope_visiting", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
auto entity = IkarusEntity{};
|
||||
|
||||
auto property_blueprint_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto property_entity_scope = ikarus_property_scope_create_entity(entity);
|
||||
|
||||
int test = 0;
|
||||
|
||||
ikarus_property_scope_visit(
|
||||
property_blueprint_scope,
|
||||
[](IkarusBlueprint, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusEntity, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
&test
|
||||
);
|
||||
|
||||
REQUIRE(test == 1);
|
||||
|
||||
ikarus_property_scope_visit(
|
||||
property_entity_scope,
|
||||
[](IkarusBlueprint, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusEntity, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
&test
|
||||
);
|
||||
|
||||
REQUIRE(test == 2);
|
||||
REQUIRE(ikarus_object_scope_get_type(property_entity_object_scope) == IkarusObjectScopeType_Property);
|
||||
}
|
||||
|
||||
TEST_CASE("entity_object_scope_conversion", "[object_scope]") {
|
||||
auto entity_scope = ikarus_entity_scope_create();
|
||||
auto entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
REQUIRE(entity_object_scope._type == IkarusObjectScopeType_Entity);
|
||||
}
|
||||
|
||||
TEST_CASE("object_scope_type_fetching", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
|
||||
auto blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto property_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto entity_scope = ikarus_entity_scope_create();
|
||||
|
||||
auto blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
auto property_object_scope = ikarus_property_scope_to_object_scope(property_scope);
|
||||
auto entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
|
||||
REQUIRE(ikarus_object_scope_get_type(blueprint_object_scope) == IkarusObjectScopeType_Blueprint);
|
||||
REQUIRE(ikarus_object_scope_get_type(property_object_scope) == IkarusObjectScopeType_Property);
|
||||
auto * entity_scope = ikarus_entity_scope_create();
|
||||
auto * entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
REQUIRE(ikarus_object_scope_get_type(entity_object_scope) == IkarusObjectScopeType_Entity);
|
||||
}
|
||||
|
||||
TEST_CASE("object_scope_visiting", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
auto * blueprint = ikarus_blueprint_create();
|
||||
|
||||
auto blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto property_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto entity_scope = ikarus_entity_scope_create();
|
||||
auto * blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto * property_scope = ikarus_property_scope_create_blueprint(blueprint);
|
||||
auto * entity_scope = ikarus_entity_scope_create();
|
||||
|
||||
auto blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
auto property_object_scope = ikarus_property_scope_to_object_scope(property_scope);
|
||||
auto entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
auto * blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
auto * property_object_scope = ikarus_property_scope_to_object_scope(property_scope);
|
||||
auto * entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
|
||||
auto scopes = {
|
||||
std::make_pair(blueprint_object_scope, 1),
|
||||
|
|
@ -202,9 +89,9 @@ TEST_CASE("object_scope_visiting", "[object_scope]") {
|
|||
|
||||
ikarus_object_scope_visit(
|
||||
scope,
|
||||
[](IkarusBlueprintScope, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusPropertyScope, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
[](IkarusEntityScope, void * data) { *reinterpret_cast<decltype(test) *>(data) = 3; },
|
||||
[](IkarusBlueprintScope *, void * data) { *static_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusPropertyScope *, void * data) { *static_cast<decltype(test) *>(data) = 2; },
|
||||
[](IkarusEntityScope *, void * data) { *static_cast<decltype(test) *>(data) = 3; },
|
||||
&test
|
||||
);
|
||||
|
||||
|
|
|
|||
11
src/scopes/object_scope.hpp
Normal file
11
src/scopes/object_scope.hpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <ikarus/scopes/object_scope.h>
|
||||
|
||||
#include <scopes/blueprint_scope.hpp>
|
||||
#include <scopes/entity_scope.hpp>
|
||||
#include <scopes/property_scope.hpp>
|
||||
|
||||
struct IkarusObjectScope {
|
||||
std::variant<IkarusBlueprintScope, IkarusPropertyScope, IkarusEntityScope> data;
|
||||
};
|
||||
35
src/scopes/property_scope.cpp
Normal file
35
src/scopes/property_scope.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "ikarus/scopes/property_scope.h"
|
||||
|
||||
#include <cppbase/templates.hpp>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
#include <scopes/object_scope.hpp>
|
||||
#include <scopes/property_scope.hpp>
|
||||
|
||||
IkarusPropertyScope * ikarus_property_scope_create_blueprint(IkarusBlueprint * blueprint) {
|
||||
return new IkarusPropertyScope{.data = *blueprint};
|
||||
}
|
||||
|
||||
IkarusPropertyScope * ikarus_property_scope_create_entity(IkarusEntity * entity) {
|
||||
return new IkarusPropertyScope{.data = *entity};
|
||||
}
|
||||
|
||||
IkarusObjectScope * ikarus_property_scope_to_object_scope(IkarusPropertyScope const * scope) {
|
||||
return new IkarusObjectScope{.data = *scope};
|
||||
}
|
||||
|
||||
void ikarus_property_scope_visit(
|
||||
IkarusPropertyScope * scope,
|
||||
void (*blueprint_func)(IkarusBlueprint *, void *),
|
||||
void (*entity_func)(IkarusEntity *, void *),
|
||||
void * data
|
||||
) {
|
||||
std::visit(
|
||||
cppbase::overloaded{
|
||||
[blueprint_func, data](IkarusBlueprint& blueprint) { blueprint_func(&blueprint, data); },
|
||||
[entity_func, data](IkarusEntity& entity) { entity_func(&entity, data); },
|
||||
},
|
||||
scope->data
|
||||
);
|
||||
}
|
||||
12
src/scopes/property_scope.hpp
Normal file
12
src/scopes/property_scope.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include <ikarus/scopes/property_scope.h>
|
||||
|
||||
#include <objects/blueprint.hpp>
|
||||
#include <objects/entity.hpp>
|
||||
|
||||
struct IkarusPropertyScope {
|
||||
std::variant<IkarusBlueprint, IkarusEntity> data;
|
||||
};
|
||||
|
|
@ -25,7 +25,7 @@ IKA_API IkarusEntityValue value_create_invalid(IkarusPropertyType type) {
|
|||
IkarusEntityValue ikarus_value_create_toggle(bool value) {
|
||||
return IkarusEntityValue{
|
||||
._type = IkarusPropertyType_Toggle,
|
||||
._data = IkarusEntityValueData{.toggle = IkarusToggleValue{._value = value}},
|
||||
._data = IkarusEntityValueData{._toggle = IkarusToggleValue{._value = value}},
|
||||
._state = IkarusEntityValueState_Normal,
|
||||
};
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ IkarusEntityValue ikarus_value_create_number(long double value) {
|
|||
|
||||
return IkarusEntityValue{
|
||||
._type = IkarusPropertyType_Number,
|
||||
._data = IkarusEntityValueData{.number = IkarusNumberValue{._value = value}},
|
||||
._data = IkarusEntityValueData{._number = IkarusNumberValue{._value = value}},
|
||||
._state = IkarusEntityValueState_Normal,
|
||||
};
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ IkarusEntityValue ikarus_value_create_text(char const * value) {
|
|||
|
||||
return IkarusEntityValue{
|
||||
._type = IkarusPropertyType_Text,
|
||||
._data = IkarusEntityValueData{.text = IkarusTextValue{._value = value}},
|
||||
._data = IkarusEntityValueData{._text = IkarusTextValue{._value = value}},
|
||||
._state = IkarusEntityValueState_Normal,
|
||||
};
|
||||
}
|
||||
|
|
@ -59,15 +59,15 @@ IkarusEntityValue ikarus_value_create_indeterminate(IkarusPropertyType type) {
|
|||
|
||||
switch (type) {
|
||||
case IkarusPropertyType_Toggle: {
|
||||
data.toggle = IkarusToggleValue{._value = false};
|
||||
data._toggle = IkarusToggleValue{._value = false};
|
||||
break;
|
||||
}
|
||||
case IkarusPropertyType_Number: {
|
||||
data.number = IkarusNumberValue{._value = 0.0};
|
||||
data._number = IkarusNumberValue{._value = 0.0};
|
||||
break;
|
||||
}
|
||||
case IkarusPropertyType_Text: {
|
||||
data.text = IkarusTextValue{._value = ""};
|
||||
data._text = IkarusTextValue{._value = ""};
|
||||
break;
|
||||
}
|
||||
default: return value_create_invalid(type);
|
||||
|
|
@ -133,9 +133,9 @@ bool ikarus_value_is_equal(IkarusEntityValue const * left, IkarusEntityValue con
|
|||
}
|
||||
|
||||
switch (left->_type) {
|
||||
case IkarusPropertyType_Toggle: return left->_data.toggle._value == right->_data.toggle._value;
|
||||
case IkarusPropertyType_Number: return left->_data.number._value == right->_data.number._value;
|
||||
case IkarusPropertyType_Text: return std::strcmp(left->_data.text._value, right->_data.text._value) == 0;
|
||||
case IkarusPropertyType_Toggle: return left->_data._toggle._value == right->_data._toggle._value;
|
||||
case IkarusPropertyType_Number: return left->_data._number._value == right->_data._number._value;
|
||||
case IkarusPropertyType_Text: return std::strcmp(left->_data._text._value, right->_data._text._value) == 0;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -162,19 +162,19 @@ void ikarus_value_visit(
|
|||
switch (value->_type) {
|
||||
case IkarusPropertyType_Toggle: {
|
||||
if (toggle != nullptr) {
|
||||
toggle(&value->_data.toggle, data);
|
||||
toggle(&value->_data._toggle, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusPropertyType_Number: {
|
||||
if (number != nullptr) {
|
||||
number(&value->_data.number, data);
|
||||
number(&value->_data._number, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusPropertyType_Text: {
|
||||
if (text != nullptr) {
|
||||
text(&value->_data.text, data);
|
||||
text(&value->_data._text, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -186,14 +186,14 @@ TEST_CASE("toggle_value_creation", "[value]") {
|
|||
auto toggle_value = ikarus_value_create_toggle(true);
|
||||
|
||||
REQUIRE(ikarus_value_get_type(&toggle_value) == IkarusPropertyType_Toggle);
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&toggle_value._data.toggle, true));
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&toggle_value._data._toggle, true));
|
||||
}
|
||||
|
||||
TEST_CASE("number_value_creation", "[value]") {
|
||||
auto number_value = ikarus_value_create_number(1.0);
|
||||
|
||||
REQUIRE(ikarus_value_get_type(&number_value) == IkarusPropertyType_Number);
|
||||
REQUIRE(ikarus_number_value_is_equal(&number_value._data.number, 1.0));
|
||||
REQUIRE(ikarus_number_value_is_equal(&number_value._data._number, 1.0));
|
||||
|
||||
auto nan_value = ikarus_value_create_number(std::numeric_limits<long double>::quiet_NaN());
|
||||
REQUIRE(ikarus_value_is_invalid(&nan_value));
|
||||
|
|
@ -209,7 +209,7 @@ TEST_CASE("text_value_creation", "[value]") {
|
|||
auto text_value = ikarus_value_create_text("test");
|
||||
|
||||
REQUIRE(ikarus_value_get_type(&text_value) == IkarusPropertyType_Text);
|
||||
REQUIRE(ikarus_text_value_is_equal(&text_value._data.text, "test"));
|
||||
REQUIRE(ikarus_text_value_is_equal(&text_value._data._text, "test"));
|
||||
|
||||
auto null_value = ikarus_value_create_text(nullptr);
|
||||
REQUIRE(ikarus_value_is_invalid(&null_value));
|
||||
|
|
@ -232,8 +232,8 @@ TEST_CASE("toggle_value_underlying", "[value]") {
|
|||
auto true_toggle_value = ikarus_value_create_toggle(true);
|
||||
auto false_toggle_value = ikarus_value_create_toggle(false);
|
||||
|
||||
REQUIRE(ikarus_toggle_value_get_underlying(&true_toggle_value._data.toggle) == true);
|
||||
REQUIRE(ikarus_toggle_value_get_underlying(&false_toggle_value._data.toggle) == false);
|
||||
REQUIRE(ikarus_toggle_value_get_underlying(&true_toggle_value._data._toggle) == true);
|
||||
REQUIRE(ikarus_toggle_value_get_underlying(&false_toggle_value._data._toggle) == false);
|
||||
}
|
||||
|
||||
TEST_CASE("number_value_underlying", "[value]") {
|
||||
|
|
@ -241,25 +241,25 @@ TEST_CASE("number_value_underlying", "[value]") {
|
|||
auto third_number_value = ikarus_value_create_number(1.0 / 3.0);
|
||||
auto large_number_value = ikarus_value_create_number(1.2345678910e123);
|
||||
|
||||
REQUIRE(ikarus_number_value_get_underlying(&zero_number_value._data.number) == 0.0);
|
||||
REQUIRE(ikarus_number_value_get_underlying(&third_number_value._data.number) == 1.0 / 3.0);
|
||||
REQUIRE(ikarus_number_value_get_underlying(&large_number_value._data.number) == 1.2345678910e123);
|
||||
REQUIRE(ikarus_number_value_get_underlying(&zero_number_value._data._number) == 0.0);
|
||||
REQUIRE(ikarus_number_value_get_underlying(&third_number_value._data._number) == 1.0 / 3.0);
|
||||
REQUIRE(ikarus_number_value_get_underlying(&large_number_value._data._number) == 1.2345678910e123);
|
||||
}
|
||||
|
||||
TEST_CASE("text_value_underlying", "[value]") {
|
||||
auto test_value = ikarus_value_create_text("test");
|
||||
auto empty_value = ikarus_value_create_text("");
|
||||
|
||||
REQUIRE(std::strcmp(ikarus_text_value_get_underlying(&test_value._data.text), "test") == 0);
|
||||
REQUIRE(std::strcmp(ikarus_text_value_get_underlying(&empty_value._data.text), "") == 0);
|
||||
REQUIRE(std::strcmp(ikarus_text_value_get_underlying(&test_value._data._text), "test") == 0);
|
||||
REQUIRE(std::strcmp(ikarus_text_value_get_underlying(&empty_value._data._text), "") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("toggle_comparison", "[value]") {
|
||||
auto true_toggle_value = ikarus_value_create_toggle(true);
|
||||
auto false_toggle_value = ikarus_value_create_toggle(false);
|
||||
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&true_toggle_value._data.toggle, true));
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&false_toggle_value._data.toggle, false));
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&true_toggle_value._data._toggle, true));
|
||||
REQUIRE(ikarus_toggle_value_is_equal(&false_toggle_value._data._toggle, false));
|
||||
}
|
||||
|
||||
TEST_CASE("number_comparison", "[value]") {
|
||||
|
|
@ -267,17 +267,17 @@ TEST_CASE("number_comparison", "[value]") {
|
|||
auto third_number_value = ikarus_value_create_number(1.0 / 3.0);
|
||||
auto large_number_value = ikarus_value_create_number(1.2345678910e123);
|
||||
|
||||
REQUIRE(ikarus_number_value_is_equal(&zero_number_value._data.number, 0.0));
|
||||
REQUIRE(ikarus_number_value_is_equal(&third_number_value._data.number, 1.0 / 6.0 + 1.0 / 6.0));
|
||||
REQUIRE(ikarus_number_value_is_equal(&large_number_value._data.number, 1.2345678910e123));
|
||||
REQUIRE(ikarus_number_value_is_equal(&zero_number_value._data._number, 0.0));
|
||||
REQUIRE(ikarus_number_value_is_equal(&third_number_value._data._number, 1.0 / 6.0 + 1.0 / 6.0));
|
||||
REQUIRE(ikarus_number_value_is_equal(&large_number_value._data._number, 1.2345678910e123));
|
||||
}
|
||||
|
||||
TEST_CASE("text_comparison", "[value]") {
|
||||
auto test_value = ikarus_value_create_text("test");
|
||||
auto empty_value = ikarus_value_create_text("");
|
||||
|
||||
REQUIRE(ikarus_text_value_is_equal(&test_value._data.text, "test"));
|
||||
REQUIRE(ikarus_text_value_is_equal(&empty_value._data.text, ""));
|
||||
REQUIRE(ikarus_text_value_is_equal(&test_value._data._text, "test"));
|
||||
REQUIRE(ikarus_text_value_is_equal(&empty_value._data._text, ""));
|
||||
}
|
||||
|
||||
TEST_CASE("value_comparison", "[value]") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue