[Bf-blender-cvs] [37e03622154] functions: cleanup
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:24:52 CET 2019
Commit: 37e03622154b5749712f258024996c1e9a2a2ffe
Author: Jacques Lucke
Date: Tue Jan 22 15:30:09 2019 +0100
Branches: functions
https://developer.blender.org/rB37e03622154b5749712f258024996c1e9a2a2ffe
cleanup
===================================================================
M source/blender/blenlib/BLI_small_vector.hpp
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_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
index 68153dba55a..4cfd888b07d 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -29,12 +29,19 @@ namespace BLI {
}
}
+ ~SmallVector()
+ {
+ if (!this->is_small()) {
+ std::free(this->m_elements);
+ }
+ }
+
void append(T value)
{
if (this->m_size >= this->m_capacity) {
this->m_capacity *= 2;
uint new_byte_size = sizeof(T) * this->m_capacity;
- if (this->m_elements == this->m_small_buffer) {
+ if (this->is_small()) {
this->m_elements = (T *)std::malloc(new_byte_size);
}
else {
@@ -72,6 +79,12 @@ namespace BLI {
{ return this->begin(); }
const T *cend() const
{ return this->end(); }
+
+ private:
+ bool is_small() const
+ {
+ return this->m_elements == this->m_small_buffer;
+ }
};
} /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 0f11e920578..98f5573f2fc 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -56,15 +56,15 @@ namespace FN {
class Outputs {
public:
- static Outputs *New(Function &fn);
+ Outputs(Function &fn);
- bool set(uint index, void *value);
- bool get(uint index);
+ inline void set(uint index, void *src)
+ { this->values.set(index, src); }
+ inline void get(uint index, void *dst) const
+ { this->values.get(index, dst); }
private:
- Outputs() {}
-
- Function *fn;
+ Function &fn;
ValueArray values;
};
diff --git a/source/blender/functions/intern/c_wrapper.cpp b/source/blender/functions/intern/c_wrapper.cpp
index 553ea6671ca..1d82705616b 100644
--- a/source/blender/functions/intern/c_wrapper.cpp
+++ b/source/blender/functions/intern/c_wrapper.cpp
@@ -41,9 +41,13 @@ public:
this->m_signature = FN::Signature({FN::Types::int32_ty}, {FN::Types::int32_ty});
}
- bool call(FN::Inputs &UNUSED(fn_in), FN::Outputs &UNUSED(fn_out))
+ bool call(FN::Inputs &fn_in, FN::Outputs &fn_out)
{
- return false;
+ int a;
+ fn_in.get(0, &a);
+ int result = a + this->value;
+ fn_out.set(0, &result);
+ return true;
}
private:
diff --git a/source/blender/functions/intern/function.cpp b/source/blender/functions/intern/function.cpp
index 84c186bd0e9..41793141e88 100644
--- a/source/blender/functions/intern/function.cpp
+++ b/source/blender/functions/intern/function.cpp
@@ -13,8 +13,10 @@ const uint Type::size() const
}
Inputs::Inputs(Function &fn)
- : fn(fn), values(fn.signature().inputs())
-{ }
+ : fn(fn), values(fn.signature().inputs()) { }
+
+Outputs::Outputs(Function &fn)
+ : fn(fn), values(fn.signature().outputs()) { }
bool Function::call(Inputs &UNUSED(fn_in), Outputs &UNUSED(fn_out))
{
More information about the Bf-blender-cvs
mailing list