[Bf-blender-cvs] [800a578ed79] functions: use StringMap everywhere
Jacques Lucke
noreply at git.blender.org
Thu Jul 11 17:15:49 CEST 2019
Commit: 800a578ed79a9255c428a043c2ca1f0a03bbcda0
Author: Jacques Lucke
Date: Thu Jul 11 16:30:46 2019 +0200
Branches: functions
https://developer.blender.org/rB800a578ed79a9255c428a043c2ca1f0a03bbcda0
use StringMap everywhere
===================================================================
M source/blender/blenlib/BLI_string_map.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M source/blender/functions/frontends/data_flow_nodes/inserters.hpp
M source/blender/simulations/bparticles/core.hpp
M source/blender/simulations/bparticles/inserters.cpp
M source/blender/simulations/bparticles/step_description.hpp
M source/blender/simulations/bparticles/world_state.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_string_map.hpp b/source/blender/blenlib/BLI_string_map.hpp
index d93c240d53e..bac3698feb1 100644
--- a/source/blender/blenlib/BLI_string_map.hpp
+++ b/source/blender/blenlib/BLI_string_map.hpp
@@ -17,15 +17,50 @@ template<typename V> class StringMap {
m_map.add_new(key.to_std_string(), value);
}
- V &lookup(StringRef key) const
+ void add_override(StringRef key, const V &value)
{
- return m_map.lookup(key);
+ m_map.add_override(key.to_std_string(), value);
+ }
+
+ V lookup(StringRef key) const
+ {
+ return m_map.lookup(key.to_std_string());
+ }
+
+ V *lookup_ptr(StringRef key) const
+ {
+ return m_map.lookup_ptr(key.to_std_string());
+ }
+
+ V lookup_default(StringRef key, const V &default_value) const
+ {
+ return m_map.lookup_default(key.to_std_string(), default_value);
+ }
+
+ V &lookup_ref(StringRef key) const
+ {
+ return m_map.lookup_ref(key.to_std_string());
+ }
+
+ bool contains(StringRef key) const
+ {
+ return m_map.contains(key.to_std_string());
}
decltype(m_map.items()) items() const
{
return m_map.items();
}
+
+ decltype(m_map.keys()) keys() const
+ {
+ return m_map.keys();
+ }
+
+ decltype(m_map.values()) values() const
+ {
+ return m_map.values();
+ }
};
} // namespace BLI
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
index 499d837c72c..662fe49147c 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
@@ -27,8 +27,7 @@ BLI_LAZY_INIT(GraphInserters, get_standard_inserters)
void GraphInserters::reg_node_inserter(std::string idname, NodeInserter inserter)
{
- BLI_assert(!m_node_inserters.contains(idname));
- m_node_inserters.add(idname, inserter);
+ m_node_inserters.add_new(idname, inserter);
}
void GraphInserters::reg_node_function(std::string idname, FunctionGetter getter)
@@ -43,8 +42,7 @@ void GraphInserters::reg_node_function(std::string idname, FunctionGetter getter
void GraphInserters::reg_socket_loader(std::string idname, SocketLoader loader)
{
- BLI_assert(!m_socket_loaders.contains(idname));
- m_socket_loaders.add(idname, loader);
+ m_socket_loaders.add_new(idname, loader);
}
void GraphInserters::reg_conversion_inserter(std::string from_type,
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.hpp b/source/blender/functions/frontends/data_flow_nodes/inserters.hpp
index 265ad436d21..4b1712a2033 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.hpp
@@ -3,6 +3,7 @@
#include "builder.hpp"
#include <functional>
#include "BLI_optional.hpp"
+#include "BLI_string_map.hpp"
#include "FN_tuple_call.hpp"
struct PointerRNA;
@@ -22,8 +23,8 @@ typedef std::function<SharedFunction()> FunctionGetter;
class GraphInserters {
private:
- SmallMap<std::string, NodeInserter> m_node_inserters;
- SmallMap<std::string, SocketLoader> m_socket_loaders;
+ StringMap<NodeInserter> m_node_inserters;
+ StringMap<SocketLoader> m_socket_loaders;
SmallMap<std::pair<std::string, std::string>, ConversionInserter> m_conversion_inserters;
public:
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 4f98f62495a..7d319387d80 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -10,6 +10,7 @@
#include "BLI_string_ref.hpp"
#include "BLI_small_map.hpp"
#include "BLI_vector_adaptor.hpp"
+#include "BLI_string_map.hpp"
#include "BLI_lazy_init.hpp"
#include "attributes.hpp"
@@ -18,6 +19,8 @@
namespace BParticles {
+using BLI::StringMap;
+
class EventFilterInterface;
class EventExecuteInterface;
class EmitterInterface;
@@ -178,7 +181,7 @@ class StepDescription {
*/
class ParticlesState {
private:
- SmallMap<std::string, ParticlesContainer *> m_container_by_id;
+ StringMap<ParticlesContainer *> m_container_by_id;
float m_current_time = 0.0f;
public:
@@ -194,7 +197,7 @@ class ParticlesState {
/**
* Access the mapping from particle type names to their corresponding containers.
*/
- SmallMap<std::string, ParticlesContainer *> &particle_containers();
+ StringMap<ParticlesContainer *> &particle_containers();
/**
* Get the container corresponding to a particle type name.
@@ -564,7 +567,7 @@ inline void ParticleType::attributes(AttributesInfoBuilder &UNUSED(builder))
/* ParticlesState inline functions
********************************************/
-inline SmallMap<std::string, ParticlesContainer *> &ParticlesState::particle_containers()
+inline StringMap<ParticlesContainer *> &ParticlesState::particle_containers()
{
return m_container_by_id;
}
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 740444ef9a2..88875b82557 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -105,7 +105,6 @@ static SharedFunction create_function_for_data_inputs(bNode *bnode,
static std::unique_ptr<Action> build_action(BuildContext &ctx, SocketWithNode start);
using ActionFromNodeCallback =
std::function<std::unique_ptr<Action>(BuildContext &ctx, bNode *bnode)>;
-using ActionFromNodeCallbackMap = SmallMap<std::string, ActionFromNodeCallback>;
static std::unique_ptr<Action> BUILD_ACTION_kill(BuildContext &UNUSED(ctx), bNode *UNUSED(bnode))
{
@@ -158,9 +157,9 @@ static std::unique_ptr<Action> BUILD_ACTION_condition(BuildContext &ctx, bNode *
return ACTION_condition(particle_fn, std::move(true_action), std::move(false_action));
}
-BLI_LAZY_INIT_STATIC(ActionFromNodeCallbackMap, get_action_builders)
+BLI_LAZY_INIT_STATIC(StringMap<ActionFromNodeCallback>, get_action_builders)
{
- ActionFromNodeCallbackMap map;
+ StringMap<ActionFromNodeCallback> map;
map.add_new("bp_KillParticleNode", BUILD_ACTION_kill);
map.add_new("bp_ChangeParticleDirectionNode", BUILD_ACTION_change_direction);
map.add_new("bp_ExplodeParticleNode", BUILD_ACTION_explode);
diff --git a/source/blender/simulations/bparticles/step_description.hpp b/source/blender/simulations/bparticles/step_description.hpp
index 2703d658a5b..29e3b287afb 100644
--- a/source/blender/simulations/bparticles/step_description.hpp
+++ b/source/blender/simulations/bparticles/step_description.hpp
@@ -39,7 +39,7 @@ class ModifierParticleType : public ParticleType {
class ModifierStepDescription : public StepDescription {
public:
float m_duration;
- SmallMap<std::string, ModifierParticleType *> m_types;
+ StringMap<ModifierParticleType *> m_types;
SmallVector<Emitter *> m_emitters;
SmallVector<std::string> m_particle_type_names;
diff --git a/source/blender/simulations/bparticles/world_state.hpp b/source/blender/simulations/bparticles/world_state.hpp
index 3eb257ae3b4..e88997f9a21 100644
--- a/source/blender/simulations/bparticles/world_state.hpp
+++ b/source/blender/simulations/bparticles/world_state.hpp
@@ -3,16 +3,18 @@
#include "BLI_math.hpp"
#include "BLI_small_map.hpp"
#include "BLI_string_ref.hpp"
+#include "BLI_string_map.hpp"
namespace BParticles {
using BLI::float4x4;
using BLI::SmallMap;
+using BLI::StringMap;
using BLI::StringRef;
class WorldState {
private:
- SmallMap<std::string, float4x4> m_matrices;
+ StringMap<float4x4> m_matrices;
public:
float4x4 update(StringRef id, float4x4 value)
More information about the Bf-blender-cvs
mailing list