1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "constants.h"
namespace FN {
void MF_GenericConstantValue::value_to_string(std::stringstream &ss,
const CPPType &type,
const void *value)
{
if (type == CPPType_float) {
ss << (*(float *)value);
}
else if (type == CPPType_int32) {
ss << *(int *)value;
}
else if (type == CPPType_float3) {
ss << *(BLI::float3 *)value;
}
else if (type == CPP_TYPE<bool>()) {
ss << ((*(bool *)value) ? "true" : "false");
}
else if (type == CPPType_string) {
ss << "\"" << *(std::string *)value << "\"";
}
else {
ss << "Value";
}
}
MF_GenericConstantValue::MF_GenericConstantValue(const CPPType &type, const void *value)
: m_value(value)
{
MFSignatureBuilder signature = this->get_builder("Constant " + type.name());
std::stringstream ss;
MF_GenericConstantValue::value_to_string(ss, type, value);
signature.single_output(ss.str(), type);
}
void MF_GenericConstantValue::call(IndexMask mask,
MFParams params,
MFContext UNUSED(context)) const
{
GenericMutableArrayRef r_value = params.uninitialized_single_output(0);
r_value.type().fill_uninitialized_indices(m_value, r_value.buffer(), mask);
}
MF_GenericConstantVector::MF_GenericConstantVector(GenericArrayRef array) : m_array(array)
{
const CPPType &type = array.type();
MFSignatureBuilder signature = this->get_builder("Constant " + type.name() + " List");
std::stringstream ss;
ss << "[";
uint max_amount = 5;
for (uint i : IndexRange(std::min(max_amount, array.size()))) {
MF_GenericConstantValue::value_to_string(ss, type, array[i]);
ss << ", ";
}
if (max_amount < array.size()) {
ss << "...";
}
ss << "]";
signature.vector_output(ss.str(), type);
}
void MF_GenericConstantVector::call(IndexMask mask,
MFParams params,
MFContext UNUSED(context)) const
{
GenericVectorArray &r_vectors = params.vector_output(0);
for (uint i : mask) {
r_vectors.extend_single__copy(i, m_array);
}
}
} // namespace FN
|