ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
SurfaceEngineRegistry< Engine, Params > Class Template Reference

#include <ERF_SurfaceEngineRegistry.H>

Public Types

using Creator = std::function< std::unique_ptr< Engine >(const Params &)>
 Creates an engine from the coupling inputs. More...
 

Static Public Member Functions

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. More...
 
static std::vector< std::string > names ()
 The registered names, sorted. More...
 
static std::unique_ptr< Engine > make (const std::string &name, const Params &params)
 The engine registered under name, or nullptr. More...
 

Static Private Member Functions

static std::map< std::string, Creator > & map ()
 

Member Typedef Documentation

◆ Creator

template<class Engine , class Params >
using SurfaceEngineRegistry< Engine, Params >::Creator = std::function<std::unique_ptr<Engine>(const Params&)>

Creates an engine from the coupling inputs.

Member Function Documentation

◆ add()

template<class Engine , class Params >
static bool SurfaceEngineRegistry< Engine, Params >::add ( const SurfaceCouplingNames &  names,
const std::string &  name,
Creator  creator 
)
inlinestatic

Add an engine; aborts on an empty name or a name registered twice.

34  {
35  auto& registry = map();
36  const std::string macro = std::string("ERF_REGISTER_") + names.upper + "_ENGINE";
37  if (name.empty()) {
38  amrex::Abort(names.tag() + " " + macro + ": an engine registered an empty name");
39  }
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");
43  }
44  registry.emplace(name, std::move(creator));
45  return true;
46  }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
static std::map< std::string, Creator > & map()
Definition: ERF_SurfaceEngineRegistry.H:68
static std::vector< std::string > names()
The registered names, sorted.
Definition: ERF_SurfaceEngineRegistry.H:49

Referenced by register_fire_engine(), and register_flood_engine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make()

template<class Engine , class Params >
static std::unique_ptr<Engine> SurfaceEngineRegistry< Engine, Params >::make ( const std::string &  name,
const Params &  params 
)
inlinestatic

The engine registered under name, or nullptr.

58  {
59  const auto& registry = map();
60  const auto it = registry.find(name);
61  if (it == registry.end()) { return nullptr; }
62  return it->second(params);
63  }

Referenced by make_fire_engine(), and make_flood_engine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ map()

template<class Engine , class Params >
static std::map<std::string, Creator>& SurfaceEngineRegistry< Engine, Params >::map ( )
inlinestaticprivate
69  {
70  static std::map<std::string, Creator> registry;
71  return registry;
72  }

Referenced by SurfaceEngineRegistry< Engine, Params >::add(), SurfaceEngineRegistry< Engine, Params >::make(), and SurfaceEngineRegistry< Engine, Params >::names().

Here is the caller graph for this function:

◆ names()

template<class Engine , class Params >
static std::vector<std::string> SurfaceEngineRegistry< Engine, Params >::names ( )
inlinestatic

The registered names, sorted.

50  {
51  std::vector<std::string> out;
52  for (const auto& kv : map()) { out.push_back(kv.first); }
53  return out; // std::map keeps them sorted
54  }

Referenced by SurfaceEngineRegistry< Engine, Params >::add(), fire_engine_names(), and flood_engine_names().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: