[Bf-blender-cvs] [0e3d34e48f5] master: BLI: add StringRefNull.c_str() method
Jacques Lucke
noreply at git.blender.org
Fri Jul 17 12:38:25 CEST 2020
Commit: 0e3d34e48f5d5ed3845b1858a66008ab87c55af8
Author: Jacques Lucke
Date: Fri Jul 17 12:38:15 2020 +0200
Branches: master
https://developer.blender.org/rB0e3d34e48f5d5ed3845b1858a66008ab87c55af8
BLI: add StringRefNull.c_str() method
This should be used whenever you rely on the fact, that the
returned pointer points to the beginning of a null-terminated array.
===================================================================
M source/blender/blenkernel/intern/simulation.cc
M source/blender/blenlib/BLI_string_ref.hh
M source/blender/nodes/NOD_derived_node_tree.hh
M source/blender/nodes/NOD_node_tree_multi_function.hh
M source/blender/nodes/NOD_node_tree_ref.hh
===================================================================
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index b57d85e66ad..fdb0f0b235f 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -399,7 +399,7 @@ static void add_missing_particle_states(Simulation *simulation, Span<std::string
continue;
}
- BKE_simulation_state_add(simulation, SIM_STATE_TYPE_PARTICLES, name.data());
+ BKE_simulation_state_add(simulation, SIM_STATE_TYPE_PARTICLES, name.c_str());
}
}
diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh
index bcf2d20338e..5b555b8cd1d 100644
--- a/source/blender/blenlib/BLI_string_ref.hh
+++ b/source/blender/blenlib/BLI_string_ref.hh
@@ -187,7 +187,7 @@ class StringRefNull : public StringRefBase {
* Reference a std::string. Remember that when the std::string is destructed, the StringRefNull
* will point to uninitialized memory.
*/
- StringRefNull(const std::string &str) : StringRefNull(str.data())
+ StringRefNull(const std::string &str) : StringRefNull(str.c_str())
{
}
@@ -200,6 +200,16 @@ class StringRefNull : public StringRefBase {
BLI_assert(index <= size_);
return data_[index];
}
+
+ /**
+ * Returns the beginning of a null-terminated char array.
+ *
+ * This is like ->data(), but can only be called on a StringRefNull.
+ */
+ const char *c_str() const
+ {
+ return data_;
+ }
};
/**
diff --git a/source/blender/nodes/NOD_derived_node_tree.hh b/source/blender/nodes/NOD_derived_node_tree.hh
index 24144496c92..84370dcd399 100644
--- a/source/blender/nodes/NOD_derived_node_tree.hh
+++ b/source/blender/nodes/NOD_derived_node_tree.hh
@@ -477,7 +477,7 @@ inline Span<const DNode *> DerivedNodeTree::nodes() const
inline Span<const DNode *> DerivedNodeTree::nodes_by_type(StringRefNull idname) const
{
- const bNodeType *nodetype = nodeTypeFind(idname.data());
+ const bNodeType *nodetype = nodeTypeFind(idname.c_str());
return this->nodes_by_type(nodetype);
}
diff --git a/source/blender/nodes/NOD_node_tree_multi_function.hh b/source/blender/nodes/NOD_node_tree_multi_function.hh
index d40a630c9f2..f7a1fbb114d 100644
--- a/source/blender/nodes/NOD_node_tree_multi_function.hh
+++ b/source/blender/nodes/NOD_node_tree_multi_function.hh
@@ -240,7 +240,7 @@ class MFNetworkBuilderBase {
BLI_STATIC_ASSERT((std::is_base_of_v<fn::MultiFunction, T>), "");
void *buffer = common_.resources.linear_allocator().allocate(sizeof(T), alignof(T));
T *fn = new (buffer) T(std::forward<Args>(args)...);
- common_.resources.add(destruct_ptr<T>(fn), fn->name().data());
+ common_.resources.add(destruct_ptr<T>(fn), fn->name().c_str());
return *fn;
}
};
diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh
index b5e4a768bd3..907184125b8 100644
--- a/source/blender/nodes/NOD_node_tree_ref.hh
+++ b/source/blender/nodes/NOD_node_tree_ref.hh
@@ -405,7 +405,7 @@ inline Span<const NodeRef *> NodeTreeRef::nodes() const
inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) const
{
- const bNodeType *nodetype = nodeTypeFind(idname.data());
+ const bNodeType *nodetype = nodeTypeFind(idname.c_str());
return this->nodes_by_type(nodetype);
}
More information about the Bf-blender-cvs
mailing list