Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-11-12 20:33:31 +0300
committerJacques Lucke <jacques@blender.org>2022-11-12 20:33:31 +0300
commita6c822733ac7da4921297804475adadd50c08ed9 (patch)
treeb34cc2924d7effa33d9ca9abfa026c8917fb953a /source/blender/blenlib/BLI_cpp_types.hh
parenta145b96396c4d2b8dd5ae027c676e838df0bd701 (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.hh')
-rw-r--r--source/blender/blenlib/BLI_cpp_types.hh44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_cpp_types.hh b/source/blender/blenlib/BLI_cpp_types.hh
new file mode 100644
index 00000000000..596090b95e5
--- /dev/null
+++ b/source/blender/blenlib/BLI_cpp_types.hh
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+#include "BLI_cpp_type.hh"
+#include "BLI_vector.hh"
+
+namespace blender {
+
+/**
+ * Contains information about how to deal with a #Vector<T> generically.
+ */
+class VectorCPPType {
+ public:
+ /** The #Vector<T> itself. */
+ const CPPType &self;
+ /** The type stored in the vector. */
+ const CPPType &value;
+
+ template<typename ValueType> VectorCPPType(TypeTag<ValueType> /*value_type*/);
+
+ /**
+ * Try to find the #VectorCPPType that corresponds to a #CPPType.
+ */
+ static const VectorCPPType *get_from_self(const CPPType &self);
+ /**
+ * Try to find the #VectorCPPType that wraps a vector containing the given value type.
+ * This only works when the vector type has been created with #BLI_VECTOR_CPP_TYPE_MAKE.
+ */
+ static const VectorCPPType *get_from_value(const CPPType &value);
+
+ template<typename ValueType> static const VectorCPPType &get()
+ {
+ static const VectorCPPType &type = VectorCPPType::get_impl<std::decay_t<ValueType>>();
+ return type;
+ }
+
+ template<typename ValueType> static const VectorCPPType &get_impl();
+
+ private:
+ void register_self();
+};
+
+} // namespace blender