5#include <unordered_map>
8#include "AMReX_Print.H"
64template <
class Base,
class... Args>
72 static std::unique_ptr<Base>
create(
const std::string& key, Args... args)
75 auto ptr =
table().at(key)(std::forward<Args>(args)...);
76 amrex::Print() <<
"Creating " << Base::base_identifier()
77 <<
" instance: " << key << std::endl;
85 static void print(std::ostream& os)
87 const auto& tbl =
table();
88 os << Base::base_identifier() <<
" " << tbl.size() << std::endl;
89 for (
const auto& it : tbl) {
90 os <<
" - " << it.first << std::endl;
105 [](Args... args) -> std::unique_ptr<Base> {
106 return std::unique_ptr<Base>(
107 new T(std::forward<Args>(args)...));
116 const auto& it = tbl.find(T::identifier());
136 const auto& tbl =
table();
137 if (tbl.find(key) == tbl.end()) {
139 if (amrex::ParallelDescriptor::IOProcessor()) {
144 "In " + Base::base_identifier() +
145 " cannot find instance: " + key);
159template <
class Base,
class... Args>
161bool Factory<Base, Args...>::Register<T>::registered =
Solver for PArallel Discrete Event Simulation.
Definition ConsoleIO.cpp:14
Class to handle registration of subclass for runtime selection.
Definition Factory.H:97
static bool registered
Definition Factory.H:99
friend T
Definition Factory.H:98
~Register() override
Definition Factory.H:112
static bool add_sub_type()
Definition Factory.H:101
Register()
Definition Factory.H:122
static void print(std::ostream &os)
Definition Factory.H:85
static void key_exists_or_error(const std::string &key)
Definition Factory.H:134
std::unordered_map< std::string, CreatorFunc > LookupTable
Definition Factory.H:130
virtual ~Factory()=default
static std::unique_ptr< Base > create(const std::string &key, Args... args)
Definition Factory.H:72
std::unique_ptr< Base >(*)(Args...) CreatorFunc
Definition Factory.H:129
static LookupTable & table()
Lookup table containing all registered instances.
Definition Factory.H:150
friend Base
Definition Factory.H:126