meta: use enum-as-bitmask support to get rid of old fashioned enum for meta traits

This commit is contained in:
Michele Caini
2021-08-05 10:44:13 +02:00
parent 4b629045c3
commit 7b35bcb68a
2 changed files with 27 additions and 25 deletions

View File

@@ -819,7 +819,7 @@ struct meta_data {
* @return True if the data member is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_CONST);
return !!(node->traits & internal::meta_traits::IS_CONST);
}
/**
@@ -827,7 +827,7 @@ struct meta_data {
* @return True if the data member is static, false otherwise.
*/
[[nodiscard]] bool is_static() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_STATIC);
return !!(node->traits & internal::meta_traits::IS_STATIC);
}
/*! @copydoc meta_any::type */
@@ -928,7 +928,7 @@ struct meta_func {
* @return True if the member function is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_CONST);
return !!(node->traits & internal::meta_traits::IS_CONST);
}
/**
@@ -936,7 +936,7 @@ struct meta_func {
* @return True if the member function is static, false otherwise.
*/
[[nodiscard]] bool is_static() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_STATIC);
return !!(node->traits & internal::meta_traits::IS_STATIC);
}
/**
@@ -1103,7 +1103,7 @@ public:
* @return True if the underlying type is an integral type, false otherwise.
*/
[[nodiscard]] bool is_integral() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_INTEGRAL);
return !!(node->traits & internal::meta_traits::IS_INTEGRAL);
}
/**
@@ -1112,7 +1112,7 @@ public:
* otherwise.
*/
[[nodiscard]] bool is_floating_point() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_FLOATING_POINT);
return !!(node->traits & internal::meta_traits::IS_FLOATING_POINT);
}
/**
@@ -1120,7 +1120,7 @@ public:
* @return True if the underlying type is an array type, false otherwise.
*/
[[nodiscard]] bool is_array() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_ARRAY);
return !!(node->traits & internal::meta_traits::IS_ARRAY);
}
/**
@@ -1128,7 +1128,7 @@ public:
* @return True if the underlying type is an enum, false otherwise.
*/
[[nodiscard]] bool is_enum() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_ENUM);
return !!(node->traits & internal::meta_traits::IS_ENUM);
}
/**
@@ -1136,7 +1136,7 @@ public:
* @return True if the underlying type is an union, false otherwise.
*/
[[nodiscard]] bool is_union() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_UNION);
return !!(node->traits & internal::meta_traits::IS_UNION);
}
/**
@@ -1144,7 +1144,7 @@ public:
* @return True if the underlying type is a class, false otherwise.
*/
[[nodiscard]] bool is_class() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_CLASS);
return !!(node->traits & internal::meta_traits::IS_CLASS);
}
/**
@@ -1152,7 +1152,7 @@ public:
* @return True if the underlying type is a pointer, false otherwise.
*/
[[nodiscard]] bool is_pointer() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_POINTER);
return !!(node->traits & internal::meta_traits::IS_POINTER);
}
/**
@@ -1161,7 +1161,7 @@ public:
* otherwise.
*/
[[nodiscard]] bool is_member_object_pointer() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_MEMBER_OBJECT_POINTER);
return !!(node->traits & internal::meta_traits::IS_MEMBER_OBJECT_POINTER);
}
/**
@@ -1171,7 +1171,7 @@ public:
* false otherwise.
*/
[[nodiscard]] bool is_member_function_pointer() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_MEMBER_FUNCTION_POINTER);
return !!(node->traits & internal::meta_traits::IS_MEMBER_FUNCTION_POINTER);
}
/**
@@ -1180,7 +1180,7 @@ public:
* otherwise.
*/
[[nodiscard]] bool is_pointer_like() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_META_POINTER_LIKE);
return !!(node->traits & internal::meta_traits::IS_META_POINTER_LIKE);
}
/**
@@ -1188,7 +1188,7 @@ public:
* @return True if the type is a sequence container, false otherwise.
*/
[[nodiscard]] bool is_sequence_container() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_META_SEQUENCE_CONTAINER);
return !!(node->traits & internal::meta_traits::IS_META_SEQUENCE_CONTAINER);
}
/**
@@ -1196,7 +1196,7 @@ public:
* @return True if the type is an associative container, false otherwise.
*/
[[nodiscard]] bool is_associative_container() const ENTT_NOEXCEPT {
return (node->traits & internal::meta_traits::IS_META_ASSOCIATIVE_CONTAINER);
return !!(node->traits & internal::meta_traits::IS_META_ASSOCIATIVE_CONTAINER);
}
/**

View File

@@ -7,6 +7,7 @@
#include <utility>
#include "../config/config.h"
#include "../core/attribute.h"
#include "../core/enum.hpp"
#include "../core/fwd.hpp"
#include "../core/type_info.hpp"
#include "../core/type_traits.hpp"
@@ -30,7 +31,7 @@ struct meta_handle;
namespace internal {
enum meta_traits: std::uint32_t {
enum class meta_traits: std::uint32_t {
IS_NONE = 0x0000,
IS_CONST = 0x0001,
IS_STATIC = 0x0002,
@@ -41,11 +42,12 @@ enum meta_traits: std::uint32_t {
IS_UNION = 0x0040,
IS_CLASS = 0x0080,
IS_POINTER = 0x0100,
IS_MEMBER_OBJECT_POINTER = 0x0400,
IS_MEMBER_FUNCTION_POINTER = 0x0800,
IS_META_POINTER_LIKE = 0x1000,
IS_META_SEQUENCE_CONTAINER = 0x2000,
IS_META_ASSOCIATIVE_CONTAINER = 0x4000
IS_MEMBER_OBJECT_POINTER = 0x0200,
IS_MEMBER_FUNCTION_POINTER = 0x0400,
IS_META_POINTER_LIKE = 0x0800,
IS_META_SEQUENCE_CONTAINER = 0x1000,
IS_META_ASSOCIATIVE_CONTAINER = 0x2000,
_entt_enum_as_bitmask
};
@@ -87,7 +89,7 @@ struct meta_data_node {
id_type id;
meta_data_node * next;
meta_prop_node * prop;
std::underlying_type_t<meta_traits> traits;
meta_traits traits;
meta_type_node * const type;
bool(* const set)(meta_handle, meta_any);
meta_any(* const get)(meta_handle);
@@ -100,7 +102,7 @@ struct meta_func_node {
meta_func_node * next;
meta_prop_node * prop;
const size_type arity;
std::underlying_type_t<meta_traits> traits;
meta_traits traits;
meta_type_node * const ret;
meta_type(* const arg)(const size_type) ENTT_NOEXCEPT;
meta_any(* const invoke)(meta_handle, meta_any * const);
@@ -122,7 +124,7 @@ struct meta_type_node {
meta_type_node * next;
meta_prop_node * prop;
const size_type size_of;
std::underlying_type_t<meta_traits> traits;
meta_traits traits;
const meta_template_node *const templ;
meta_ctor_node * const def_ctor;
meta_ctor_node *ctor{nullptr};