[Bf-blender-cvs] [3d16a8193f8] functions: improved debug error checking

Jacques Lucke noreply at git.blender.org
Thu Nov 21 15:19:30 CET 2019


Commit: 3d16a8193f854f501543b93b4a938426a6192e4f
Author: Jacques Lucke
Date:   Tue Nov 19 10:49:34 2019 +0100
Branches: functions
https://developer.blender.org/rB3d16a8193f854f501543b93b4a938426a6192e4f

improved debug error checking

===================================================================

M	source/blender/functions/FN_generic_virtual_list_list_ref.h
M	source/blender/functions/FN_generic_virtual_list_ref.h
M	source/blender/functions/FN_multi_function.h

===================================================================

diff --git a/source/blender/functions/FN_generic_virtual_list_list_ref.h b/source/blender/functions/FN_generic_virtual_list_list_ref.h
index 54d01bb3fdb..7a309780bb7 100644
--- a/source/blender/functions/FN_generic_virtual_list_list_ref.h
+++ b/source/blender/functions/FN_generic_virtual_list_list_ref.h
@@ -76,6 +76,11 @@ class GenericVirtualListListRef {
     return m_virtual_list_size;
   }
 
+  const CPPType &type() const
+  {
+    return *m_type;
+  }
+
   GenericVirtualListRef operator[](uint index) const
   {
     BLI_assert(index < m_virtual_list_size);
diff --git a/source/blender/functions/FN_generic_virtual_list_ref.h b/source/blender/functions/FN_generic_virtual_list_ref.h
index f8543c0a04f..7bb38edc992 100644
--- a/source/blender/functions/FN_generic_virtual_list_ref.h
+++ b/source/blender/functions/FN_generic_virtual_list_ref.h
@@ -128,6 +128,11 @@ class GenericVirtualListRef {
     return m_virtual_size;
   }
 
+  const CPPType &type() const
+  {
+    return *m_type;
+  }
+
   const void *operator[](uint index) const
   {
     BLI_assert(index < m_virtual_size);
diff --git a/source/blender/functions/FN_multi_function.h b/source/blender/functions/FN_multi_function.h
index b8eb3a366a1..59fa0be5d04 100644
--- a/source/blender/functions/FN_multi_function.h
+++ b/source/blender/functions/FN_multi_function.h
@@ -217,57 +217,88 @@ class MFParamsBuilder {
 
   template<typename T> void add_readonly_single_input(ArrayRef<T> array)
   {
-    BLI_assert(array.size() >= m_min_array_size);
-    m_virtual_list_refs.append(GenericVirtualListRef::FromFullArray<T>(array));
+    this->add_readonly_single_input(GenericVirtualListRef::FromFullArray<T>(array));
   }
 
   template<typename T> void add_readonly_single_input(const T *value)
   {
-    m_virtual_list_refs.append(
+    this->add_readonly_single_input(
         GenericVirtualListRef::FromSingle(CPP_TYPE<T>(), (void *)value, m_min_array_size));
   }
 
   void add_readonly_single_input(GenericVirtualListRef list)
   {
+    this->assert_current_param_type(MFParamType::ForSingleInput(list.type()));
     BLI_assert(list.size() >= m_min_array_size);
     m_virtual_list_refs.append(list);
   }
 
   void add_readonly_vector_input(GenericVirtualListListRef list)
   {
+    this->assert_current_param_type(MFParamType::ForVectorInput(list.type()));
     BLI_assert(list.size() >= m_min_array_size);
     m_virtual_list_list_refs.append(list);
   }
 
+  template<typename T> void add_single_output(ArrayRef<T> array)
+  {
+    BLI_assert(array.size() >= m_min_array_size);
+    this->add_single_output(GenericMutableArrayRef(array));
+  }
   void add_single_output(GenericMutableArrayRef array)
   {
+    this->assert_current_param_type(MFParamType::ForSingleOutput(array.type()));
     BLI_assert(array.size() >= m_min_array_size);
     m_mutable_array_refs.append(array);
   }
 
   void add_vector_output(GenericVectorArray &vector_array)
   {
+    this->assert_current_param_type(MFParamType::ForVectorOutput(vector_array.type()));
     BLI_assert(vector_array.size() >= m_min_array_size);
     m_vector_arrays.append(&vector_array);
   }
 
-  template<typename T> void add_single_output(ArrayRef<T> array)
-  {
-    BLI_assert(array.size() >= m_min_array_size);
-    m_mutable_array_refs.append(GenericMutableArrayRef(array));
-  }
-
   void add_mutable_vector(GenericVectorArray &vector_array)
   {
+    this->assert_current_param_type(MFParamType::ForVectorMutable(vector_array.type()));
     BLI_assert(vector_array.size() >= m_min_array_size);
     m_vector_arrays.append(&vector_array);
   }
 
   void add_mutable_single(GenericMutableArrayRef array)
   {
+    this->assert_current_param_type(MFParamType::ForSingleMutable(array.type()));
     BLI_assert(array.size() >= m_min_array_size);
     m_mutable_array_refs.append(array);
   }
+
+ private:
+  void assert_current_param_type(MFParamType param_type) const
+  {
+    UNUSED_VARS_NDEBUG(param_type);
+#ifdef DEBUG
+    uint param_index = this->current_param_index();
+    MFParamType expected_type = m_signature->param_types()[param_index];
+    BLI_assert(expected_type == param_type);
+#endif
+  }
+
+  void assert_current_param_type(MFParamType::Type type) const
+  {
+    UNUSED_VARS_NDEBUG(type);
+#ifdef DEBUG
+    uint param_index = this->current_param_index();
+    MFParamType::Type expected_type = m_signature->param_types()[param_index].type();
+    BLI_assert(expected_type == type);
+#endif
+  }
+
+  uint current_param_index() const
+  {
+    return m_mutable_array_refs.size() + m_virtual_list_refs.size() +
+           m_virtual_list_list_refs.size() + m_vector_arrays.size();
+  }
 };
 
 class MFParams {



More information about the Bf-blender-cvs mailing list