1 #ifndef ERF_SURFACE_ENGINE_REGISTRY_H
2 #define ERF_SURFACE_ENGINE_REGISTRY_H
25 template <
class Engine,
class Params>
30 using Creator = std::function<std::unique_ptr<Engine>(
const Params&)>;
35 auto& registry =
map();
36 const std::string macro = std::string(
"ERF_REGISTER_") +
names.upper +
"_ENGINE";
38 amrex::Abort(
names.tag() +
" " + macro +
": an engine registered an empty name");
40 if (registry.count(
name) > 0) {
41 amrex::Abort(
names.tag() +
" " + macro +
": two engines registered the name \"" +
name
42 +
"\"; each engine directory in the build must use its own name");
44 registry.emplace(
name, std::move(creator));
49 static std::vector<std::string>
names ()
51 std::vector<std::string> out;
52 for (
const auto& kv :
map()) { out.push_back(kv.first); }
57 static std::unique_ptr<Engine>
make (
const std::string&
name,
const Params& params)
59 const auto& registry =
map();
60 const auto it = registry.find(
name);
61 if (it == registry.end()) {
return nullptr; }
62 return it->second(params);
68 static std::map<std::string, Creator>&
map ()
70 static std::map<std::string, Creator> registry;
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
The names a surface coupling uses in its inputs and messages.
Definition: ERF_SurfaceEngineRegistry.H:27
static std::unique_ptr< Engine > make(const std::string &name, const Params ¶ms)
The engine registered under name, or nullptr.
Definition: ERF_SurfaceEngineRegistry.H:57
static std::map< std::string, Creator > & map()
Definition: ERF_SurfaceEngineRegistry.H:68
static bool add(const SurfaceCouplingNames &names, const std::string &name, Creator creator)
Add an engine; aborts on an empty name or a name registered twice.
Definition: ERF_SurfaceEngineRegistry.H:33
static std::vector< std::string > names()
The registered names, sorted.
Definition: ERF_SurfaceEngineRegistry.H:49
std::function< std::unique_ptr< Engine >(const Params &)> Creator
Creates an engine from the coupling inputs.
Definition: ERF_SurfaceEngineRegistry.H:30
Definition: ERF_SurfaceCouplingNames.H:18