Restriction of the nodes api to clearly define never-null function arguments. Side effects: some assertions and null-check (with early return) were removed. On the caller side is ensured to never derefer null to pass argument (mainly in RNA). In addition, one pointer argument now actually a return type. By-reference return types instead of pointers going to be separate kind of change since also imply of cleaning up variables created from reference. Also good future improvement would be to mark a copy-constructor as explicit for DNA node types. Pull Request: https://projects.blender.org/blender/blender/pulls/134627
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_string_utf8.h"
|
|
|
|
#include "node_function_util.hh"
|
|
|
|
namespace blender::nodes::node_fn_string_length_cc {
|
|
|
|
static void node_declare(NodeDeclarationBuilder &b)
|
|
{
|
|
b.add_input<decl::String>("String").hide_label();
|
|
b.add_output<decl::Int>("Length");
|
|
}
|
|
|
|
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
|
|
{
|
|
static auto str_len_fn = mf::build::SI1_SO<std::string, int>(
|
|
"String Length", [](const std::string &a) { return BLI_strlen_utf8(a.c_str()); });
|
|
builder.set_matching_fn(&str_len_fn);
|
|
}
|
|
|
|
static void node_register()
|
|
{
|
|
static blender::bke::bNodeType ntype;
|
|
|
|
fn_node_type_base(&ntype, "FunctionNodeStringLength", FN_NODE_STRING_LENGTH);
|
|
ntype.ui_name = "String Length";
|
|
ntype.enum_name_legacy = "STRING_LENGTH";
|
|
ntype.nclass = NODE_CLASS_CONVERTER;
|
|
ntype.declare = node_declare;
|
|
ntype.build_multi_function = node_build_multi_function;
|
|
blender::bke::node_register_type(ntype);
|
|
}
|
|
NOD_REGISTER_NODE(node_register)
|
|
|
|
} // namespace blender::nodes::node_fn_string_length_cc
|