a few changes to the meta system

This commit is contained in:
Michele Caini
2018-10-15 15:29:40 +02:00
parent 09e0d2d15b
commit a86ba1fdf6
4 changed files with 76 additions and 53 deletions

1
TODO
View File

@@ -14,6 +14,7 @@
* work stealing job system (see #100)
* composable looper so as to pack erased systems, compose runners at different rates and run them at once in the loop
* meta: sort of meta view based on meta stuff to iterate entities, void * and meta info objects
* meta: move-to-head optimization when searching by name on parts (data, func, etc)
* registry::probe<component>(entt) (returns a component * if entt has the component, nullptr otherwise)
* hashed string: add implicit check on construction for uniqueness (optional)
* add a note about multithreading support to the README file

View File

@@ -33,7 +33,7 @@ meta_factory<Type> reflect(const char *str, Property &&... property) ENTT_NOEXCE
*/
template<typename Type>
class meta_factory {
static_assert((std::is_scalar_v<Type> || std::is_class_v<Type>) && !std::is_const_v<Type>);
static_assert(std::is_object_v<Type> && !(std::is_const_v<Type> || std::is_volatile_v<Type>));
template<auto Data>
static std::enable_if_t<std::is_member_object_pointer_v<decltype(Data)>, decltype(std::declval<Type>().*Data)>
@@ -91,15 +91,18 @@ class meta_factory {
internal::meta_info<>::type,
properties<Type>(std::forward<Property>(property)...),
std::is_void_v<Type>,
std::is_integral_v<Type>,
std::is_floating_point_v<Type>,
std::is_enum_v<Type>,
std::is_union_v<Type>,
std::is_class_v<Type>,
std::is_pointer_v<Type>,
std::is_pointer_v<Type> && std::is_function_v<std::remove_pointer_t<Type>>,
std::is_function_v<Type>,
std::is_member_object_pointer_v<Type>,
std::is_member_function_pointer_v<Type>,
std::is_member_pointer_v<Type>,
std::is_arithmetic_v<Type>,
std::is_compound_v<Type>,
[]() -> meta_type {
return internal::meta_info<std::remove_pointer_t<Type>>::resolve();
},
&internal::destroy<Type>,
[]() -> meta_type {
return &node;

View File

@@ -120,15 +120,16 @@ struct meta_type_node final {
meta_type_node * const next;
meta_prop_node * const prop;
const bool is_void;
const bool is_integral;
const bool is_floating_point;
const bool is_enum;
const bool is_union;
const bool is_class;
const bool is_pointer;
const bool is_function_pointer;
const bool is_function;
const bool is_member_object_pointer;
const bool is_member_function_pointer;
const bool is_member_pointer;
const bool is_arithmetic;
const bool is_compound;
meta_type(* const remove_pointer)();
bool(* const destroy)(meta_handle);
meta_type(* const meta)();
meta_base_node *base;
@@ -1534,6 +1535,25 @@ public:
return node->is_void;
}
/**
* @brief Indicates whether a given meta type refers to an integral type or
* not.
* @return True if the underlying type is an integral type, false otherwise.
*/
inline bool is_integral() const ENTT_NOEXCEPT {
return node->is_integral;
}
/**
* @brief Indicates whether a given meta type refers to a floating-point
* type or not.
* @return True if the underlying type is a floating-point type, false
* otherwise.
*/
inline bool is_floating_point() const ENTT_NOEXCEPT {
return node->is_floating_point;
}
/**
* @brief Indicates whether a given meta type refers to an enum or not.
* @return True if the underlying type is an enum, false otherwise.
@@ -1542,6 +1562,14 @@ public:
return node->is_enum;
}
/**
* @brief Indicates whether a given meta type refers to an union or not.
* @return True if the underlying type is an union, false otherwise.
*/
inline bool is_union() const ENTT_NOEXCEPT {
return node->is_union;
}
/**
* @brief Indicates whether a given meta type refers to a class or not.
* @return True if the underlying type is a class, false otherwise.
@@ -1559,13 +1587,12 @@ public:
}
/**
* @brief Indicates whether a given meta type refers to a function pointer
* or not.
* @return True if the underlying type is a function pointer, false
* otherwise.
* @brief Indicates whether a given meta type refers to a function type or
* not.
* @return True if the underlying type is a function, false otherwise.
*/
inline bool is_function_pointer() const ENTT_NOEXCEPT {
return node->is_function_pointer;
inline bool is_function() const ENTT_NOEXCEPT {
return node->is_function;
}
/**
@@ -1589,32 +1616,12 @@ public:
}
/**
* @brief Indicates whether a given meta type refers to a pointer to member
* or not.
* @return True if the underlying type is a pointer to member, false
* otherwise.
* @brief Provides the meta type for which the pointer is defined.
* @return The meta type for which the pointer is defined or this meta type
* if it doesn't refer to a pointer type.
*/
inline bool is_member_pointer() const ENTT_NOEXCEPT {
return node->is_member_pointer;
}
/**
* @brief Indicates whether a given meta type refers to an arithmetic type
* or not.
* @return True if the underlying type is an arithmetic type, false
* otherwise.
*/
inline bool is_arithmetic() const ENTT_NOEXCEPT {
return node->is_arithmetic;
}
/**
* @brief Indicates whether a given meta type refers to a compound type or
* not.
* @return True if the underlying type is a compound type, false otherwise.
*/
inline bool is_compound() const ENTT_NOEXCEPT {
return node->is_compound;
inline meta_type remove_pointer() const ENTT_NOEXCEPT {
return node->remove_pointer();
}
/**
@@ -2020,12 +2027,12 @@ struct meta_function_helper<std::integral_constant<decltype(Func), Func>>: declt
template<typename Type>
inline bool destroy([[maybe_unused]] meta_handle handle) {
if constexpr(std::is_void_v<Type>) {
return false;
} else {
if constexpr(std::is_object_v<Type>) {
return handle.type() == meta_info<Type>::resolve()->meta()
? (static_cast<Type *>(handle.data())->~Type(), true)
: false;
} else {
return false;
}
}
@@ -2129,23 +2136,24 @@ invoke(meta_handle &handle, meta_any *args, std::index_sequence<Indexes...>) {
template<typename Type>
meta_type_node * meta_node<Type>::resolve() ENTT_NOEXCEPT {
static_assert((std::is_scalar_v<Type> || std::is_class_v<Type> || std::is_void_v<Type>) && !std::is_const_v<Type>);
if(!type) {
static meta_type_node node{
{},
nullptr,
nullptr,
std::is_void_v<Type>,
std::is_integral_v<Type>,
std::is_floating_point_v<Type>,
std::is_enum_v<Type>,
std::is_union_v<Type>,
std::is_class_v<Type>,
std::is_pointer_v<Type>,
std::is_pointer_v<Type> && std::is_function_v<std::remove_pointer_t<Type>>,
std::is_function_v<Type>,
std::is_member_object_pointer_v<Type>,
std::is_member_function_pointer_v<Type>,
std::is_member_pointer_v<Type>,
std::is_arithmetic_v<Type>,
std::is_compound_v<Type>,
[]() -> meta_type {
return internal::meta_info<std::remove_pointer_t<Type>>::resolve();
},
&destroy<Type>,
[]() -> meta_type {
return &node;

View File

@@ -35,6 +35,11 @@ struct fat_type: empty_type {
}
};
union union_type {
int i;
double d;
};
bool operator!=(const fat_type &lhs, const fat_type &rhs) {
return !(lhs == rhs);
}
@@ -1106,15 +1111,21 @@ TEST_F(Meta, MetaType) {
TEST_F(Meta, MetaTypeTraits) {
ASSERT_TRUE(entt::resolve<void>().is_void());
ASSERT_TRUE(entt::resolve<bool>().is_integral());
ASSERT_TRUE(entt::resolve<double>().is_floating_point());
ASSERT_TRUE(entt::resolve<properties>().is_enum());
ASSERT_TRUE(entt::resolve<union_type>().is_union());
ASSERT_TRUE(entt::resolve<derived_type>().is_class());
ASSERT_TRUE(entt::resolve<int *>().is_pointer());
ASSERT_TRUE(entt::resolve<decltype(&empty_type::destroy)>().is_function_pointer());
ASSERT_TRUE(entt::resolve<decltype(empty_type::destroy)>().is_function());
ASSERT_TRUE(entt::resolve<decltype(&data_type::i)>().is_member_object_pointer());
ASSERT_TRUE(entt::resolve<decltype(&func_type::g)>().is_member_function_pointer());
ASSERT_TRUE(entt::resolve<decltype(&data_type::j)>().is_member_pointer());
ASSERT_TRUE(entt::resolve<bool>().is_arithmetic());
ASSERT_TRUE(entt::resolve<properties>().is_compound());
}
TEST_F(Meta, MetaTypeRemovePointer) {
ASSERT_EQ(entt::resolve<void *>().remove_pointer(), entt::resolve<void>());
ASSERT_EQ(entt::resolve<int(*)(char, double)>().remove_pointer(), entt::resolve<int(char, double)>());
ASSERT_EQ(entt::resolve<int>().remove_pointer(), entt::resolve<int>());
}
TEST_F(Meta, MetaTypeBase) {