[Bf-blender-cvs] [b36a4d7c729] functions: first successful execution

Jacques Lucke noreply at git.blender.org
Sun Feb 10 20:25:01 CET 2019


Commit: b36a4d7c729db61ddd3b703ed6eb37e05700f8a7
Author: Jacques Lucke
Date:   Tue Jan 22 16:55:53 2019 +0100
Branches: functions
https://developer.blender.org/rBb36a4d7c729db61ddd3b703ed6eb37e05700f8a7

first successful execution

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

M	source/blender/blenlib/BLI_small_buffer.hpp
M	source/blender/editors/object/object_edit.c
M	source/blender/functions/FN_functions.hpp
M	source/blender/functions/intern/c_wrapper.cpp
M	source/blender/functions/intern/function.cpp

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

diff --git a/source/blender/blenlib/BLI_small_buffer.hpp b/source/blender/blenlib/BLI_small_buffer.hpp
index 52166fbba64..a8a79471347 100644
--- a/source/blender/blenlib/BLI_small_buffer.hpp
+++ b/source/blender/blenlib/BLI_small_buffer.hpp
@@ -24,13 +24,13 @@ namespace BLI {
 
 		void copy_in(uint dst, void *src, uint amount)
 		{
-			BLI_assert(dst + amount < this->size);
+			BLI_assert(dst + amount <= this->size);
 			memcpy(this->buffer + dst, src, amount);
 		}
 
 		void copy_out(void *dst, uint src, uint amount) const
 		{
-			BLI_assert(src + amount < this->size);
+			BLI_assert(src + amount <= this->size);
 			memcpy(dst, this->buffer + src, amount);
 		}
 
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index bd25ec2c799..ce47ebea011 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1748,9 +1748,17 @@ void OBJECT_OT_link_to_collection(wmOperatorType *ot)
 
 static int test_functions_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
-	FunctionRef fn = NULL;
-	FnTypeRef type = FN_type_get_float_vector_3d();
-	printf("Type: %s\n", FN_type_name(type));
+	FunctionRef fn = FN_get_add_const_function(100);
+	FnInputsRef fn_in = FN_inputs_new(fn);
+	FnOutputsRef fn_out = FN_outputs_new(fn);
+
+	int value = 42;
+	FN_inputs_set_index(fn_in, 0, &value);
+	FN_function_call(fn, fn_in, fn_out);
+	int result;
+	FN_outputs_get_index(fn_out, 0, &result);
+	printf("Result: %d\n", result);
+
 	printf("Finished\n");
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 98f5573f2fc..2e0506f9ce6 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -35,7 +35,7 @@ namespace FN {
 		void get(uint index, void *dst) const;
 
 	private:
-		SmallTypeVector types;
+		const SmallTypeVector types;
 		SmallVector<int> offsets;
 		SmallBuffer<> storage;
 	};
@@ -70,23 +70,30 @@ namespace FN {
 
 	class Signature {
 	public:
-		Signature() {}
+		Signature()
+			: m_inputs({}), m_outputs({}) {}
+
 		Signature(SmallTypeVector inputs, SmallTypeVector outputs)
 			: m_inputs(inputs), m_outputs(outputs) {}
 
+		~Signature() {}
+
 		inline const SmallTypeVector &inputs() const
 		{ return this->m_inputs; }
 		inline const SmallTypeVector &outputs() const
 		{ return this->m_outputs; }
 
 	private:
-		SmallTypeVector m_inputs;
-		SmallTypeVector m_outputs;
+		const SmallTypeVector m_inputs;
+		const SmallTypeVector m_outputs;
 	};
 
 	class Function {
 	public:
-		bool call(Inputs &fn_in, Outputs &fn_out);
+		Function(Signature signature)
+			: m_signature(signature) {}
+
+		virtual bool call(Inputs &fn_in, Outputs &fn_out) = 0;
 
 		inline const Signature &signature() const
 		{ return this->m_signature; }
diff --git a/source/blender/functions/intern/c_wrapper.cpp b/source/blender/functions/intern/c_wrapper.cpp
index 1d82705616b..f6bd3c1313d 100644
--- a/source/blender/functions/intern/c_wrapper.cpp
+++ b/source/blender/functions/intern/c_wrapper.cpp
@@ -13,9 +13,19 @@ FnInputsRef FN_inputs_new(FunctionRef fn)
 	return (FnInputsRef)new FN::Inputs(*(FN::Function *)fn);
 }
 
-void FN_inputs_set_index(FnInputsRef fn_in, uint index, void *value)
+FnOutputsRef FN_outputs_new(FunctionRef fn)
 {
-	((FN::Inputs *)fn_in)->set(index, value);
+	return (FnOutputsRef)new FN::Outputs(*(FN::Function *)fn);
+}
+
+void FN_inputs_set_index(FnInputsRef fn_in, uint index, void *src)
+{
+	((FN::Inputs *)fn_in)->set(index, src);
+}
+
+void FN_outputs_get_index(FnOutputsRef fn_out, uint index, void *dst)
+{
+	((FN::Outputs *)fn_out)->get(index, dst);
 }
 
 const char *FN_type_name(FnTypeRef type)
@@ -36,10 +46,8 @@ FnTypeRef FN_type_get_float_vector_3d()
 class AddConstFunction : public FN::Function {
 public:
 	AddConstFunction(int value)
-		: value(value)
-	{
-		this->m_signature = FN::Signature({FN::Types::int32_ty}, {FN::Types::int32_ty});
-	}
+		: FN::Function(FN::Signature({FN::Types::int32_ty}, {FN::Types::int32_ty})), value(value)
+	{ }
 
 	bool call(FN::Inputs &fn_in, FN::Outputs &fn_out)
 	{
diff --git a/source/blender/functions/intern/function.cpp b/source/blender/functions/intern/function.cpp
index 41793141e88..c7b2cd875ae 100644
--- a/source/blender/functions/intern/function.cpp
+++ b/source/blender/functions/intern/function.cpp
@@ -13,15 +13,10 @@ const uint Type::size() const
 }
 
 Inputs::Inputs(Function &fn)
-	: fn(fn), values(fn.signature().inputs()) { }
+	: fn(fn), values(ValueArray(fn.signature().inputs())) { }
 
 Outputs::Outputs(Function &fn)
-	: fn(fn), values(fn.signature().outputs()) { }
-
-bool Function::call(Inputs &UNUSED(fn_in), Outputs &UNUSED(fn_out))
-{
-	return false;
-}
+	: fn(fn), values(ValueArray(fn.signature().outputs())) { }
 
 ValueArray::ValueArray(SmallTypeVector types)
 	: types(types)



More information about the Bf-blender-cvs mailing list