[Bf-blender-cvs] [3dfee3c0b19] temp-cpp-type-cleanup: improve printing
Jacques Lucke
noreply at git.blender.org
Sun Jun 27 17:07:05 CEST 2021
Commit: 3dfee3c0b19222e650d4c60edbf1882a0c2e959f
Author: Jacques Lucke
Date: Sun Jun 27 16:35:24 2021 +0200
Branches: temp-cpp-type-cleanup
https://developer.blender.org/rB3dfee3c0b19222e650d4c60edbf1882a0c2e959f
improve printing
===================================================================
M source/blender/functions/FN_cpp_type.hh
M source/blender/functions/FN_cpp_type_make.hh
M source/blender/functions/intern/multi_function_builder.cc
===================================================================
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 70fd9131da5..e4c21885b40 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -107,7 +107,7 @@ struct CPPTypeMembers {
void (*fill_construct_indices)(const void *value, void *dst, IndexMask mask) = nullptr;
- void (*debug_print)(const void *value, std::stringstream &ss) = nullptr;
+ void (*print)(const void *value, std::stringstream &ss) = nullptr;
bool (*is_equal)(const void *a, const void *b) = nullptr;
uint64_t (*hash)(const void *value) = nullptr;
@@ -223,6 +223,21 @@ class CPPType : NonCopyable, NonMovable {
return m_.copy_construct != nullptr;
}
+ bool is_printable() const
+ {
+ return m_.print != nullptr;
+ }
+
+ bool is_equality_comparable() const
+ {
+ return m_.is_equal != nullptr;
+ }
+
+ bool is_hashable() const
+ {
+ return m_.hash != nullptr;
+ }
+
/**
* Returns true, when the type has the following functions:
* - Default constructor.
@@ -524,10 +539,20 @@ class CPPType : NonCopyable, NonMovable {
m_.fill_construct_indices(value, dst, mask);
}
- void debug_print(const void *value, std::stringstream &ss) const
+ void print(const void *value, std::stringstream &ss) const
{
BLI_assert(this->pointer_can_point_to_instance(value));
- m_.debug_print(value, ss);
+ m_.print(value, ss);
+ }
+
+ void print_or_default(const void *value, std::stringstream &ss, StringRef default_value) const
+ {
+ if (this->is_printable()) {
+ m_.print(value, ss);
+ }
+ else {
+ ss << default_value;
+ }
}
bool is_equal(const void *a, const void *b) const
diff --git a/source/blender/functions/FN_cpp_type_make.hh b/source/blender/functions/FN_cpp_type_make.hh
index b7c83bf8c86..529ec261946 100644
--- a/source/blender/functions/FN_cpp_type_make.hh
+++ b/source/blender/functions/FN_cpp_type_make.hh
@@ -164,7 +164,7 @@ template<typename T> void fill_construct_indices_cb(const void *value, void *dst
mask.foreach_index([&](int64_t i) { new (dst_ + i) T(value_); });
}
-template<typename T> void debug_print_cb(const void *value, std::stringstream &ss)
+template<typename T> void print_cb(const void *value, std::stringstream &ss)
{
const T &value_ = *static_cast<const T *>(value);
ss << value_;
@@ -258,7 +258,7 @@ inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name)
m.hash = hash_cb<T>;
}
if constexpr ((bool)(flags & CPPTypeFlags::Printable)) {
- m.debug_print = debug_print_cb<T>;
+ m.print = print_cb<T>;
}
if constexpr ((bool)(flags & CPPTypeFlags::EqualityComparable)) {
m.is_equal = is_equal_cb<T>;
diff --git a/source/blender/functions/intern/multi_function_builder.cc b/source/blender/functions/intern/multi_function_builder.cc
index 6961935dc0c..69b2b6e0b93 100644
--- a/source/blender/functions/intern/multi_function_builder.cc
+++ b/source/blender/functions/intern/multi_function_builder.cc
@@ -25,7 +25,7 @@ CustomMF_GenericConstant::CustomMF_GenericConstant(const CPPType &type, const vo
{
MFSignatureBuilder signature{"Constant " + type.name()};
std::stringstream ss;
- type.debug_print(value, ss);
+ type.print_or_default(value, ss, type.name());
signature.single_output(ss.str(), type);
signature_ = signature.build();
this->set_signature(&signature_);
@@ -58,11 +58,12 @@ bool CustomMF_GenericConstant::equals(const MultiFunction &other) const
static std::string gspan_to_string(GSpan array)
{
+ const CPPType &type = array.type();
std::stringstream ss;
ss << "[";
const int64_t max_amount = 5;
for (int64_t i : IndexRange(std::min(max_amount, array.size()))) {
- array.type().debug_print(array[i], ss);
+ type.print_or_default(array[i], ss, type.name());
ss << ", ";
}
if (max_amount < array.size()) {
More information about the Bf-blender-cvs
mailing list