[Bf-blender-cvs] [ba80e27] depsgraph_refactor: Use a generalized functor type for the operation eval callbacks instead of a plain function pointer.

Lukas Tönne noreply at git.blender.org
Sun Jun 8 12:46:55 CEST 2014


Commit: ba80e278ab14488b6ab66934143b3bc70842dddb
Author: Lukas Tönne
Date:   Sun Jun 8 12:38:48 2014 +0200
https://developer.blender.org/rBba80e278ab14488b6ab66934143b3bc70842dddb

Use a generalized functor type for the operation eval callbacks instead
of a plain function pointer.

With std::bind the previous function pointer wrapper is also no longer
needed.

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

M	source/blender/depsgraph/intern/depsgraph_types.h
M	source/blender/depsgraph/intern/depsnode_operation.h
M	source/blender/depsgraph/util/depsgraph_util_function.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index 52b09f3..b565b5a 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -33,6 +33,7 @@
 #ifndef __DEPSGRAPH_TYPES_H__
 #define __DEPSGRAPH_TYPES_H__
 
+#include "depsgraph_util_function.h"
 #include "depsgraph_util_string.h"
 
 struct ChannelDriver;
@@ -45,7 +46,7 @@ struct PointerRNA;
  * < (item): (ComponentDepsNode/PointerRNA) the specific entity involved, where applicable
  */
 // XXX: move this to another header that can be exposed?
-typedef void (*DepsEvalOperationCb)(void *context, PointerRNA *item);
+typedef function<void(void *, PointerRNA *)> DepsEvalOperationCb;
 
 /* Metatype of Nodes - The general "level" in the graph structure the node serves */
 typedef enum eDepsNode_Class {
diff --git a/source/blender/depsgraph/intern/depsnode_operation.h b/source/blender/depsgraph/intern/depsnode_operation.h
index 1464823..12e000b 100644
--- a/source/blender/depsgraph/intern/depsnode_operation.h
+++ b/source/blender/depsgraph/intern/depsnode_operation.h
@@ -47,78 +47,6 @@ struct ID;
 struct Depsgraph;
 struct DepsgraphCopyContext;
 
-class DepsgraphOperation {
-public:
-	typedef void (*call_func)(void *data);
-	typedef void (*free_func)(void *data);
-	
-	template <typename functor_t>
-	struct MemFunWrapper {
-		MemFunWrapper(const functor_t &f) :
-		    fun(f)
-		{}
-		
-		inline static void call(void *self)
-		{
-			((MemFunWrapper<functor_t> *)self)->fun();
-		}
-		
-		inline static void free(void *self)
-		{
-			delete (MemFunWrapper<functor_t> *)self;
-		}
-		
-	private:
-		functor_t fun;
-	};
-	
-	/* default constructor creates a NOOP */
-	DepsgraphOperation()
-	{
-		m_func = NULL;
-		m_data = NULL;
-		m_data_free = NULL;
-	}
-	
-	template <typename functor_t>
-	DepsgraphOperation(const functor_t &f)
-	{
-		typedef MemFunWrapper<functor_t> wrapper_t;
-		
-		/* TODO we make a new alloc here as the actual persistent copy,
-		 * so could use efficient memory management later, and don't need to
-		 * define new/delete in every operation args type! (using placement new/delete)
-		 */
-		wrapper_t *wrapper = new wrapper_t(f);
-		m_func = &wrapper_t::call;
-		m_data = wrapper;
-		m_data_free = &wrapper_t::free;
-	}
-	
-	~DepsgraphOperation()
-	{
-		/* XXX TODO Also consider placement new/delete here (see constructor) */
-		if (m_data && m_data_free)
-			m_data_free(m_data);
-	}
-	
-	inline void operator() () const
-	{
-		BLI_assert(m_func);
-		m_func(m_data);
-	}
-	
-	bool is_noop() const
-	{
-		return m_func == NULL;
-	}
-	
-private:
-	call_func m_func;
-	void *m_data;
-	free_func m_data_free;
-};
-
 /* Flags for Depsgraph Nodes */
 typedef enum eDepsOperation_Flag {
 	/* node needs to be updated */
diff --git a/source/blender/depsgraph/util/depsgraph_util_function.h b/source/blender/depsgraph/util/depsgraph_util_function.h
index 5be9330..5788f80 100644
--- a/source/blender/depsgraph/util/depsgraph_util_function.h
+++ b/source/blender/depsgraph/util/depsgraph_util_function.h
@@ -29,6 +29,6 @@
 
 using std::bind;
 using std::function;
-using std::placeholders;
+using namespace std::placeholders;
 
 #endif /* __DEPSGRAPH_UTIL_SET_H__ */




More information about the Bf-blender-cvs mailing list