[Bf-blender-cvs] [a7f3b1a3efc] temp-cpp-type-cleanup: make more CPPType features optional
Jacques Lucke
noreply at git.blender.org
Sun Jun 27 17:07:05 CEST 2021
Commit: a7f3b1a3efca88faca3d475d4e0a8bd797c796c2
Author: Jacques Lucke
Date: Sun Jun 27 16:26:16 2021 +0200
Branches: temp-cpp-type-cleanup
https://developer.blender.org/rBa7f3b1a3efca88faca3d475d4e0a8bd797c796c2
make more CPPType features optional
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/geometry_set.cc
M source/blender/blenlib/BLI_utildefines.h
M source/blender/functions/FN_cpp_type_make.hh
M source/blender/functions/intern/cpp_types.cc
M source/blender/nodes/geometry/node_geometry_exec.cc
M source/blender/nodes/intern/node_socket.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index b2342a5fd96..82c9a31dfce 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -280,8 +280,6 @@ struct GeometrySet {
void compute_boundbox_without_instances(blender::float3 *r_min, blender::float3 *r_max) const;
friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);
- friend bool operator==(const GeometrySet &a, const GeometrySet &b);
- uint64_t hash() const;
void clear();
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 3d85118deee..07b4e715ea9 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -199,20 +199,6 @@ std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set)
return stream;
}
-/* This generally should not be used. It is necessary currently, so that GeometrySet can by used by
- * the CPPType system. */
-bool operator==(const GeometrySet &UNUSED(a), const GeometrySet &UNUSED(b))
-{
- return false;
-}
-
-/* This generally should not be used. It is necessary currently, so that GeometrySet can by used by
- * the CPPType system. */
-uint64_t GeometrySet::hash() const
-{
- return reinterpret_cast<uint64_t>(this);
-}
-
/* Remove all geometry components from the geometry set. */
void GeometrySet::clear()
{
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 0ddabcaa2fb..5b84e050f82 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -788,23 +788,24 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
extern "C++" { \
inline constexpr _enum_type operator|(_enum_type a, _enum_type b) \
{ \
- return static_cast<_enum_type>(static_cast<int>(a) | b); \
+ return static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
} \
inline constexpr _enum_type operator&(_enum_type a, _enum_type b) \
{ \
- return static_cast<_enum_type>(static_cast<int>(a) & b); \
+ return static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
} \
inline constexpr _enum_type operator~(_enum_type a) \
{ \
- return static_cast<_enum_type>(~static_cast<int>(a) & (2 * _max_enum_value - 1)); \
+ return static_cast<_enum_type>(~static_cast<uint64_t>(a) & \
+ (2 * static_cast<uint64_t>(_max_enum_value) - 1)); \
} \
inline _enum_type &operator|=(_enum_type &a, _enum_type b) \
{ \
- return a = static_cast<_enum_type>(static_cast<int>(a) | b); \
+ return a = static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
} \
inline _enum_type &operator&=(_enum_type &a, _enum_type b) \
{ \
- return a = static_cast<_enum_type>(static_cast<int>(a) & b); \
+ return a = static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
} \
} /* extern "C++" */
diff --git a/source/blender/functions/FN_cpp_type_make.hh b/source/blender/functions/FN_cpp_type_make.hh
index 7af68f3e23a..b7c83bf8c86 100644
--- a/source/blender/functions/FN_cpp_type_make.hh
+++ b/source/blender/functions/FN_cpp_type_make.hh
@@ -20,6 +20,7 @@
* \ingroup fn
*/
+#include "BLI_utildefines.h"
#include "FN_cpp_type.hh"
namespace blender::fn::cpp_type_util {
@@ -184,9 +185,25 @@ template<typename T> uint64_t hash_cb(const void *value)
} // namespace blender::fn::cpp_type_util
+/**
+ * Different types support different features. Features like copy constructibility can be detected
+ * automatically easily. For some features this is harder as of C++17. Those have flags in this
+ * enum and need to be determined by the programmer.
+ */
+enum class CPPTypeFlags {
+ None = 0,
+ Hashable = 1 << 0,
+ Printable = 1 << 1,
+ EqualityComparable = 1 << 2,
+
+ BasicType = Hashable | Printable | EqualityComparable,
+};
+ENUM_OPERATORS(CPPTypeFlags, CPPTypeFlags::EqualityComparable)
+
namespace blender::fn {
-template<typename T> inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
+template<typename T, CPPTypeFlags flags>
+inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
{
using namespace cpp_type_util;
@@ -237,9 +254,15 @@ template<typename T> inline std::unique_ptr<const CPPType> create_cpp_type(Strin
if constexpr (std::is_copy_constructible_v<T>) {
m.fill_construct_indices = fill_construct_indices_cb<T>;
}
- m.debug_print = debug_print_cb<T>;
- m.is_equal = is_equal_cb<T>;
- m.hash = hash_cb<T>;
+ if constexpr ((bool)(flags & CPPTypeFlags::Hashable)) {
+ m.hash = hash_cb<T>;
+ }
+ if constexpr ((bool)(flags & CPPTypeFlags::Printable)) {
+ m.debug_print = debug_print_cb<T>;
+ }
+ if constexpr ((bool)(flags & CPPTypeFlags::EqualityComparable)) {
+ m.is_equal = is_equal_cb<T>;
+ }
const CPPType *type = new CPPType(std::move(m));
return std::unique_ptr<const CPPType>(type);
@@ -247,11 +270,11 @@ template<typename T> inline std::unique_ptr<const CPPType> create_cpp_type(Strin
} // namespace blender::fn
-#define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME) \
+#define MAKE_CPP_TYPE(IDENTIFIER, TYPE_NAME, FLAGS) \
template<> const blender::fn::CPPType &blender::fn::CPPType::get<TYPE_NAME>() \
{ \
- static std::unique_ptr<const CPPType> cpp_type = blender::fn::create_cpp_type<TYPE_NAME>( \
- STRINGIFY(IDENTIFIER)); \
+ static std::unique_ptr<const CPPType> cpp_type = \
+ blender::fn::create_cpp_type<TYPE_NAME, FLAGS>(STRINGIFY(IDENTIFIER)); \
return *cpp_type; \
} \
/* Support using `CPPType::get<const T>()`. Otherwise the caller would have to remove const. */ \
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index 9c2c1621e23..7be34d2a1bf 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -23,20 +23,20 @@
namespace blender::fn {
-MAKE_CPP_TYPE(bool, bool)
+MAKE_CPP_TYPE(bool, bool, CPPTypeFlags::BasicType)
-MAKE_CPP_TYPE(float, float)
-MAKE_CPP_TYPE(float2, blender::float2)
-MAKE_CPP_TYPE(float3, blender::float3)
-MAKE_CPP_TYPE(float4x4, blender::float4x4)
+MAKE_CPP_TYPE(float, float, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(float2, blender::float2, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(float3, blender::float3, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(float4x4, blender::float4x4, CPPTypeFlags::BasicType)
-MAKE_CPP_TYPE(int32, int32_t)
-MAKE_CPP_TYPE(uint32, uint32_t)
-MAKE_CPP_TYPE(uint8, uint8_t)
+MAKE_CPP_TYPE(int32, int32_t, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(uint32, uint32_t, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(uint8, uint8_t, CPPTypeFlags::BasicType)
-MAKE_CPP_TYPE(ColorGeometry4f, blender::ColorGeometry4f)
-MAKE_CPP_TYPE(ColorGeometry4b, blender::ColorGeometry4b)
+MAKE_CPP_TYPE(ColorGeometry4f, blender::ColorGeometry4f, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(ColorGeometry4b, blender::ColorGeometry4b, CPPTypeFlags::BasicType)
-MAKE_CPP_TYPE(string, std::string)
+MAKE_CPP_TYPE(string, std::string, CPPTypeFlags::BasicType)
} // namespace blender::fn
diff --git a/source/blender/nodes/geometry/node_geometry_exec.cc b/source/blender/nodes/geometry/node_geometry_exec.cc
index a24a6d7ad21..8bf7680c835 100644
--- a/source/blender/nodes/geometry/node_geometry_exec.cc
+++ b/source/blender/nodes/geometry/node_geometry_exec.cc
@@ -17,7 +17,7 @@
#include "FN_cpp_type_make.hh"
#include "NOD_geometry_exec.hh"
-MAKE_CPP_TYPE(GeometrySet, GeometrySet);
+MAKE_CPP_TYPE(GeometrySet, GeometrySet, CPPTypeFlags::Printable);
namespace blender::nodes {
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index d00bf636e15..9f0a145ace2 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -662,10 +662,10 @@ static bNodeSocketType *make_socket_type_string()
return socktype;
}
-MAKE_CPP_TYPE(Object, Object *)
-MAKE_CPP_TYPE(Collection, Collection *)
-MAKE_CPP_TYPE(Texture, Tex *)
-MAKE_CPP_TYPE(Material, Material *)
+MAKE_CPP_TYPE(Object, Object *, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(Collection, Collection *, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(Texture, Tex *, CPPTypeFlags::BasicType)
+MAKE_CPP_TYPE(Material, Material *, CPPTypeFlags::BasicType)
static bNodeSocketType *make_socket_type_object()
{
More information about the Bf-blender-cvs
mailing list