diff options
author | Jacques Lucke <jacques@blender.org> | 2022-11-12 20:33:31 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-11-12 20:33:31 +0300 |
commit | a6c822733ac7da4921297804475adadd50c08ed9 (patch) | |
tree | b34cc2924d7effa33d9ca9abfa026c8917fb953a /source/blender/blenlib/BLI_cpp_types_make.hh | |
parent | a145b96396c4d2b8dd5ae027c676e838df0bd701 (diff) |
BLI: improve CPPType system
* Support bidirectional type lookups. E.g. finding the base type of a
field was supported, but not the other way around. This also removes
the todo in `get_vector_type`. To achieve this, types have to be
registered up-front.
* Separate `CPPType` from other "type traits". For example, previously
`ValueOrFieldCPPType` adds additional behavior on top of `CPPType`.
Previously, it was a subclass, now it just contains a reference to the
`CPPType` it corresponds to. This follows the composition-over-inheritance
idea. This makes it easier to have self-contained "type traits" without
having to put everything into `CPPType`.
Differential Revision: https://developer.blender.org/D16479
Diffstat (limited to 'source/blender/blenlib/BLI_cpp_types_make.hh')
-rw-r--r-- | source/blender/blenlib/BLI_cpp_types_make.hh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_cpp_types_make.hh b/source/blender/blenlib/BLI_cpp_types_make.hh new file mode 100644 index 00000000000..ba729c4cc69 --- /dev/null +++ b/source/blender/blenlib/BLI_cpp_types_make.hh @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#include "BLI_cpp_type_make.hh" +#include "BLI_cpp_types.hh" + +namespace blender { + +template<typename ValueType> +inline VectorCPPType::VectorCPPType(TypeTag<ValueType> /*value_type*/) + : self(CPPType::get<Vector<ValueType>>()), value(CPPType::get<ValueType>()) +{ + this->register_self(); +} + +} // namespace blender + +/** Create a new #VectorCPPType that can be accessed through `VectorCPPType::get<T>()`. */ +#define BLI_VECTOR_CPP_TYPE_MAKE(VALUE_TYPE) \ + BLI_CPP_TYPE_MAKE(blender::Vector<VALUE_TYPE>, CPPTypeFlags::None) \ + template<> const blender::VectorCPPType &blender::VectorCPPType::get_impl<VALUE_TYPE>() \ + { \ + static blender::VectorCPPType type{blender::TypeTag<VALUE_TYPE>{}}; \ + return type; \ + } + +/** Register a #VectorCPPType created with #BLI_VECTOR_CPP_TYPE_MAKE. */ +#define BLI_VECTOR_CPP_TYPE_REGISTER(VALUE_TYPE) blender::VectorCPPType::get<VALUE_TYPE>() |