[Bf-blender-cvs] [12149d8e1bc] functions: initial string map

Jacques Lucke noreply at git.blender.org
Thu Jul 11 17:15:47 CEST 2019


Commit: 12149d8e1bccae61dcf00bb741dc817a46a7770f
Author: Jacques Lucke
Date:   Thu Jul 11 15:50:46 2019 +0200
Branches: functions
https://developer.blender.org/rB12149d8e1bccae61dcf00bb741dc817a46a7770f

initial string map

===================================================================

A	source/blender/blenlib/BLI_string_map.hpp
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/simulations/bparticles/inserters.cpp
M	source/blender/simulations/bparticles/inserters.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_string_map.hpp b/source/blender/blenlib/BLI_string_map.hpp
new file mode 100644
index 00000000000..d93c240d53e
--- /dev/null
+++ b/source/blender/blenlib/BLI_string_map.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "BLI_small_map.hpp"
+#include "BLI_string_ref.hpp"
+
+namespace BLI {
+
+template<typename V> class StringMap {
+ private:
+  SmallMap<std::string, V> m_map;
+
+ public:
+  StringMap() = default;
+
+  void add_new(StringRef key, const V &value)
+  {
+    m_map.add_new(key.to_std_string(), value);
+  }
+
+  V &lookup(StringRef key) const
+  {
+    return m_map.lookup(key);
+  }
+
+  decltype(m_map.items()) items() const
+  {
+    return m_map.items();
+  }
+};
+
+}  // namespace BLI
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 2968faa42c9..e809cadf952 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -257,6 +257,7 @@ set(SRC
   BLI_small_set.hpp
   BLI_small_set_vector.hpp
   BLI_small_stack.hpp
+  BLI_string_map.hpp
   BLI_string_ref.hpp
   BLI_timeit.hpp
   BLI_vector_adaptor.hpp
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 09f462227f9..740444ef9a2 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -241,25 +241,25 @@ static std::unique_ptr<Emitter> BUILD_EMITTER_mesh_surface(BuildContext &ctx,
   return EMITTER_mesh_surface(particle_type_name, fn, ctx.world_state, std::move(action));
 }
 
-BLI_LAZY_INIT(ForceFromNodeCallbackMap, get_force_builders)
+BLI_LAZY_INIT(StringMap<ForceFromNodeCallback>, get_force_builders)
 {
-  ForceFromNodeCallbackMap map;
+  StringMap<ForceFromNodeCallback> map;
   map.add_new("bp_GravityForceNode", BUILD_FORCE_gravity);
   map.add_new("bp_TurbulenceForceNode", BUILD_FORCE_turbulence);
   return map;
 }
 
-BLI_LAZY_INIT(EventFromNodeCallbackMap, get_event_builders)
+BLI_LAZY_INIT(StringMap<EventFromNodeCallback>, get_event_builders)
 {
-  EventFromNodeCallbackMap map;
+  StringMap<EventFromNodeCallback> map;
   map.add_new("bp_MeshCollisionEventNode", Build_EVENT_mesh_collision);
   map.add_new("bp_AgeReachedEventNode", BUILD_EVENT_age_reached);
   return map;
 }
 
-BLI_LAZY_INIT(EmitterFromNodeCallbackMap, get_emitter_builders)
+BLI_LAZY_INIT(StringMap<EmitterFromNodeCallback>, get_emitter_builders)
 {
-  EmitterFromNodeCallbackMap map;
+  StringMap<EmitterFromNodeCallback> map;
   map.add_new("bp_PointEmitterNode", BUILD_EMITTER_point);
   map.add_new("bp_MeshEmitterNode", BUILD_EMITTER_mesh_surface);
   return map;
diff --git a/source/blender/simulations/bparticles/inserters.hpp b/source/blender/simulations/bparticles/inserters.hpp
index bc2ee622854..4e300513f3e 100644
--- a/source/blender/simulations/bparticles/inserters.hpp
+++ b/source/blender/simulations/bparticles/inserters.hpp
@@ -4,6 +4,7 @@
 
 #include "BKE_node_tree.hpp"
 #include "FN_data_flow_nodes.hpp"
+#include "BLI_string_map.hpp"
 
 #include "world_state.hpp"
 #include "step_description.hpp"
@@ -14,6 +15,7 @@ namespace BParticles {
 using BKE::bSocketList;
 using BKE::IndexedNodeTree;
 using BKE::SocketWithNode;
+using BLI::StringMap;
 using FN::DataFlowNodes::BTreeDataGraph;
 
 struct BuildContext {
@@ -25,20 +27,17 @@ struct BuildContext {
 
 using ForceFromNodeCallback =
     std::function<std::unique_ptr<Force>(BuildContext &ctx, bNode *bnode)>;
-using ForceFromNodeCallbackMap = SmallMap<std::string, ForceFromNodeCallback>;
 
-ForceFromNodeCallbackMap &get_force_builders();
+StringMap<ForceFromNodeCallback> &get_force_builders();
 
 using EventFromNodeCallback =
     std::function<std::unique_ptr<Event>(BuildContext &ctx, bNode *bnode)>;
-using EventFromNodeCallbackMap = SmallMap<std::string, EventFromNodeCallback>;
 
-EventFromNodeCallbackMap &get_event_builders();
+StringMap<EventFromNodeCallback> &get_event_builders();
 
 using EmitterFromNodeCallback = std::function<std::unique_ptr<Emitter>(
     BuildContext &ctx, bNode *bnode, StringRef particle_type_name)>;
-using EmitterFromNodeCallbackMap = SmallMap<std::string, EmitterFromNodeCallback>;
 
-EmitterFromNodeCallbackMap &get_emitter_builders();
+StringMap<EmitterFromNodeCallback> &get_emitter_builders();
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list