Blender V5.0
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"
10
11namespace blender::nodes {
12
20 static constexpr StringRefNull node_idname = "FunctionNodeFormatString";
21 static constexpr bool has_type = true;
22 static constexpr bool has_name = true;
23 static constexpr bool has_name_validation = true;
24 static constexpr bool has_custom_initial_name = true;
25 static constexpr char unique_name_separator = '_';
27 static constexpr StringRefNull add_item = "NODE_OT_format_string_item_add";
28 static constexpr StringRefNull remove_item = "NODE_OT_format_string_item_remove";
29 static constexpr StringRefNull move_item = "NODE_OT_format_string_item_move";
30 };
31 struct ui_idnames {
32 static constexpr StringRefNull list = "DATA_UL_format_string_items";
33 };
34 struct rna_names {
35 static constexpr StringRefNull items = "format_items";
36 static constexpr StringRefNull active_index = "active_index";
37 };
38
40 bNode &node)
41 {
42 auto *storage = static_cast<NodeFunctionFormatString *>(node.storage);
43 return {&storage->items, &storage->items_num, &storage->active_index};
44 }
45
47 {
48 dst = src;
49 dst.name = BLI_strdup_null(dst.name);
50 }
51
53 {
54 MEM_SAFE_FREE(item->name);
55 }
56
57 static void blend_write_item(BlendWriter *writer, const ItemT &item);
58 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
59
64
66 {
67 return &item.name;
68 }
69
70 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
71 {
72 return ELEM(socket_type, SOCK_INT, SOCK_FLOAT, SOCK_STRING);
73 }
74
77 const eNodeSocketDatatype socket_type,
78 const char *name)
79 {
80 auto *storage = static_cast<NodeFunctionFormatString *>(node.storage);
81 item.socket_type = socket_type;
82 item.identifier = storage->next_identifier++;
84 }
85
86 static std::string custom_initial_name(const bNode &node, StringRef src_name);
87 static std::string validate_name(const StringRef name);
88
90 {
91 return "Item_" + std::to_string(item.identifier);
92 }
93};
94
95} // namespace blender::nodes
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
#define ELEM(...)
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_FLOAT
@ SOCK_STRING
#define MEM_SAFE_FREE(v)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
const char * name
void * storage
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 void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static std::string custom_initial_name(const bNode &node, StringRef src_name)
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)