Cleanup: Nodes: use StringRefNull in socket item accessors

This mainly helps avoid accidentally comparing char pointers instead of the
strings they point to.

Pull Request: https://projects.blender.org/blender/blender/pulls/138917
This commit is contained in:
Jacques Lucke
2025-05-15 08:41:21 +02:00
parent 79d37720de
commit a33df684c4
11 changed files with 110 additions and 106 deletions

View File

@@ -228,16 +228,18 @@ inline void move_active_item(wmOperatorType *ot,
template<typename Accessor> inline void make_common_operators()
{
WM_operatortype_append([](wmOperatorType *ot) {
socket_items::ops::add_item<Accessor>(
ot, "Add Item", Accessor::operator_idnames::add_item, "Add item below active item");
socket_items::ops::add_item<Accessor>(ot,
"Add Item",
Accessor::operator_idnames::add_item.c_str(),
"Add item below active item");
});
WM_operatortype_append([](wmOperatorType *ot) {
socket_items::ops::remove_active_item<Accessor>(
ot, "Remove Item", Accessor::operator_idnames::remove_item, "Remove active item");
ot, "Remove Item", Accessor::operator_idnames::remove_item.c_str(), "Remove active item");
});
WM_operatortype_append([](wmOperatorType *ot) {
socket_items::ops::move_active_item<Accessor>(
ot, "Move Item", Accessor::operator_idnames::move_item, "Move active item");
ot, "Move Item", Accessor::operator_idnames::move_item.c_str(), "Move active item");
});
}

View File

