Browse Source

component: add basic_component_traits aside component_traits

Michele Caini 4 years ago
parent
commit
2e86c1f1a2

+ 12 - 7
src/entt/entity/component.hpp

@@ -9,17 +9,22 @@
 namespace entt {
 
 
+/*! @brief Commonly used default traits for all types. */
+struct basic_component_traits {
+    /*! @brief Pointer stability, default is `std::false_type`. */
+    using in_place_delete = std::false_type;
+    /*! @brief Empty type optimization, default is `ENTT_IGNORE_IF_EMPTY`. */
+    using ignore_if_empty = ENTT_IGNORE_IF_EMPTY;
+};
+
+
 /**
- * @brief Common way to access various properties of components
+ * @brief Common way to access various properties of components.
  * @tparam Type Type of component.
  */
 template<typename Type, typename = void>
-struct component_traits {
-    static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Type is not decayed");
-    /*! @brief Pointer stable component, default is `std::false_type`. */
-    using in_place_delete = std::false_type;
-    /*! @brief Empty type optimization, default is `ENTT_IGNORE_IF_EMPTY`. */
-    using ignore_if_empty = ENTT_IGNORE_IF_EMPTY;
+struct component_traits: basic_component_traits {
+    static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
 };
 
 

+ 3 - 3
test/entt/entity/registry.cpp

@@ -6,16 +6,16 @@
 #include <type_traits>
 #include <gtest/gtest.h>
 #include <entt/core/type_traits.hpp>
-#include <entt/entity/registry.hpp>
+#include <entt/entity/component.hpp>
 #include <entt/entity/entity.hpp>
+#include <entt/entity/registry.hpp>
 
 struct empty_type {};
 struct stable_type { int value; };
 
 template<>
-struct entt::component_traits<stable_type> {
+struct entt::component_traits<stable_type>: basic_component_traits {
     using in_place_delete = std::true_type;
-    using ignore_if_empty = std::true_type;
 };
 
 struct non_default_constructible {

+ 2 - 2
test/entt/entity/runtime_view.cpp

@@ -2,15 +2,15 @@
 #include <algorithm>
 #include <gtest/gtest.h>
 #include <entt/core/type_info.hpp>
+#include <entt/entity/component.hpp>
 #include <entt/entity/registry.hpp>
 #include <entt/entity/runtime_view.hpp>
 
 struct stable_type { int value; };
 
 template<>
-struct entt::component_traits<stable_type> {
+struct entt::component_traits<stable_type>: basic_component_traits {
     using in_place_delete = std::true_type;
-    using ignore_if_empty = std::true_type;
 };
 
 TEST(RuntimeView, Functionalities) {

+ 1 - 2
test/entt/entity/storage.cpp

@@ -16,9 +16,8 @@ struct boxed_int { int value; };
 struct stable_type { int value; };
 
 template<>
-struct entt::component_traits<stable_type> {
+struct entt::component_traits<stable_type>: basic_component_traits {
     using in_place_delete = std::true_type;
-    using ignore_if_empty = std::true_type;
 };
 
 bool operator==(const boxed_int &lhs, const boxed_int &rhs) {

+ 2 - 2
test/entt/entity/view.cpp

@@ -3,6 +3,7 @@
 #include <utility>
 #include <type_traits>
 #include <gtest/gtest.h>
+#include <entt/entity/component.hpp>
 #include <entt/entity/registry.hpp>
 #include <entt/entity/view.hpp>
 
@@ -10,9 +11,8 @@ struct empty_type {};
 struct stable_type { int value; };
 
 template<>
-struct entt::component_traits<stable_type> {
+struct entt::component_traits<stable_type>: basic_component_traits {
     using in_place_delete = std::true_type;
-    using ignore_if_empty = std::true_type;
 };
 
 TEST(SingleComponentView, Functionalities) {