[Bf-blender-cvs] [54b8d6ba0b0] functions: more const

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


Commit: 54b8d6ba0b054e4176eb3c6cdca598eec0f2ac8f
Author: Jacques Lucke
Date:   Wed Jan 23 15:13:19 2019 +0100
Branches: functions
https://developer.blender.org/rB54b8d6ba0b054e4176eb3c6cdca598eec0f2ac8f

more const

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

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/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 2e0506f9ce6..2ba0fed987b 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -30,7 +30,7 @@ namespace FN {
 	class ValueArray {
 	public:
 		ValueArray() {};
-		ValueArray(SmallTypeVector types);
+		ValueArray(const SmallTypeVector &types);
 		void set(uint index, void *src);
 		void get(uint index, void *dst) const;
 
@@ -42,7 +42,7 @@ namespace FN {
 
 	class Inputs {
 	public:
-		Inputs(Function &fn);
+		Inputs(const Function &fn);
 
 		inline void set(uint index, void *src)
 		{ this->values.set(index, src); }
@@ -50,13 +50,13 @@ namespace FN {
 		{ this->values.get(index, dst); }
 
 	private:
-		Function &fn;
+		const Function &fn;
 		ValueArray values;
 	};
 
 	class Outputs {
 	public:
-		Outputs(Function &fn);
+		Outputs(const Function &fn);
 
 		inline void set(uint index, void *src)
 		{ this->values.set(index, src); }
@@ -64,7 +64,7 @@ namespace FN {
 		{ this->values.get(index, dst); }
 
 	private:
-		Function &fn;
+		const Function &fn;
 		ValueArray values;
 	};
 
@@ -73,7 +73,7 @@ namespace FN {
 		Signature()
 			: m_inputs({}), m_outputs({}) {}
 
-		Signature(SmallTypeVector inputs, SmallTypeVector outputs)
+		Signature(const SmallTypeVector &inputs, const SmallTypeVector &outputs)
 			: m_inputs(inputs), m_outputs(outputs) {}
 
 		~Signature() {}
@@ -90,17 +90,17 @@ namespace FN {
 
 	class Function {
 	public:
-		Function(Signature signature)
+		Function(const Signature &signature)
 			: m_signature(signature) {}
 
-		virtual bool call(Inputs &fn_in, Outputs &fn_out) = 0;
+		virtual ~Function();
 
-		inline const Signature &signature() const
-		{ return this->m_signature; }
+		virtual bool call(const Inputs &fn_in, Outputs &fn_out) = 0;
 
-	private:
+		const Signature &signature() const;
 
-	protected:
-		Signature m_signature;
+	private:
+		const Signature m_signature;
 	};
+
 } /* namespace FN */
diff --git a/source/blender/functions/intern/c_wrapper.cpp b/source/blender/functions/intern/c_wrapper.cpp
index f6bd3c1313d..bc0f669747b 100644
--- a/source/blender/functions/intern/c_wrapper.cpp
+++ b/source/blender/functions/intern/c_wrapper.cpp
@@ -44,12 +44,18 @@ FnTypeRef FN_type_get_float_vector_3d()
 
 
 class AddConstFunction : public FN::Function {
+private:
+	AddConstFunction(FN::Signature sig, int value)
+		: Function(sig), value(value) {}
+
 public:
-	AddConstFunction(int value)
-		: FN::Function(FN::Signature({FN::Types::int32_ty}, {FN::Types::int32_ty})), value(value)
-	{ }
+	static AddConstFunction *Create(int value)
+	{
+		FN::Signature sig({FN::Types::int32_ty}, {FN::Types::int32_ty});
+		return new AddConstFunction(sig, value);
+	}
 
-	bool call(FN::Inputs &fn_in, FN::Outputs &fn_out)
+	bool call(const FN::Inputs &fn_in, FN::Outputs &fn_out) override
 	{
 		int a;
 		fn_in.get(0, &a);
@@ -64,5 +70,5 @@ private:
 
 FunctionRef FN_get_add_const_function(int value)
 {
-	return (FunctionRef)new AddConstFunction(value);
-}
\ No newline at end of file
+	return (FunctionRef)AddConstFunction::Create(value);
+}
diff --git a/source/blender/functions/intern/function.cpp b/source/blender/functions/intern/function.cpp
index c7b2cd875ae..a985b132606 100644
--- a/source/blender/functions/intern/function.cpp
+++ b/source/blender/functions/intern/function.cpp
@@ -12,13 +12,17 @@ const uint Type::size() const
 	return this->m_size;
 }
 
-Inputs::Inputs(Function &fn)
-	: fn(fn), values(ValueArray(fn.signature().inputs())) { }
 
-Outputs::Outputs(Function &fn)
-	: fn(fn), values(ValueArray(fn.signature().outputs())) { }
 
-ValueArray::ValueArray(SmallTypeVector types)
+Inputs::Inputs(const Function &fn)
+	: fn(fn), values(fn.signature().inputs()) { }
+
+Outputs::Outputs(const Function &fn)
+	: fn(fn), values(fn.signature().outputs()) { }
+
+
+
+ValueArray::ValueArray(const SmallTypeVector &types)
 	: types(types)
 {
 	int total_size = 0;
@@ -26,16 +30,15 @@ ValueArray::ValueArray(SmallTypeVector types)
 		this->offsets.append(total_size);
 		total_size += type->size();
 	}
+	this->offsets.append(total_size);
 	this->storage = SmallBuffer<>(total_size);
 }
 
 void ValueArray::set(uint index, void *src)
 {
-	BLI_assert(index < this->offsets.size());
-	this->storage.copy_in(
-		this->offsets[index],
-		src,
-		this->types[index]->size());
+	BLI_assert(index < this->types.size());
+	uint size = this->offsets[index + 1] - this->offsets[index];
+	this->storage.copy_in(this->offsets[index], src, size);
 }
 
 void ValueArray::get(uint index, void *dst) const
@@ -45,4 +48,14 @@ void ValueArray::get(uint index, void *dst) const
 		dst,
 		this->offsets[index],
 		this->types[index]->size());
+}
+
+
+Function::~Function()
+{
+}
+
+const Signature &Function::signature() const
+{
+	return this->m_signature;
 }
\ No newline at end of file



More information about the Bf-blender-cvs mailing list