restructure into smaller files & add IWYU/clang-tidy
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
660736133a
commit
13eee8b168
28 changed files with 845 additions and 556 deletions
|
|
@ -1,11 +1,11 @@
|
|||
#include "ikarus/types/id.h"
|
||||
#include "ikarus/id.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/object_type.h>
|
||||
|
||||
IkarusId ikarus_id_from_data(int64_t data) {
|
||||
return IkarusId {
|
||||
.data = data
|
||||
};
|
||||
return IkarusId{.data = data};
|
||||
}
|
||||
|
||||
IkarusObjectType ikarus_id_get_object_type(IkarusId id) {
|
||||
27
src/objects/object.cpp
Normal file
27
src/objects/object.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "ikarus/objects/object.h"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/object_type.h>
|
||||
|
||||
IkarusObjectType ikarus_object_get_type(IkarusObject object) {
|
||||
return object.type;
|
||||
}
|
||||
|
||||
TEST_CASE("object_type", "[object]") {
|
||||
auto types = {
|
||||
IkarusObjectType_Blueprint,
|
||||
IkarusObjectType_Property,
|
||||
IkarusObjectType_Entity,
|
||||
IkarusObjectType_BlueprintFolder,
|
||||
IkarusObjectType_PropertyFolder,
|
||||
IkarusObjectType_EntityFolder,
|
||||
};
|
||||
|
||||
for (auto type : types) {
|
||||
auto object = IkarusObject{.type = type};
|
||||
REQUIRE(ikarus_object_get_type(object) == type);
|
||||
}
|
||||
}
|
||||
16
src/objects/object_type.cpp
Normal file
16
src/objects/object_type.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -1,52 +1,56 @@
|
|||
#include "ikarus/types/object_scope.h"
|
||||
#include "ikarus/scopes/object_scope.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/objects/blueprint.h>
|
||||
#include <ikarus/objects/entity.h>
|
||||
#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};
|
||||
}
|
||||
|
||||
IkarusObjectScope ikarus_blueprint_scope_to_object_scope(IkarusBlueprintScope const * scope) {
|
||||
IkarusObjectScope ikarus_blueprint_scope_to_object_scope(IkarusBlueprintScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._blueprint = *scope;
|
||||
data._blueprint = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Blueprint, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScope ikarus_property_scope_create_blueprint(IkarusBlueprint const * blueprint) {
|
||||
IkarusPropertyScope ikarus_property_scope_create_blueprint(IkarusBlueprint blueprint) {
|
||||
IkarusPropertyScopeData data{};
|
||||
data._blueprint = *blueprint;
|
||||
data._blueprint = blueprint;
|
||||
return IkarusPropertyScope{._type = IkarusPropertyScopeType_Blueprint, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScope ikarus_property_scope_create_entity(IkarusEntity const * entity) {
|
||||
IkarusPropertyScope ikarus_property_scope_create_entity(IkarusEntity entity) {
|
||||
IkarusPropertyScopeData data{};
|
||||
data._entity = *entity;
|
||||
data._entity = entity;
|
||||
return IkarusPropertyScope{._type = IkarusPropertyScopeType_Entity, ._data = data};
|
||||
}
|
||||
|
||||
IkarusObjectScope ikarus_property_scope_to_object_scope(IkarusPropertyScope const * scope) {
|
||||
IkarusObjectScope ikarus_property_scope_to_object_scope(IkarusPropertyScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._property = *scope;
|
||||
data._property = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Property, ._data = data};
|
||||
}
|
||||
|
||||
IkarusPropertyScopeType ikarus_property_scope_get_type(IkarusPropertyScope const * scope) {
|
||||
return scope->_type;
|
||||
IkarusPropertyScopeType ikarus_property_scope_get_type(IkarusPropertyScope scope) {
|
||||
return scope._type;
|
||||
}
|
||||
|
||||
void ikarus_property_scope_visit(
|
||||
IkarusPropertyScope const * scope,
|
||||
void (*blueprint)(IkarusBlueprint const *, void *),
|
||||
void (*entity)(IkarusEntity const *, void *),
|
||||
void * data
|
||||
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;
|
||||
switch (scope._type) {
|
||||
case IkarusPropertyScopeType_Blueprint: blueprint(scope._data._blueprint, data); break;
|
||||
case IkarusPropertyScopeType_Entity: entity(scope._data._entity, data); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,40 +58,40 @@ IkarusEntityScope ikarus_entity_scope_create() {
|
|||
return IkarusEntityScope{._dummy = 0};
|
||||
}
|
||||
|
||||
IkarusObjectScope ikarus_entity_scope_to_object_scope(IkarusEntityScope const * scope) {
|
||||
IkarusObjectScope ikarus_entity_scope_to_object_scope(IkarusEntityScope scope) {
|
||||
IkarusObjectScopeData data{};
|
||||
data._entity = *scope;
|
||||
data._entity = scope;
|
||||
|
||||
return IkarusObjectScope{._type = IkarusObjectScopeType_Entity, ._data = data};
|
||||
}
|
||||
|
||||
IkarusObjectScopeType ikarus_object_scope_get_type(IkarusObjectScope const * scope) {
|
||||
return scope->_type;
|
||||
IkarusObjectScopeType ikarus_object_scope_get_type(IkarusObjectScope scope) {
|
||||
return scope._type;
|
||||
}
|
||||
|
||||
void ikarus_object_scope_visit(
|
||||
IkarusObjectScope const * scope,
|
||||
void (*blueprint)(IkarusBlueprintScope const *, void *),
|
||||
void (*property)(IkarusPropertyScope const *, void *),
|
||||
void (*entity)(IkarusEntityScope const *, void *),
|
||||
IkarusObjectScope scope,
|
||||
void(blueprint)(IkarusBlueprintScope, void *),
|
||||
void(property)(IkarusPropertyScope, void *),
|
||||
void(entity)(IkarusEntityScope, void *),
|
||||
void * data
|
||||
) {
|
||||
switch (scope->_type) {
|
||||
switch (scope._type) {
|
||||
case IkarusObjectScopeType_Blueprint: {
|
||||
if (blueprint != nullptr) {
|
||||
blueprint(&scope->_data._blueprint, data);
|
||||
blueprint(scope._data._blueprint, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusObjectScopeType_Property: {
|
||||
if (property != nullptr) {
|
||||
property(&scope->_data._property, data);
|
||||
property(scope._data._property, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IkarusObjectScopeType_Entity: {
|
||||
if (entity != nullptr) {
|
||||
entity(&scope->_data._entity, data);
|
||||
entity(scope._data._entity, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -96,7 +100,7 @@ void ikarus_object_scope_visit(
|
|||
|
||||
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);
|
||||
auto blueprint_object_scope = ikarus_blueprint_scope_to_object_scope(blueprint_scope);
|
||||
REQUIRE(blueprint_object_scope._type == IkarusObjectScopeType_Blueprint);
|
||||
}
|
||||
|
||||
|
|
@ -104,24 +108,24 @@ 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);
|
||||
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);
|
||||
REQUIRE(ikarus_property_scope_get_type(property_blueprint_scope) == IkarusPropertyScopeType_Blueprint);
|
||||
REQUIRE(ikarus_property_scope_get_type(property_entity_scope) == IkarusPropertyScopeType_Entity);
|
||||
}
|
||||
|
||||
TEST_CASE("property_object_scope_conversion", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
auto entity = IkarusEntity{};
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -130,24 +134,24 @@ 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);
|
||||
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 const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusEntity const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
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 const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusEntity const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
property_entity_scope,
|
||||
[](IkarusBlueprint, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusEntity, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
&test
|
||||
);
|
||||
|
||||
|
|
@ -156,7 +160,7 @@ TEST_CASE("property_scope_visiting", "[object_scope]") {
|
|||
|
||||
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);
|
||||
auto entity_object_scope = ikarus_entity_scope_to_object_scope(entity_scope);
|
||||
REQUIRE(entity_object_scope._type == IkarusObjectScopeType_Entity);
|
||||
}
|
||||
|
||||
|
|
@ -164,28 +168,28 @@ 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 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);
|
||||
|
||||
REQUIRE(ikarus_object_scope_get_type(&blueprint_object_scope) == IkarusObjectScopeType_Blueprint);
|
||||
REQUIRE(ikarus_object_scope_get_type(&property_object_scope) == IkarusObjectScopeType_Property);
|
||||
REQUIRE(ikarus_object_scope_get_type(&entity_object_scope) == IkarusObjectScopeType_Entity);
|
||||
REQUIRE(ikarus_object_scope_get_type(blueprint_object_scope) == IkarusObjectScopeType_Blueprint);
|
||||
REQUIRE(ikarus_object_scope_get_type(property_object_scope) == IkarusObjectScopeType_Property);
|
||||
REQUIRE(ikarus_object_scope_get_type(entity_object_scope) == IkarusObjectScopeType_Entity);
|
||||
}
|
||||
|
||||
TEST_CASE("object_scope_visiting", "[object_scope]") {
|
||||
auto blueprint = IkarusBlueprint{};
|
||||
|
||||
auto blueprint_scope = ikarus_blueprint_scope_create();
|
||||
auto property_scope = ikarus_property_scope_create_blueprint(&blueprint);
|
||||
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),
|
||||
|
|
@ -197,10 +201,10 @@ TEST_CASE("object_scope_visiting", "[object_scope]") {
|
|||
int test = 0;
|
||||
|
||||
ikarus_object_scope_visit(
|
||||
&scope,
|
||||
[](IkarusBlueprintScope const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusPropertyScope const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
[](IkarusEntityScope const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 3; },
|
||||
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; },
|
||||
&test
|
||||
);
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#include <ikarus/types/object_type.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
IkarusObjectType ikarus_folder_type_to_object_type(IkarusFolderType type) {
|
||||
return static_cast<IkarusObjectType>(type);
|
||||
}
|
||||
|
||||
IkarusObjectTypes ikarus_object_type_to_bitset(IkarusObjectType type) {
|
||||
if (type == 0) {
|
||||
return static_cast<IkarusObjectTypes>(0);
|
||||
}
|
||||
|
||||
return static_cast<IkarusObjectTypes>(1 << 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);
|
||||
}
|
||||
|
||||
TEST_CASE("object_type_to_bitset_conversion", "[object_type]") {
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_None) == IkarusObjectTypes_None);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_Blueprint) == IkarusObjectTypes_Blueprint);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_Property) == IkarusObjectTypes_Property);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_Entity) == IkarusObjectTypes_Entity);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_BlueprintFolder) == IkarusObjectTypes_BlueprintFolder);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_PropertyFolder) == IkarusObjectTypes_PropertyFolder);
|
||||
REQUIRE(ikarus_object_type_to_bitset(IkarusObjectType_EntityFolder) == IkarusObjectTypes_EntityFolder);
|
||||
}
|
||||
|
|
@ -1,10 +1,16 @@
|
|||
#include "ikarus/types/value.h"
|
||||
#include "ikarus/values/value.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/property.h>
|
||||
|
||||
/// \brief Creates an indeterminate entity value of a given type.
|
||||
/// \param type The type of the value.
|
||||
/// \return The entity value.
|
||||
|
|
@ -39,7 +45,7 @@ IkarusEntityValue ikarus_value_create_number(long double value) {
|
|||
IkarusEntityValue ikarus_value_create_text(char const * value) {
|
||||
if (value == nullptr) {
|
||||
return value_create_invalid(IkarusPropertyType_Text);
|
||||
};
|
||||
}
|
||||
|
||||
return IkarusEntityValue{
|
||||
._type = IkarusPropertyType_Text,
|
||||
|
|
@ -326,9 +332,9 @@ TEST_CASE("visit_value", "[value]") {
|
|||
|
||||
ikarus_value_visit(
|
||||
&value,
|
||||
[](IkarusToggleValue const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusNumberValue const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
[](IkarusTextValue const * _, void * data) { *reinterpret_cast<decltype(test) *>(data) = 3; },
|
||||
[](IkarusToggleValue const *, void * data) { *reinterpret_cast<decltype(test) *>(data) = 1; },
|
||||
[](IkarusNumberValue const *, void * data) { *reinterpret_cast<decltype(test) *>(data) = 2; },
|
||||
[](IkarusTextValue const *, void * data) { *reinterpret_cast<decltype(test) *>(data) = 3; },
|
||||
&test
|
||||
);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue