[Bf-blender-cvs] [a5260c143ce] functions: implicitely convert StringRef to std::string
Jacques Lucke
noreply at git.blender.org
Mon Aug 26 09:38:37 CEST 2019
Commit: a5260c143ce6ca5a8b08d54b7cde3c36664f3134
Author: Jacques Lucke
Date: Mon Aug 26 09:37:04 2019 +0200
Branches: functions
https://developer.blender.org/rBa5260c143ce6ca5a8b08d54b7cde3c36664f3134
implicitely convert StringRef to std::string
===================================================================
M source/blender/blenkernel/BKE_node_tree.hpp
M source/blender/blenlib/BLI_string_ref.hpp
M source/blender/functions/core/type.hpp
M source/blender/functions/frontends/data_flow_nodes/mappings.cpp
M source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
M source/blender/simulations/bparticles/attributes.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
M source/blender/simulations/bparticles/particle_function_builder.cpp
M source/blender/simulations/bparticles/particle_set.cpp
M source/blender/simulations/bparticles/particles_state.hpp
M tests/gtests/blenlib/BLI_string_map_test.cc
M tests/gtests/blenlib/BLI_string_ref_test.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node_tree.hpp b/source/blender/blenkernel/BKE_node_tree.hpp
index 52998a1e5cb..73a196d10e5 100644
--- a/source/blender/blenkernel/BKE_node_tree.hpp
+++ b/source/blender/blenkernel/BKE_node_tree.hpp
@@ -68,7 +68,7 @@ class VirtualNodeTree {
ArrayRef<VirtualNode *> nodes_with_idname(StringRef idname)
{
BLI_assert(m_frozen);
- return m_nodes_by_idname.lookup_default(idname.to_std_string());
+ return m_nodes_by_idname.lookup_default(idname);
}
bool is_frozen()
diff --git a/source/blender/blenlib/BLI_string_ref.hpp b/source/blender/blenlib/BLI_string_ref.hpp
index 8ae4049789f..00648cc0957 100644
--- a/source/blender/blenlib/BLI_string_ref.hpp
+++ b/source/blender/blenlib/BLI_string_ref.hpp
@@ -79,6 +79,11 @@ class StringRefBase {
return ArrayRef<char>(m_data, m_size);
}
+ operator std::string() const
+ {
+ return std::string(m_data, m_size);
+ }
+
const char *begin() const
{
return m_data;
@@ -98,14 +103,6 @@ class StringRefBase {
* Returns true when the string ends with the given suffix. Otherwise false.
*/
bool endswith(StringRef suffix) const;
-
- /**
- * Convert the referenced string into a std::string object.
- */
- std::string to_std_string() const
- {
- return std::string(m_data, m_size);
- }
};
class StringRefNull : public StringRefBase {
@@ -183,19 +180,19 @@ class StringRef : public StringRefBase {
inline std::ostream &operator<<(std::ostream &stream, StringRef ref)
{
- stream << ref.to_std_string();
+ stream << std::string(ref);
return stream;
}
inline std::ostream &operator<<(std::ostream &stream, StringRefNull ref)
{
- stream << ref.to_std_string();
+ stream << std::string(ref.data(), ref.size());
return stream;
}
inline std::string operator+(StringRef a, StringRef b)
{
- return a.to_std_string() + b.to_std_string();
+ return std::string(a) + std::string(b);
}
inline bool operator==(StringRef a, StringRef b)
diff --git a/source/blender/functions/core/type.hpp b/source/blender/functions/core/type.hpp
index c03b5fd6006..d3e5d2859a9 100644
--- a/source/blender/functions/core/type.hpp
+++ b/source/blender/functions/core/type.hpp
@@ -92,7 +92,7 @@ class Type final {
/* Type inline functions
****************************************/
-inline Type::Type(StringRef name) : m_name(name.to_std_string())
+inline Type::Type(StringRef name) : m_name(name)
{
}
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
index 3ee9e739e55..7aaa1ec6007 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings.cpp
@@ -38,8 +38,8 @@ void TypeMappings::register_type(StringRef idname, StringRef name, Type *type)
{
m_type_by_idname.add_new(idname, type);
m_type_by_name.add_new(name, type);
- m_name_by_idname.add_new(idname, name.to_std_string());
- m_idname_by_name.add_new(name, idname.to_std_string());
+ m_name_by_idname.add_new(idname, name);
+ m_idname_by_name.add_new(name, idname);
}
void NodeInserters::register_inserter(StringRef idname, NodeInserter inserter)
@@ -94,8 +94,7 @@ void LinkInserters::register_conversion_inserter(StringRef from_type,
{
StringRef from_idname = m_type_mappings->idname_by_name(from_type);
StringRef to_idname = m_type_mappings->idname_by_name(to_type);
- m_conversion_inserters.add_new(
- StringPair(from_idname.to_std_string(), to_idname.to_std_string()), inserter);
+ m_conversion_inserters.add_new(StringPair(from_idname, to_idname), inserter);
}
void LinkInserters::register_conversion_function(StringRef from_type,
diff --git a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
index 6b3100a9d88..51b762f8dd8 100644
--- a/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/vtree_data_graph_builder.cpp
@@ -98,7 +98,7 @@ class NodeSource : public SourceInfo {
PyObject *function = PyDict_GetItemString(globals, "report_warning");
PyObject *py_bnode = get_py_bnode(m_btree, m_bnode);
- PyObject *ret = PyObject_CallFunction(function, "Os", py_bnode, msg.to_std_string().c_str());
+ PyObject *ret = PyObject_CallFunction(function, "Os", py_bnode, std::string(msg).c_str());
Py_DECREF(ret);
PyGILState_Release(gilstate);
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index b11a2133141..5ca8c9d4dd0 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -115,7 +115,7 @@ class AttributesDeclaration {
template<typename T> void add(StringRef name, T default_value)
{
- if (m_names.add(name.to_std_string())) {
+ if (m_names.add(name)) {
AttributeType type = attribute_type_by_type<T>::value;
m_types.append(type);
m_defaults.append(AnyAttributeValue::FromValue(default_value));
@@ -199,7 +199,7 @@ class AttributesInfo {
*/
int attribute_index_try(StringRef name) const
{
- return m_names.index_try(name.to_std_string());
+ return m_names.index_try(name);
}
/**
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 936cc35f431..c82bb5feb94 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -300,7 +300,7 @@ void BParticles_modifier_cache_state(BParticlesModifierData *bpmd,
state.particle_containers().foreach_key_value_pair(
[&container_names, &containers](StringRefNull name, ParticlesContainer *container) {
- container_names.append(name.to_std_string());
+ container_names.append(name);
containers.append(container);
});
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 11316f83aba..137db54ee45 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -26,7 +26,7 @@ class AgeReachedEvent : public Event {
AgeReachedEvent(StringRef identifier,
std::unique_ptr<ParticleFunction> compute_inputs,
std::unique_ptr<Action> action)
- : m_identifier(identifier.to_std_string()),
+ : m_identifier(identifier),
m_compute_inputs(std::move(compute_inputs)),
m_action(std::move(action))
{
@@ -88,7 +88,7 @@ class MeshCollisionEvent : public Event {
public:
MeshCollisionEvent(StringRef identifier, Object *object, std::unique_ptr<Action> action)
- : m_identifier(identifier.to_std_string()), m_object(object), m_action(std::move(action))
+ : m_identifier(identifier), m_object(object), m_action(std::move(action))
{
BLI_assert(object->type == OB_MESH);
m_local_to_world = m_object->obmat;
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index cd2c45a9356..c5e9bb8b34e 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -463,7 +463,7 @@ std::unique_ptr<StepDescription> step_description_from_node_tree(VirtualNodeTree
Vector<std::string> type_names;
for (VirtualNode *vnode : vtree.nodes_with_idname("bp_ParticleTypeNode")) {
StringRef name = vnode->name();
- type_names.append(name.to_std_string());
+ type_names.append(name);
}
for (std::string &type_name : type_names) {
diff --git a/source/blender/simulations/bparticles/particle_function_builder.cpp b/source/blender/simulations/bparticles/particle_function_builder.cpp
index 5e532bc4936..f7f918f92da 100644
--- a/source/blender/simulations/bparticles/particle_function_builder.cpp
+++ b/source/blender/simulations/bparticles/particle_function_builder.cpp
@@ -59,7 +59,7 @@ class AttributeInputProvider : public ParticleFunctionInputProvider {
std::string m_name;
public:
- AttributeInputProvider(StringRef name) : m_name(name.to_std_string())
+ AttributeInputProvider(StringRef name) : m_name(name)
{
}
diff --git a/source/blender/simulations/bparticles/particle_set.cpp b/source/blender/simulations/bparticles/particle_set.cpp
index 6ada6e1fad5..9c40d43c8d2 100644
--- a/source/blender/simulations/bparticles/particle_set.cpp
+++ b/source/blender/simulations/bparticles/particle_set.cpp
@@ -5,9 +5,7 @@ namespace BParticles {
ParticleSets::ParticleSets(StringRef particle_type_name,
AttributesInfo &attributes_info,
ArrayRef<ParticleSet> sets)
- : m_particle_type_name(particle_type_name.to_std_string()),
- m_attributes_info(attributes_info),
- m_sets(sets)
+ : m_particle_type_name(particle_type_name), m_attributes_info(attributes_info), m_sets(sets)
{
m_size = 0;
for (auto &set : sets) {
diff --git a/source/blender/simulations/bparticles/particles_state.hpp b/source/blender/simulations/bparticles/particles_state.hpp
index a31890384c2..df4703188f2 100644
--- a/source/blender/simulations/bparticles/particles_state.hpp
+++ b/source/blender/simulations/bparticles/particles_state.hpp
@@ -67,7 +67,7 @@ inline StringMap<ParticlesContainer *> &ParticlesState::particle_containers()
inline ParticlesContainer &ParticlesState::particle_container(StringRef name)
{
- return *m_container_by_id.lookup(name.to_std_string());
+ return *m_container_by_id.lookup(name);
}
inline StringRefNull ParticlesState::particle_container_name(ParticlesContainer &container)
diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc
index 96ed0e9b8fd..1c4d5aa3af2 100644
--- a/tests/gtests/blenlib/BLI_string_map_test.cc
+++ b/tests/gtests/blenlib/BLI_string_map_test.cc
@@ -162,7 +162,7 @@ TEST(string_map, ForeachKey)
map.add_new("C", 1);
Vector<std::string> keys;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list