object type interface

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
Folling 2023-08-25 08:52:34 +02:00 committed by Folling
parent 27d603519b
commit d33190b204
No known key found for this signature in database
2 changed files with 55 additions and 13 deletions

View file

@ -9,39 +9,40 @@ IKARUS_BEGIN_HEADER
/// @{ /// @{
/// \brief The type of a folder. /// \brief The type of a folder.
/// \remark folders have the first bit set and then mirror the object type of the underlying object /// \remark These values are identical to the associated values of IkarusObjectType.
enum IkarusFolderType { enum IkarusFolderType {
/// \brief Not a folder or no folder. /// \brief Not a folder or no folder.
IkarusFolderType_None = 0, IkarusFolderType_None = 0,
/// \brief An IkarusBlueprintFolder /// \brief An IkarusBlueprintFolder
IkarusFolderType_BlueprintFolder = 0b1000'0001, IkarusFolderType_BlueprintFolder = 17,
/// \brief An IkarusPropertyFolder /// \brief An IkarusPropertyFolder
IkarusFolderType_PropertyFolder = 0b1000'0010, IkarusFolderType_PropertyFolder = 18,
/// \brief An IkarusEntityFolder /// \brief An IkarusEntityFolder
IkarusFolderType_EntityFolder = 0b1000'0011, IkarusFolderType_EntityFolder = 19,
}; };
/// \brief The type of an object. /// \brief The type of an object.
/// \remark folders have the first bit set and then mirror the object type of the underlying object /// \remark Folders have the 4th bit set.
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. /// \brief An IkarusBlueprint.
IkarusObjectType_Blueprint = 0b0000'0001, IkarusObjectType_Blueprint = 1,
/// \brief An IkarusProperty. /// \brief An IkarusProperty.
IkarusObjectType_Property = 0b0000'0010, IkarusObjectType_Property = 2,
/// \brief An IkarusEntity. /// \brief An IkarusEntity.
IkarusObjectType_Entity = 0b0000'0011, IkarusObjectType_Entity = 3,
/// \brief An IkarusBlueprintFolder /// \brief An IkarusBlueprintFolder
IkarusObjectType_BlueprintFolder = 0b1000'0001, IkarusObjectType_BlueprintFolder = IkarusFolderType_BlueprintFolder,
/// \brief An IkarusPropertyFolder /// \brief An IkarusPropertyFolder
IkarusObjectType_PropertyFolder = 0b1000'0010, IkarusObjectType_PropertyFolder = IkarusFolderType_PropertyFolder,
/// \brief An IkarusEntityFolder /// \brief An IkarusEntityFolder
IkarusObjectType_EntityFolder = 0b1000'0011, IkarusObjectType_EntityFolder = IkarusFolderType_EntityFolder,
}; };
// because of the nature of bitsets, the largest possible object-type is 31
/// \brief A bitset of IkarusObjectType%s. /// \brief A bitset of IkarusObjectType%s.
enum ObjectTypes { enum IkarusObjectTypes {
/// \brief No object type. /// \brief No object type.
IkarusObjectTypes_None = 0, IkarusObjectTypes_None = 0,
/// \brief An IkarusBlueprint. /// \brief An IkarusBlueprint.
@ -58,6 +59,15 @@ enum ObjectTypes {
IkarusObjectTypes_EntityFolder = 1 << IkarusObjectType_EntityFolder, IkarusObjectTypes_EntityFolder = 1 << IkarusObjectType_EntityFolder,
}; };
/// \brief Converts an IkarusFolderType to an IkarusObjectType.
/// \param type The IkarusFolderType to convert.
/// \return The converted IkarusObjectType, representing the folder type.
IKA_API IkarusObjectType ikarus_folder_type_to_object_type(IkarusFolderType type);
/// \brief Converts an IkarusObjectType to a bitset of IkarusObjectTypes.
/// \param type The IkarusObjectType to convert.
/// \return The converted IkarusObjectTypes, representing the object type.
IKA_API IkarusObjectTypes ikarus_object_type_to_bitset(IkarusObjectType type);
// @} // @}
IKARUS_END_HEADER IKARUS_END_HEADER

32
src/types/object_type.cpp Normal file
View file

@ -0,0 +1,32 @@
#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);
}