Blender V5.3
NOD_fn_format_string.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "DNA_node_types.h"
8
9#include "NOD_socket_items.hh"
11
12namespace blender::nodes {
13
21 static constexpr StringRefNull node_idname = "FunctionNodeFormatString";
22 static constexpr bool has_type = true;
23 static constexpr bool has_name = true;
24 static constexpr bool has_name_validation = true;
25 static constexpr bool has_custom_initial_name = true;
26 static constexpr char unique_name_separator = '_';
28 static constexpr StringRefNull add_item = "NODE_OT_format_string_item_add";
29 static constexpr StringRefNull remove_item = "NODE_OT_format_string_item_remove";
30 static constexpr StringRefNull move_item = "NODE_OT_format_string_item_move";
31 };
32 struct ui_idnames {
33 static constexpr StringRefNull list = "DATA_UL_format_string_items";
34 };
35 struct rna_names {
36 static constexpr StringRefNull items = "format_items";
37 static constexpr StringRefNull active_index = "active_index";
38 };
39
41 bNode &node)
42 {
43 auto *storage = static_cast<NodeFunctionFormatString *>(node.storage);
44 return {&storage->items, &storage->items_num, &storage->active_index};
45 }
46
48 {
49 dst = src;
50 dst.name = BLI_strdup_null(dst.name);
51 }
52
54 {
55 MEM_SAFE_DELETE(item->name);
56 }
57
58 static void blend_write_item(BlendWriter *writer, const ItemT &item);
59 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
60
62 {
63 return item.socket_type;
64 }
65
67 {
68 return &item.name;
69 }
70
71 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
72 {
73 return ELEM(socket_type, SOCK_INT, SOCK_FLOAT, SOCK_STRING);
74 }
75
78 const eNodeSocketDatatype socket_type,
79 const char *name)
80 {
81 auto *storage = static_cast<NodeFunctionFormatString *>(node.storage);
82 item.socket_type = socket_type;
83 item.identifier = storage->next_identifier++;
85 }
86
87 static std::string custom_initial_name(const bNode &node, StringRef src_name)
88 {
90 }
91
92 static std::string validate_name(const StringRef name)
93 {
95 }
96
98 {
99 return "Item_" + std::to_string(item.identifier);
100 }
101};
102
103} // namespace blender::nodes
#define ELEM(...)
#define storage(slot, qualifiers)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
std::string variable_name_find_short(StringRef src_name, FunctionRef< bool(StringRef)> exists_fn)
std::string variable_name_validate(StringRef name)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int)
static char ** get_name(NodeFunctionFormatStringItem &item)
static void destruct_item(NodeFunctionFormatStringItem *item)
static std::string custom_initial_name(const bNode &node, StringRef src_name)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static std::string validate_name(const StringRef name)
static std::string socket_identifier_for_item(const NodeFunctionFormatStringItem &item)
static socket_items::SocketItemsRef< NodeFunctionFormatStringItem > get_items_from_node(bNode &node)
static void copy_item(const NodeFunctionFormatStringItem &src, NodeFunctionFormatStringItem &dst)
static void init_with_socket_type_and_name(bNode &node, NodeFunctionFormatStringItem &item, const eNodeSocketDatatype socket_type, const char *name)
static eNodeSocketDatatype get_socket_type(const NodeFunctionFormatStringItem &item)