@@ -58,8 +58,8 @@ static void draw_items_list_with_operators(const bContext *C,
const_cast<ID *>(&tree.id), &RNA_Node, const_cast<bNode *>(&node));
static const uiListType *items_list = []() {
uiListType *list = MEM_callocN<uiListType>(Accessor::ui_idnames::list);
STRNCPY(list->idname, Accessor::ui_idnames::list);
uiListType *list = MEM_callocN<uiListType>(Accessor::ui_idnames::list.c_str());
STRNCPY(list->idname, Accessor::ui_idnames::list.c_str());
list->draw_item = draw_item_in_list<Accessor>;
WM_uilisttype_add(list);
return list;
@@ -73,7 +73,7 @@ static void draw_items_list_with_operators(const bContext *C,
&node_ptr,
Accessor::rna_names::items,
&node_ptr,
Accessor::rna_names::active_index,
Accessor::rna_names::active_index.c_str(),
nullptr,
3,
5,

View File

@@ -31,21 +31,21 @@ struct BakeItemsAccessor {
using ItemT = NodeGeometryBakeItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeBake";
static constexpr StringRefNull node_idname = "GeometryNodeBake";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_bake_node_item_add";
static constexpr const char *remove_item = "NODE_OT_bake_node_item_remove";
static constexpr const char *move_item = "NODE_OT_bake_node_item_move";
static constexpr StringRefNull add_item = "NODE_OT_bake_node_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_bake_node_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_bake_node_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_bake_node_items";
static constexpr StringRefNull list = "DATA_UL_bake_node_items";
};
struct rna_names {
static constexpr const char *items = "bake_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "bake_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<NodeGeometryBakeItem> get_items_from_node(bNode &node)

View File

@@ -34,21 +34,21 @@ struct CombineBundleItemsAccessor {
using ItemT = NodeGeometryCombineBundleItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeCombineBundle";
static constexpr StringRefNull node_idname = "GeometryNodeCombineBundle";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_combine_bundle_item_add";
static constexpr const char *remove_item = "NODE_OT_combine_bundle_item_remove";
static constexpr const char *move_item = "NODE_OT_combine_bundle_item_move";
static constexpr StringRefNull add_item = "NODE_OT_combine_bundle_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_combine_bundle_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_combine_bundle_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_combine_bundle_items";
static constexpr StringRefNull list = "DATA_UL_combine_bundle_items";
};
struct rna_names {
static constexpr const char *items = "bundle_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "bundle_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -107,21 +107,21 @@ struct SeparateBundleItemsAccessor {
using ItemT = NodeGeometrySeparateBundleItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeSeparateBundle";
static constexpr StringRefNull node_idname = "GeometryNodeSeparateBundle";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_separate_bundle_item_add";
static constexpr const char *remove_item = "NODE_OT_separate_bundle_item_remove";
static constexpr const char *move_item = "NODE_OT_separate_bundle_item_move";
static constexpr StringRefNull add_item = "NODE_OT_separate_bundle_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_separate_bundle_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_separate_bundle_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_separate_bundle_items";
static constexpr StringRefNull list = "DATA_UL_separate_bundle_items";
};
struct rna_names {
static constexpr const char *items = "bundle_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "bundle_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)

View File

@@ -16,21 +16,21 @@ struct CaptureAttributeItemsAccessor {
using ItemT = NodeGeometryAttributeCaptureItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeCaptureAttribute";
static constexpr StringRefNull node_idname = "GeometryNodeCaptureAttribute";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = false;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_capture_attribute_item_add";
static constexpr const char *remove_item = "NODE_OT_capture_attribute_item_remove";
static constexpr const char *move_item = "NODE_OT_capture_attribute_item_move";
static constexpr StringRefNull add_item = "NODE_OT_capture_attribute_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_capture_attribute_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_capture_attribute_item_move";
};
struct ui_idnames {
static constexpr const char *list = "NODE_UL_capture_items_list";
static constexpr StringRefNull list = "NODE_UL_capture_items_list";
};
struct rna_names {
static constexpr const char *items = "capture_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "capture_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<NodeGeometryAttributeCaptureItem> get_items_from_node(

View File

@@ -34,21 +34,21 @@ struct ClosureInputItemsAccessor {
using ItemT = NodeGeometryClosureInputItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeClosureOutput";
static constexpr StringRefNull node_idname = "GeometryNodeClosureOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_closure_input_item_add";
static constexpr const char *remove_item = "NODE_OT_closure_input_item_remove";
static constexpr const char *move_item = "NODE_OT_closure_input_item_move";
static constexpr StringRefNull add_item = "NODE_OT_closure_input_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_closure_input_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_closure_input_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_closure_input_items";
static constexpr StringRefNull list = "DATA_UL_closure_input_items";
};
struct rna_names {
static constexpr const char *items = "input_items";
static constexpr const char *active_index = "active_input_index";
static constexpr StringRefNull items = "input_items";
static constexpr StringRefNull active_index = "active_input_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -109,21 +109,21 @@ struct ClosureOutputItemsAccessor {
using ItemT = NodeGeometryClosureOutputItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeClosureOutput";
static constexpr StringRefNull node_idname = "GeometryNodeClosureOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_closure_output_item_add";
static constexpr const char *remove_item = "NODE_OT_closure_output_item_remove";
static constexpr const char *move_item = "NODE_OT_closure_output_item_move";
static constexpr StringRefNull add_item = "NODE_OT_closure_output_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_closure_output_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_closure_output_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_closure_output_items";
static constexpr StringRefNull list = "DATA_UL_closure_output_items";
};
struct rna_names {
static constexpr const char *items = "output_items";
static constexpr const char *active_index = "active_output_index";
static constexpr StringRefNull items = "output_items";
static constexpr StringRefNull active_index = "active_output_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -184,21 +184,21 @@ struct EvaluateClosureInputItemsAccessor {
using ItemT = NodeGeometryEvaluateClosureInputItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeEvaluateClosure";
static constexpr StringRefNull node_idname = "GeometryNodeEvaluateClosure";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_evaluate_closure_input_item_add";
static constexpr const char *remove_item = "NODE_OT_evaluate_closure_input_item_remove";
static constexpr const char *move_item = "NODE_OT_evaluate_closure_input_item_move";
static constexpr StringRefNull add_item = "NODE_OT_evaluate_closure_input_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_evaluate_closure_input_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_evaluate_closure_input_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_evaluate_closure_input_items";
static constexpr StringRefNull list = "DATA_UL_evaluate_closure_input_items";
};
struct rna_names {
static constexpr const char *items = "input_items";
static constexpr const char *active_index = "active_input_index";
static constexpr StringRefNull items = "input_items";
static constexpr StringRefNull active_index = "active_input_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -260,21 +260,21 @@ struct EvaluateClosureOutputItemsAccessor {
using ItemT = NodeGeometryEvaluateClosureOutputItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeEvaluateClosure";
static constexpr StringRefNull node_idname = "GeometryNodeEvaluateClosure";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_evaluate_closure_output_item_add";
static constexpr const char *remove_item = "NODE_OT_evaluate_closure_output_item_remove";
static constexpr const char *move_item = "NODE_OT_evaluate_closure_output_item_move";
static constexpr StringRefNull add_item = "NODE_OT_evaluate_closure_output_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_evaluate_closure_output_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_evaluate_closure_output_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_evaluate_closure_output_items";
static constexpr StringRefNull list = "DATA_UL_evaluate_closure_output_items";
};
struct rna_names {
static constexpr const char *items = "output_items";
static constexpr const char *active_index = "active_output_index";
static constexpr StringRefNull items = "output_items";
static constexpr StringRefNull active_index = "active_output_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)

View File

@@ -14,23 +14,24 @@ struct ForeachGeometryElementInputItemsAccessor {
using ItemT = NodeForeachGeometryElementInputItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr StringRefNull node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_foreach_geometry_element_zone_input_item_add";
static constexpr const char *remove_item =
static constexpr StringRefNull add_item =
"NODE_OT_foreach_geometry_element_zone_input_item_add";
static constexpr StringRefNull remove_item =
"NODE_OT_foreach_geometry_element_zone_input_item_remove";
static constexpr const char *move_item =
static constexpr StringRefNull move_item =
"NODE_OT_foreach_geometry_element_zone_input_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_foreach_geometry_element_input_items";
static constexpr StringRefNull list = "DATA_UL_foreach_geometry_element_input_items";
};
struct rna_names {
static constexpr const char *items = "input_items";
static constexpr const char *active_index = "active_input_index";
static constexpr StringRefNull items = "input_items";
static constexpr StringRefNull active_index = "active_input_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -100,23 +101,24 @@ struct ForeachGeometryElementMainItemsAccessor {
using ItemT = NodeForeachGeometryElementMainItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr StringRefNull node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_foreach_geometry_element_zone_main_item_add";
static constexpr const char *remove_item =
static constexpr StringRefNull add_item =
"NODE_OT_foreach_geometry_element_zone_main_item_add";
static constexpr StringRefNull remove_item =
"NODE_OT_foreach_geometry_element_zone_main_item_remove";
static constexpr const char *move_item =
static constexpr StringRefNull move_item =
"NODE_OT_foreach_geometry_element_zone_main_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_foreach_geometry_element_main_items";
static constexpr StringRefNull list = "DATA_UL_foreach_geometry_element_main_items";
};
struct rna_names {
static constexpr const char *items = "main_items";
static constexpr const char *active_index = "active_main_index";
static constexpr StringRefNull items = "main_items";
static constexpr StringRefNull active_index = "active_main_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
@@ -185,24 +187,24 @@ struct ForeachGeometryElementGenerationItemsAccessor {
using ItemT = NodeForeachGeometryElementGenerationItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr StringRefNull node_idname = "GeometryNodeForeachGeometryElementOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item =
static constexpr StringRefNull add_item =
"NODE_OT_foreach_geometry_element_zone_generation_item_add";
static constexpr const char *remove_item =
static constexpr StringRefNull remove_item =
"NODE_OT_foreach_geometry_element_zone_generation_item_remove";
static constexpr const char *move_item =
static constexpr StringRefNull move_item =
"NODE_OT_foreach_geometry_element_zone_generation_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_foreach_geometry_element_generation_items";
static constexpr StringRefNull list = "DATA_UL_foreach_geometry_element_generation_items";
};
struct rna_names {
static constexpr const char *items = "generation_items";
static constexpr const char *active_index = "active_generation_index";
static constexpr StringRefNull items = "generation_items";
static constexpr StringRefNull active_index = "active_generation_index";
};
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)

View File

@@ -18,7 +18,7 @@ struct IndexSwitchItemsAccessor {
using ItemT = IndexSwitchItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeIndexSwitch";
static constexpr StringRefNull node_idname = "GeometryNodeIndexSwitch";
static constexpr bool has_type = false;
static constexpr bool has_name = false;
static constexpr bool has_single_identifier_str = true;

View File

@@ -19,21 +19,21 @@ struct MenuSwitchItemsAccessor {
using ItemT = NodeEnumItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeMenuSwitch";
static constexpr StringRefNull node_idname = "GeometryNodeMenuSwitch";
static constexpr bool has_type = false;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_enum_definition_item_add";
static constexpr const char *remove_item = "NODE_OT_enum_definition_item_remove";
static constexpr const char *move_item = "NODE_OT_enum_definition_item_move";
static constexpr StringRefNull add_item = "NODE_OT_enum_definition_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_enum_definition_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_enum_definition_item_move";
};
struct ui_idnames {
static constexpr const char *list = "NODE_UL_enum_definition_items";
static constexpr StringRefNull list = "NODE_UL_enum_definition_items";
};
struct rna_names {
static constexpr const char *items = "enum_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "enum_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<NodeEnumItem> get_items_from_node(bNode &node)

View File

@@ -18,21 +18,21 @@ struct RepeatItemsAccessor {
using ItemT = NodeRepeatItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeRepeatOutput";
static constexpr StringRefNull node_idname = "GeometryNodeRepeatOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_repeat_zone_item_add";
static constexpr const char *remove_item = "NODE_OT_repeat_zone_item_remove";
static constexpr const char *move_item = "NODE_OT_repeat_zone_item_move";
static constexpr StringRefNull add_item = "NODE_OT_repeat_zone_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_repeat_zone_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_repeat_zone_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_repeat_zone_state";
static constexpr StringRefNull list = "DATA_UL_repeat_zone_state";
};
struct rna_names {
static constexpr const char *items = "repeat_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "repeat_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<NodeRepeatItem> get_items_from_node(bNode &node)

View File

@@ -18,21 +18,21 @@ struct SimulationItemsAccessor {
using ItemT = NodeSimulationItem;
static StructRNA *item_srna;
static int node_type;
static constexpr const char *node_idname = "GeometryNodeSimulationOutput";
static constexpr StringRefNull node_idname = "GeometryNodeSimulationOutput";
static constexpr bool has_type = true;
static constexpr bool has_name = true;
static constexpr bool has_single_identifier_str = true;
struct operator_idnames {
static constexpr const char *add_item = "NODE_OT_simulation_zone_item_add";
static constexpr const char *remove_item = "NODE_OT_simulation_zone_item_remove";
static constexpr const char *move_item = "NODE_OT_simulation_zone_item_move";
static constexpr StringRefNull add_item = "NODE_OT_simulation_zone_item_add";
static constexpr StringRefNull remove_item = "NODE_OT_simulation_zone_item_remove";
static constexpr StringRefNull move_item = "NODE_OT_simulation_zone_item_move";
};
struct ui_idnames {
static constexpr const char *list = "DATA_UL_simulation_zone_state";
static constexpr StringRefNull list = "DATA_UL_simulation_zone_state";
};
struct rna_names {
static constexpr const char *items = "state_items";
static constexpr const char *active_index = "active_index";
static constexpr StringRefNull items = "state_items";
static constexpr StringRefNull active_index = "active_index";
};
static socket_items::SocketItemsRef<NodeSimulationItem> get_items_from_node(bNode &node)