[Bf-blender-cvs] [28c554ec270] functions: initial static class id system

Jacques Lucke noreply at git.blender.org
Wed Dec 11 10:53:46 CET 2019


Commit: 28c554ec2705570bf3664e60777e6a599811b9fb
Author: Jacques Lucke
Date:   Wed Dec 11 10:50:08 2019 +0100
Branches: functions
https://developer.blender.org/rB28c554ec2705570bf3664e60777e6a599811b9fb

initial static class id system

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

A	source/blender/blenlib/BLI_static_class_ids.h
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/functions/FN_multi_function_context.h
M	source/blender/functions/intern/multi_function_common_contexts.cc

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

diff --git a/source/blender/blenlib/BLI_static_class_ids.h b/source/blender/blenlib/BLI_static_class_ids.h
new file mode 100644
index 00000000000..40bac7f6163
--- /dev/null
+++ b/source/blender/blenlib/BLI_static_class_ids.h
@@ -0,0 +1,26 @@
+#ifndef __BLI_STATIC_CLASS_IDS_H__
+#define __BLI_STATIC_CLASS_IDS_H__
+
+#include "BLI_utildefines.h"
+
+namespace BLI {
+
+using class_id_t = uintptr_t;
+
+template<typename T> class_id_t get_class_id();
+
+}  // namespace BLI
+
+#define BLI_CREATE_CLASS_ID_UTIL1(class_name, id) \
+  static char class_id_char##id = 0; \
+  static BLI::class_id_t class_id##id = (BLI::class_id_t)&class_id_char##id; \
+  template<> BLI::class_id_t BLI::get_class_id<class_name>() \
+  { \
+    return class_id##id; \
+  }
+
+#define BLI_CREATE_CLASS_ID_UTIL2(class_name, id) BLI_CREATE_CLASS_ID_UTIL1(class_name, id)
+
+#define BLI_CREATE_CLASS_ID(class_name) BLI_CREATE_CLASS_ID_UTIL2(class_name, __LINE__)
+
+#endif /* __BLI_STATIC_CLASS_IDS_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index fb088d23f48..83953396cfa 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -272,6 +272,7 @@ set(SRC
   BLI_vector_adaptor.h
   BLI_multi_vector.h
   BLI_utility_mixins.h
+  BLI_static_class_ids.h
 )
 
 set(LIB
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index 966aa6dadfb..d2b1ce358d8 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -7,6 +7,7 @@
 #include "BLI_vector.h"
 #include "BLI_utility_mixins.h"
 #include "BLI_index_range.h"
+#include "BLI_static_class_ids.h"
 
 #include "BKE_id_handle.h"
 
@@ -19,16 +20,6 @@ using BLI::Optional;
 using BLI::Vector;
 using BLI::VirtualListRef;
 
-template<typename T> uintptr_t get_multi_function_element_context_id();
-
-#define FN_MAKE_MF_ELEMENT_CONTEXT(name) \
-  char name##_id_char = 0; \
-  uintptr_t name##_id = (uintptr_t)&name##_id_char; \
-  template<> uintptr_t get_multi_function_element_context_id<name>() \
-  { \
-    return name##_id; \
-  }
-
 class MFElementContexts {
  private:
   Vector<uintptr_t> m_ids;
@@ -47,7 +38,7 @@ class MFElementContexts {
 
   template<typename T> Optional<TypedContext<T>> try_find() const
   {
-    uintptr_t context_id = get_multi_function_element_context_id<T>();
+    uintptr_t context_id = BLI::get_class_id<T>();
     for (uint i : m_contexts.index_iterator()) {
       if (m_ids[i] == context_id) {
         const T *context = (const T *)m_contexts[i];
@@ -74,7 +65,7 @@ class MFContextBuilder : BLI::NonCopyable, BLI::NonMovable {
 
   template<typename T> void add_element_context(const T &context, VirtualListRef<uint> indices)
   {
-    m_element_contexts.m_ids.append(get_multi_function_element_context_id<T>());
+    m_element_contexts.m_ids.append(BLI::get_class_id<T>());
     m_element_contexts.m_contexts.append((const void *)&context);
     m_element_contexts.m_indices.append(indices);
   }
diff --git a/source/blender/functions/intern/multi_function_common_contexts.cc b/source/blender/functions/intern/multi_function_common_contexts.cc
index 1f4ca5c7cd6..265ac7d2492 100644
--- a/source/blender/functions/intern/multi_function_common_contexts.cc
+++ b/source/blender/functions/intern/multi_function_common_contexts.cc
@@ -1,10 +1,10 @@
 #include "FN_multi_function_common_contexts.h"
 
-namespace FN {
+BLI_CREATE_CLASS_ID(FN::VertexPositionArray)
+BLI_CREATE_CLASS_ID(FN::SceneTimeContext)
+BLI_CREATE_CLASS_ID(FN::ParticleAttributesContext)
+BLI_CREATE_CLASS_ID(FN::ExternalDataCacheContext)
 
-FN_MAKE_MF_ELEMENT_CONTEXT(VertexPositionArray)
-FN_MAKE_MF_ELEMENT_CONTEXT(SceneTimeContext)
-FN_MAKE_MF_ELEMENT_CONTEXT(ParticleAttributesContext)
-FN_MAKE_MF_ELEMENT_CONTEXT(ExternalDataCacheContext)
+namespace FN {
 
 }  // namespace FN



More information about the Bf-blender-cvs mailing list