[Bf-blender-cvs] [ac8555af9eb] functions: Function and Type are final classes - can still be extended with Composition

Jacques Lucke noreply at git.blender.org
Sun Feb 10 20:26:34 CET 2019


Commit: ac8555af9ebaceb54329026b60e8eff340cb1005
Author: Jacques Lucke
Date:   Thu Feb 7 18:24:33 2019 +0100
Branches: functions
https://developer.blender.org/rBac8555af9ebaceb54329026b60e8eff340cb1005

Function and Type are final classes - can still be extended with Composition

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

M	source/blender/functions/FN_functions.h
M	source/blender/functions/c_wrapper.cpp
M	source/blender/functions/core/core.hpp
M	source/blender/functions/types/numeric.cpp
M	source/blender/functions/types/numeric.hpp
M	source/creator/CMakeLists.txt
M	source/creator/creator.c

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

diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index 852c3756f48..a45a5b0487f 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -7,6 +7,8 @@
 extern "C" {
 #endif
 
+void FN_initialize(void);
+
 typedef struct OpaqueFnFunction *FnFunction;
 typedef struct OpaqueFnType *FnType;
 typedef struct OpaqueFnTuple *FnTuple;
@@ -35,7 +37,7 @@ FnType FN_type_get_fvec3(void);
 
 FnFunction FN_get_deform_function(int type);
 
-FnFunction FN_get_generated_function();
+FnFunction FN_get_generated_function(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 456f810e1ef..4117af07983 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -12,10 +12,14 @@
 
 WRAPPERS(BLI::RefCounted<FN::Function> *, FnFunction);
 WRAPPERS(BLI::RefCounted<FN::Type> *, FnType);
-
 WRAPPERS(FN::Tuple *, FnTuple);
 WRAPPERS(const FN::TupleCallBody *, FnCallable);
 
+void FN_initialize()
+{
+	FN::Types::init_numeric_types();
+}
+
 void FN_function_call(FnCallable fn_call, FnTuple fn_in, FnTuple fn_out)
 {
 	unwrap(fn_call)->call(*unwrap(fn_in), *unwrap(fn_out));
diff --git a/source/blender/functions/core/core.hpp b/source/blender/functions/core/core.hpp
index a1a09956cbe..c86bea681ec 100644
--- a/source/blender/functions/core/core.hpp
+++ b/source/blender/functions/core/core.hpp
@@ -80,8 +80,12 @@ namespace FN {
 		BLI::SmallMap<uint64_t, Entry> m_elements;
 	};
 
-	class Type {
+	class Type final {
 	public:
+		Type() = delete;
+		Type(const std::string &name)
+			: m_name(name) {}
+
 		const std::string &name() const
 		{
 			return this->m_name;
@@ -183,12 +187,12 @@ namespace FN {
 		const OutputParameters m_outputs;
 	};
 
-	class Function {
+	class Function final {
 	public:
 		Function(const Signature &signature, const std::string &name = "Function")
 			: m_signature(signature), m_name(name) {}
 
-		virtual ~Function() {}
+		~Function() = default;
 
 		inline const Signature &signature() const
 		{
diff --git a/source/blender/functions/types/numeric.cpp b/source/blender/functions/types/numeric.cpp
index a788c0c1585..5e9bb52efd5 100644
--- a/source/blender/functions/types/numeric.cpp
+++ b/source/blender/functions/types/numeric.cpp
@@ -2,40 +2,31 @@
 
 namespace FN::Types {
 
-	class FloatType : public FN::Type {
-	public:
-		FloatType()
-		{
-			this->m_name = "Float";
-			this->extend(new FN::TypeSize(sizeof(float)));
-		}
-	};
-
-	class Int32Type : public FN::Type {
-	public:
-		Int32Type()
-		{
-			this->m_name = "Int32";
-			this->extend(new FN::TypeSize(sizeof(int32_t)));
-		}
-	};
-
-	template<uint N>
-	class FloatVectorType : public FN::Type {
-	public:
-		FloatVectorType()
-		{
-			this->m_name = "FloatVector" + std::to_string(N) + "D";
-			this->extend(new FN::TypeSize(sizeof(float) * N));
-		}
-	};
-
-#define DEFAULT_TYPE(name, initializer) \
-	SharedType TYPE_##name = SharedType::FromPointer(initializer); \
-	SharedType &get_##name##_type() { return TYPE_##name; }
-
-	DEFAULT_TYPE(float, new FloatType());
-	DEFAULT_TYPE(int32, new Int32Type());
-	DEFAULT_TYPE(fvec3, new FloatVectorType<3>());
+	SharedType float_type = SharedType::New("Float");
+	SharedType int32_type = SharedType::New("Int32");
+	SharedType fvec3_type = SharedType::New("FloatVector3D");
+
+
+	void init_numeric_types()
+	{
+		float_type->extend(new TypeSize(sizeof(float)));
+		int32_type->extend(new TypeSize(sizeof(int32_t)));
+		fvec3_type->extend(new TypeSize(sizeof(float) * 3));
+	}
+
+	SharedType &get_float_type()
+	{
+		return float_type;
+	}
+
+	SharedType &get_int32_type()
+	{
+		return int32_type;
+	}
+
+	SharedType &get_fvec3_type()
+	{
+		return fvec3_type;
+	}
 
 } /* namespace FN::Types */
\ No newline at end of file
diff --git a/source/blender/functions/types/numeric.hpp b/source/blender/functions/types/numeric.hpp
index 1ecc1a810dc..98a6f809ec9 100644
--- a/source/blender/functions/types/numeric.hpp
+++ b/source/blender/functions/types/numeric.hpp
@@ -4,6 +4,8 @@
 
 namespace FN::Types {
 
+	void init_numeric_types();
+
 	SharedType &get_float_type();
 	SharedType &get_int32_type();
 	SharedType &get_fvec3_type();
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index ea90b900dfd..f5ad2d81dd1 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -29,6 +29,7 @@ blender_include_dirs(
 	../blender/blenloader
 	../blender/depsgraph
 	../blender/editors/include
+	../blender/functions
 	../blender/makesrna
 	../blender/imbuf
 	../blender/render/extern/include
diff --git a/source/creator/creator.c b/source/creator/creator.c
index fbe3ceb1d29..38600ee260f 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -75,6 +75,8 @@
 
 #include "RNA_define.h"
 
+#include "FN_functions.h"
+
 #ifdef WITH_FREESTYLE
 #  include "FRS_freestyle.h"
 #endif
@@ -366,6 +368,7 @@ int main(
 	BKE_gpencil_modifier_init();
 	BKE_shaderfx_init();
 	DEG_register_node_types();
+	FN_initialize();
 
 	BKE_brush_system_init();
 	RE_texture_rng_init();



More information about the Bf-blender-cvs mailing list