Explorar el Código

meta: use the hot/cold model with meta_prop_node

Michele Caini hace 3 años
padre
commit
10755275ea
Se han modificado 3 ficheros con 23 adiciones y 15 borrados
  1. 8 4
      src/entt/meta/factory.hpp
  2. 10 10
      src/entt/meta/meta.hpp
  3. 5 1
      src/entt/meta/range.hpp

+ 8 - 4
src/entt/meta/factory.hpp

@@ -78,12 +78,16 @@ public:
      * @return An extended meta factory for the given type.
      * @return An extended meta factory for the given type.
      */
      */
     template<typename... Value>
     template<typename... Value>
-    meta_factory prop(id_type key, Value &&...value) {
+    meta_factory prop(id_type key, [[maybe_unused]] Value &&...value) {
         internal::meta_details_setup(*node);
         internal::meta_details_setup(*node);
 
 
-        node->details->prop[key] = internal::meta_prop_node{
-            &internal::resolve<std::decay_t<Value>>...,
-            std::make_shared<std::decay_t<Value>>(std::forward<Value>(value))...};
+        if constexpr(sizeof...(Value) == 0u) {
+            node->details->prop[key] = internal::meta_prop_node{&internal::resolve<void>};
+        } else {
+            node->details->prop[key] = internal::meta_prop_node{
+                &internal::resolve<std::decay_t<Value>>...,
+                std::make_shared<std::decay_t<Value>>(std::forward<Value>(value))...};
+        }
 
 
         return *this;
         return *this;
     }
     }

+ 10 - 10
src/entt/meta/meta.hpp

@@ -661,7 +661,7 @@ struct meta_prop {
      * @brief Constructs an instance from a given node.
      * @brief Constructs an instance from a given node.
      * @param curr The underlying node with which to construct the instance.
      * @param curr The underlying node with which to construct the instance.
      */
      */
-    meta_prop(const node_type *curr = nullptr) noexcept
+    meta_prop(const node_type &curr = {}) noexcept
         : node{curr} {}
         : node{curr} {}
 
 
     /**
     /**
@@ -669,7 +669,7 @@ struct meta_prop {
      * @return A wrapper containing the value stored with the property.
      * @return A wrapper containing the value stored with the property.
      */
      */
     [[nodiscard]] meta_any value() const {
     [[nodiscard]] meta_any value() const {
-        return (node && node->type) ? node->type()->from_void(nullptr, node->value.get()) : meta_any{};
+        return node.value ? node.type()->from_void(nullptr, node.value.get()) : meta_any{};
     }
     }
 
 
     /**
     /**
@@ -677,11 +677,11 @@ struct meta_prop {
      * @return True if the object is valid, false otherwise.
      * @return True if the object is valid, false otherwise.
      */
      */
     [[nodiscard]] explicit operator bool() const noexcept {
     [[nodiscard]] explicit operator bool() const noexcept {
-        return !(node == nullptr);
+        return !(node.type == nullptr);
     }
     }
 
 
 private:
 private:
-    const node_type *node;
+    node_type node;
 };
 };
 
 
 /*! @brief Opaque wrapper for data members. */
 /*! @brief Opaque wrapper for data members. */
@@ -780,11 +780,11 @@ struct meta_data {
     [[nodiscard]] meta_prop prop(const id_type key) const {
     [[nodiscard]] meta_prop prop(const id_type key) const {
         if(node->details) {
         if(node->details) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
-                return &it->second;
+                return it->second;
             }
             }
         }
         }
 
 
-        return nullptr;
+        return {};
     }
     }
 
 
     /**
     /**
@@ -898,11 +898,11 @@ struct meta_func {
     [[nodiscard]] meta_prop prop(const id_type key) const {
     [[nodiscard]] meta_prop prop(const id_type key) const {
         if(node->details) {
         if(node->details) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
-                return &it->second;
+                return it->second;
             }
             }
         }
         }
 
 
-        return nullptr;
+        return {};
     }
     }
 
 
     /**
     /**
@@ -1394,7 +1394,7 @@ public:
     [[nodiscard]] meta_prop prop(const id_type key) const {
     [[nodiscard]] meta_prop prop(const id_type key) const {
         if(node->details) {
         if(node->details) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
             if(auto it = node->details->prop.find(key); it != node->details->prop.cend()) {
-                return &it->second;
+                return it->second;
             }
             }
         }
         }
 
 
@@ -1404,7 +1404,7 @@ public:
             }
             }
         }
         }
 
 
-        return nullptr;
+        return {};
     }
     }
 
 
     /**
     /**

+ 5 - 1
src/entt/meta/range.hpp

@@ -25,7 +25,11 @@ class meta_range_iterator final {
 
 
     template<typename Value>
     template<typename Value>
     Type to_value(char, const Value &value) const {
     Type to_value(char, const Value &value) const {
-        return &value;
+        if constexpr(std::is_same_v<std::decay_t<Value>, internal::meta_prop_node>) {
+            return value;
+        } else {
+            return &value;
+        }
     }
     }
 
 
 public:
 public: