[Bf-blender-cvs] [59d589e736d] functions: move concrete type definitions into separate translation unit
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:26:30 CET 2019
Commit: 59d589e736d9a0aa8fb63c078e9a96b0077f695f
Author: Jacques Lucke
Date: Thu Feb 7 15:03:44 2019 +0100
Branches: functions
https://developer.blender.org/rB59d589e736d9a0aa8fb63c078e9a96b0077f695f
move concrete type definitions into separate translation unit
===================================================================
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_functions.h
M source/blender/functions/c_wrapper.cpp
M source/blender/functions/core/core.hpp
A source/blender/functions/core/cpu.cpp
M source/blender/functions/core/cpu.hpp
A source/blender/functions/types/numeric.cpp
M source/blender/functions/types/numeric.hpp
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index efc9d2a6d7e..9139b3336b1 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -13,11 +13,13 @@ set(SRC
core/core.hpp
core/data_flow_graph.hpp
core/cpu.hpp
+ core/cpu.cpp
core/data_flow_graph.cpp
core/dot_export.cpp
FN_functions.hpp
+ types/numeric.cpp
types/numeric.hpp
types/types.hpp
)
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index 428c09f54fe..b5e49a0c78a 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -31,7 +31,7 @@ void FN_type_free(FnType type);
FnType FN_type_get_float(void);
FnType FN_type_get_int32(void);
-FnType FN_type_get_float_vector_3d(void);
+FnType FN_type_get_fvec3(void);
FnFunction FN_get_deform_function(int type);
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 69229e0c411..aea8ff92f39 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -69,7 +69,7 @@ void FN_tuple_get_float_vector_3(FnTuple tuple, uint index, float dst[3])
const char *FN_type_name(FnType type)
{
- return ((FN::Type *)type)->name().c_str();
+ return unwrap(type)->ptr()->name().c_str();
}
void FN_type_free(FnType type)
@@ -84,27 +84,17 @@ static FnType get_type_with_increased_refcount(const FN::SharedType &type)
return wrap(typeref);
}
-FnType FN_type_get_float()
-{
- return get_type_with_increased_refcount(FN::Types::float_ty);
-}
-
-FnType FN_type_get_int32()
-{
- return get_type_with_increased_refcount(FN::Types::int32_ty);
-}
-
-FnType FN_type_get_float_vector_3d()
-{
- return get_type_with_increased_refcount(FN::Types::floatvec3d_ty);
-}
+#define SIMPLE_TYPE_GETTER(name) \
+ FnType FN_type_get_##name() \
+ { return get_type_with_increased_refcount(FN::Types::get_##name##_type()); }
+SIMPLE_TYPE_GETTER(float);
+SIMPLE_TYPE_GETTER(int32);
+SIMPLE_TYPE_GETTER(fvec3);
#include <cmath>
#include <algorithm>
-
-
class Deform1 : public FN::TupleCallBody {
public:
virtual void call(const FN::Tuple &fn_in, FN::Tuple &fn_out) const override
@@ -142,11 +132,11 @@ public:
FnFunction FN_get_deform_function(int type)
{
FN::InputParameters inputs;
- inputs.append(FN::InputParameter("Position", FN::Types::floatvec3d_ty));
- inputs.append(FN::InputParameter("Control", FN::Types::float_ty));
+ inputs.append(FN::InputParameter("Position", FN::Types::get_fvec3_type()));
+ inputs.append(FN::InputParameter("Control", FN::Types::get_float_type()));
FN::OutputParameters outputs;
- outputs.append(FN::OutputParameter("Position", FN::Types::floatvec3d_ty));
+ outputs.append(FN::OutputParameter("Position", FN::Types::get_fvec3_type()));
auto fn = FN::SharedFunction::New(FN::Signature(inputs, outputs), "Deform");
if (type == 0) {
diff --git a/source/blender/functions/core/core.hpp b/source/blender/functions/core/core.hpp
index e67702b9fd4..d89c156b446 100644
--- a/source/blender/functions/core/core.hpp
+++ b/source/blender/functions/core/core.hpp
@@ -59,7 +59,7 @@ namespace FN {
template<typename T>
static uint64_t get_key()
{
- return (uint64_t)T::identifier;
+ return (uint64_t)T::identifier();
}
template<typename T>
diff --git a/source/blender/functions/core/cpu.cpp b/source/blender/functions/core/cpu.cpp
new file mode 100644
index 00000000000..114339c3916
--- /dev/null
+++ b/source/blender/functions/core/cpu.cpp
@@ -0,0 +1,28 @@
+#include "cpu.hpp"
+
+namespace FN {
+
+ const char *TupleCallBody::identifier()
+ {
+ return "Tuple Call Body";
+ }
+
+ void TupleCallBody::free(void *value)
+ {
+ TupleCallBody *v = (TupleCallBody *)value;
+ delete v;
+ }
+
+
+ const char *TypeSize::identifier()
+ {
+ return "Type Size";
+ }
+
+ void TypeSize::free(void *value)
+ {
+ TypeSize *v = (TypeSize *)value;
+ delete v;
+ }
+
+} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/core/cpu.hpp b/source/blender/functions/core/cpu.hpp
index f4331318000..adf1b9b0789 100644
--- a/source/blender/functions/core/cpu.hpp
+++ b/source/blender/functions/core/cpu.hpp
@@ -10,13 +10,8 @@ namespace FN {
class TupleCallBody {
public:
- static constexpr const char *identifier = "Tuple Call Body";
-
- static void free(void *value)
- {
- TupleCallBody *v = (TupleCallBody *)value;
- delete v;
- }
+ static const char *identifier();
+ static void free(void *value);
virtual void call(const Tuple &fn_in, Tuple &fn_out) const = 0;
virtual ~TupleCallBody() {};
@@ -24,13 +19,8 @@ namespace FN {
class TypeSize final {
public:
- static constexpr const char *identifier = "Type Size";
-
- static void free(void *value)
- {
- TypeSize *v = (TypeSize *)value;
- delete v;
- }
+ static const char* identifier();
+ static void free(void *value);
TypeSize(uint size)
: m_size(size) {}
diff --git a/source/blender/functions/types/numeric.hpp b/source/blender/functions/types/numeric.cpp
similarity index 61%
copy from source/blender/functions/types/numeric.hpp
copy to source/blender/functions/types/numeric.cpp
index 04ac07c42d7..a788c0c1585 100644
--- a/source/blender/functions/types/numeric.hpp
+++ b/source/blender/functions/types/numeric.cpp
@@ -1,6 +1,4 @@
-#pragma once
-
-#include "../FN_functions.hpp"
+#include "numeric.hpp"
namespace FN::Types {
@@ -32,8 +30,12 @@ namespace FN::Types {
}
};
- static SharedType float_ty = SharedType::FromPointer(new FloatType());
- static SharedType int32_ty = SharedType::FromPointer(new Int32Type());
- static SharedType floatvec3d_ty = SharedType::FromPointer(new FloatVectorType<3>());
+#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>());
} /* 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 04ac07c42d7..1ecc1a810dc 100644
--- a/source/blender/functions/types/numeric.hpp
+++ b/source/blender/functions/types/numeric.hpp
@@ -4,36 +4,8 @@
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));
- }
- };
-
- static SharedType float_ty = SharedType::FromPointer(new FloatType());
- static SharedType int32_ty = SharedType::FromPointer(new Int32Type());
- static SharedType floatvec3d_ty = SharedType::FromPointer(new FloatVectorType<3>());
+ SharedType &get_float_type();
+ SharedType &get_int32_type();
+ SharedType &get_fvec3_type();
} /* namespace FN::Types */
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list