Преглед изворни кода

meta_any:
* set is necessarily non-const
* added non-const overloads for get and invoke

Michele Caini пре 5 година
родитељ
комит
1a3304a886
1 измењених фајлова са 21 додато и 3 уклоњено
  1. 21 3
      src/entt/meta/meta.hpp

+ 21 - 3
src/entt/meta/meta.hpp

@@ -239,7 +239,7 @@ public:
      * @brief Move constructor.
      * @param other The instance to move from.
      */
-    meta_any(meta_any &&other)
+    meta_any(meta_any &&other) ENTT_NOEXCEPT
         : meta_any{}
     {
         swap(*this, other);
@@ -294,6 +294,10 @@ public:
     template<typename... Args>
     meta_any invoke(const id_type id, Args &&... args) const;
 
+    /*! @copydoc invoke */
+    template<typename... Args>
+    meta_any invoke(const id_type id, Args &&... args);
+
     /**
      * @brief Sets the value of a given variable.
      *
@@ -306,7 +310,7 @@ public:
      * @return True in case of success, false otherwise.
      */
     template<typename Type>
-    bool set(const id_type id, Type &&value) const;
+    bool set(const id_type id, Type &&value);
 
     /**
      * @brief Gets the value of a given variable.
@@ -315,6 +319,9 @@ public:
      */
     [[nodiscard]] meta_any get(const id_type id) const;
 
+    /*! @copydoc get */
+    [[nodiscard]] meta_any get(const id_type id);
+
     /**
      * @brief Tries to cast an instance to a given type.
      * @tparam Type Type to which to cast the instance.
@@ -1581,8 +1588,14 @@ meta_any meta_any::invoke(const id_type id, Args &&... args) const {
 }
 
 
+template<typename... Args>
+meta_any meta_any::invoke(const id_type id, Args &&... args) {
+    return type().invoke(id, *this, std::forward<Args>(args)...);
+}
+
+
 template<typename Type>
-bool meta_any::set(const id_type id, Type &&value) const {
+bool meta_any::set(const id_type id, Type &&value) {
     return type().set(id, *this, std::forward<Type>(value));
 }
 
@@ -1592,6 +1605,11 @@ bool meta_any::set(const id_type id, Type &&value) const {
 }
 
 
+[[nodiscard]] inline meta_any meta_any::get(const id_type id) {
+    return type().get(id, *this);
+}
+
+
 [[nodiscard]] inline meta_type meta_base::parent() const ENTT_NOEXCEPT {
     return node->parent;
 }