Commit: 39af860e6dfadde3b27c5b49cb602bd065e6451e Author: Lukas Tönne Date: Wed Mar 9 17:25:58 2016 +0100 Branches: object_nodes https://developer.blender.org/rB39af860e6dfadde3b27c5b49cb602bd065e6451e
Cleanup: Moved value class into own file, away from pure type declarations. =================================================================== M source/blender/blenvm/compile/CMakeLists.txt M source/blender/blenvm/compile/bvm_nodegraph.h M source/blender/blenvm/compile/bvm_typedesc.cc M source/blender/blenvm/compile/bvm_typedesc.h A source/blender/blenvm/compile/bvm_value.cc A source/blender/blenvm/compile/bvm_value.h =================================================================== diff --git a/source/blender/blenvm/compile/CMakeLists.txt b/source/blender/blenvm/compile/CMakeLists.txt index a2b5890..72bc55f 100644 --- a/source/blender/blenvm/compile/CMakeLists.txt +++ b/source/blender/blenvm/compile/CMakeLists.txt @@ -48,6 +48,8 @@ set(SRC bvm_nodegraph.h bvm_typedesc.cc bvm_typedesc.h + bvm_value.cc + bvm_value.h ) TEST_UNORDERED_MAP_SUPPORT() diff --git a/source/blender/blenvm/compile/bvm_nodegraph.h b/source/blender/blenvm/compile/bvm_nodegraph.h index 1e97151..601e8c5 100644 --- a/source/blender/blenvm/compile/bvm_nodegraph.h +++ b/source/blender/blenvm/compile/bvm_nodegraph.h @@ -52,6 +52,7 @@ extern "C" { #include "bvm_opcode.h" #include "bvm_typedesc.h" +#include "bvm_value.h" #include "bvm_util_string.h" namespace bvm { diff --git a/source/blender/blenvm/compile/bvm_typedesc.cc b/source/blender/blenvm/compile/bvm_typedesc.cc index ec5a634..e696417 100644 --- a/source/blender/blenvm/compile/bvm_typedesc.cc +++ b/source/blender/blenvm/compile/bvm_typedesc.cc @@ -30,6 +30,7 @@ */ #include "bvm_typedesc.h" +#include "bvm_value.h" namespace bvm { diff --git a/source/blender/blenvm/compile/bvm_typedesc.h b/source/blender/blenvm/compile/bvm_typedesc.h index ed34217..b8b0902 100644 --- a/source/blender/blenvm/compile/bvm_typedesc.h +++ b/source/blender/blenvm/compile/bvm_typedesc.h @@ -162,133 +162,6 @@ struct BaseTypeTraits<BVM_DUPLIS> { /* ------------------------------------------------------------------------- */ -template <BVMType type> -struct const_array { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - - const_array(const POD *data, size_t size) : - m_data(data), - m_size(size) - {} - - ~const_array() - {} - - const POD *data() const { return m_data; } - - const POD& operator [] (size_t index) const - { - return m_data[index]; - } - -private: - POD *m_data; - size_t m_size; -}; - -template <BVMType type> -struct array { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - - array() : - m_data(NULL), - m_size(0) - {} - - array(POD *data, size_t size) : - m_data(data), - m_size(size) - {} - - ~array() - {} - - operator const_array<type>() const - { - return const_array<type>(m_data, m_size); - } - - POD *data() const { return m_data; } - - POD& operator [] (size_t index) - { - return m_data[index]; - } - -private: - POD *m_data; - size_t m_size; -}; - -template <BVMType type> -struct const_image { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - - const_image(const POD *data, size_t width, size_t height) : - m_data(data), - m_width(width), - m_height(height) - {} - - ~const_image() - {} - - const POD *data() const { return m_data; } - - const POD& get(size_t x, size_t y) const - { - return m_data[x + y * m_width]; - } - -private: - POD *m_data; - size_t m_width; - size_t m_height; -}; - -template <BVMType type> -struct image { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - - image() : - m_data(NULL), - m_width(0), - m_height(0) - {} - - image(const POD *data, size_t width, size_t height) : - m_data(data), - m_width(width), - m_height(height) - {} - - ~image() - {} - - operator const_image<type>() const - { - return const_image<type>(m_data, m_width, m_height); - } - - POD *data() const { return m_data; } - - POD& get(size_t x, size_t y) - { - return m_data[x + y * m_width]; - } - -private: - POD *m_data; - size_t m_width; - size_t m_height; -}; - -/* ------------------------------------------------------------------------- */ - struct StructSpec; struct TypeDesc { @@ -351,271 +224,6 @@ private: FieldList m_fields; }; -/* ------------------------------------------------------------------------- */ - -struct Value { - template <typename T> - static Value *create(const TypeDesc &typedesc, T *data, size_t size); - template <typename T> - static Value *create(const TypeDesc &typedesc, T data); - - virtual ~Value() - {} - - const TypeDesc &typedesc() const { return m_typedesc; } - - template <BVMType type> - bool get(array<type> *data) const; - - template <typename T> - bool get(T *data) const; - - virtual Value *copy() const = 0; - -protected: - Value(const TypeDesc &typedesc) : - m_typedesc(typedesc) - {} - - TypeDesc m_typedesc; -}; - -template <BVMType type> -struct SingleValue : public Value { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - - SingleValue(typename traits::POD data) : - Value(TypeDesc(type)), - m_data(data) - {} - - template <typename T> - SingleValue(T data) : - Value(TypeDesc(type)) - { (void)data; } - - const POD &data() const { return m_data; } - - bool get(POD *data) const - { - *data = m_data; - return true; - } - - template <typename T> - bool get(T *data) const - { - assert(!"Data type mismatch"); - (void)data; - return false; - } - - Value *copy() const - { - return new SingleValue<type>(m_data); - } - -private: - POD m_data; -}; - -template <BVMType type> -struct ArrayValue : public Value { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - typedef array<type> array_t; - typedef const_array<type> const_array_t; - - ArrayValue(const array_t &data) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)), - m_data(data) - {} - - ArrayValue(POD *data, size_t size) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)), - m_data(array_t(data, size)) - {} - - template <typename T> - ArrayValue(T data) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)) - { (void)data; } - - template <typename T> - ArrayValue(T *data, size_t size) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)) - { (void)data; (void)size; } - - const array_t &data() const { return m_data; } - - bool get(array_t *data) const - { - *data = m_data; - return true; - } - - template <typename T> - bool get(T *data) const - { - assert(!"Data type mismatch"); - (void)data; - return false; - } - - Value *copy() const - { - return new ArrayValue<type>(m_data); - } - -private: - array_t m_data; -}; - -template <BVMType type> -struct ImageValue : public Value { - typedef BaseTypeTraits<type> traits; - typedef typename traits::POD POD; - typedef image<type> image_t; - typedef const_image<type> const_image_t; - - ImageValue(const image_t &data) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)), - m_data(data) - {} - - ImageValue(POD *data, size_t width, size_t height) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)), - m_data(image_t(data, width, height)) - {} - - template <typename T> - ImageValue(T data) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)) - { (void)data; } - - template <typename T> - ImageValue(T *data, size_t width, size_t height) : - Value(TypeDesc(type, BVM_BUFFER_ARRAY)) - { (void)data; (void)width; (void)height; } - - const image_t &data() const { return m_data; } - - bool get(image_t *data) const - { - *data = m_data; - return true; - } - - template <typename T> - bool get(T *data) const - { - assert(!"Data type mismatch"); - (void)data; - return false; - } - - Value *copy() const - { - return new ImageValue<type>(m_data); - } - -private: - image_t m_data; -}; - -/* ========================================================================= */ - -template <typename T> -static Value *create(const TypeDesc &typedesc, T *data, size_t size) -{ - if (typedesc.buffer_type() == BVM_BUFFER_ARRAY) { - switch (typedesc.base_type()) { - case BVM_FLOAT: return new ArrayValue<BVM_FLOAT>(data, size); - case BVM_FLOAT3: return new ArrayValue<BVM_FLOAT3>(data, size); - case BVM_FLOAT4: return new ArrayValue<BVM_FLOAT4>(data, size); - case BVM_INT: return new ArrayValue<BVM_INT>(data, size); - case BVM_MATRIX44: return new ArrayValue<BVM_MATRIX44>(data, size); - case BVM_STRING: return new ArrayValue<BVM_STRING>(data, size); - case BVM_RNAPOINTER: return new ArrayValue<BVM_RNAPOINTER>(data, size); - case BVM_MESH: return new ArrayValue<BVM_MESH>(data, size); - case BVM_DUPLIS: return new ArrayValue<BVM_DUPLIS>(data, size); - } - } - return NULL; -} - -template <typename T> -Value *Value::create(const TypeDesc &typedesc, T data) -{ - if (typedesc.buffer_type() == BVM_BUFFER_SINGLE) { - switch (typedesc.base_type()) { - case BVM_FLOAT: return new SingleValue<BVM_FLOAT>(data); - case BVM_FLOAT3: return new SingleValue<BVM_FLOAT3>(data); - case BVM_FLOAT4: return new SingleValue<BVM_FLOAT4>(data); - case BVM_INT: return new SingleValue<BVM_INT>(data); - case BVM_MATRIX44: return new SingleValue<BVM_MATRIX44>(data); - case BVM_STRING: return new SingleValue<BVM_STRING>(data); - case BVM_RNAPOINTER: return new SingleValue<BVM_RNAPOINTER>(data); - case BVM_MESH: return new SingleValue<BVM_MESH>(data); - case BVM_DUPLIS: return new SingleValue<BVM_DUPLIS>(data); - } - } - else if (typedesc.buffer_type() == BVM_BUFFER_ARRAY) { - switch (typedesc.base_type()) { - case BVM_FLOAT: return new ArrayValue<BVM_FLOAT>(data); - case BVM_FLOAT3: return new ArrayValue<BVM_FLOAT3>(data); - case BVM_FLOAT4: return new ArrayValue<BVM_FLOAT4>(data); - case BVM_INT: return new ArrayValue<BVM_INT>(data); - case BVM_MATRIX44: return new ArrayValue<BVM_MATRIX44>(data); - case BVM_STRING: return new ArrayValue<BVM_STRING>(data); - case BVM_RNAPOINTER: return new ArrayValue<BVM_RNAPOINTER>(data); - case BVM_MESH: return new ArrayValue<BVM_MESH>(data); - case BVM_DUPLIS: return new ArrayValue<BVM_DUPLIS>(data); - } - } - return NULL; -} - - -template <BVMType type> -bool Value::get(array<type> *data) const -{ - if (m_typedesc.buffer_type() == BVM_BUFFER_ARRAY) { - switch (m_typedesc.base_type()) { - case BVM_FLOAT: return static_cast< const ArrayValue<BVM_FLOAT>* >(this)->get(data); - case BVM_FLOAT3: return static_cast< const ArrayValue<BVM_FLOAT3>* >(this)->get(data); - case BVM_FLOAT4: return static_cast< const ArrayValue<BVM_FLOAT4>* >(this)->get(data); - case BVM_INT: return static_cast< const ArrayValue<BVM_INT>* >(this)->get(data); - case BVM_MATRIX44: return static_cast< const ArrayValue<BVM_MATRIX44>* >(this)->get(data); - case BVM_STRING: @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs