16const std::map<std::string, ChiObjectFactory::ObjectRegistryEntry>&
37 Chi::log.
Log() <<
"Making object with type from parameters";
39 const std::string fname = __PRETTY_FUNCTION__;
41 if (not params.
Has(
"chi_obj_type"))
42 throw std::invalid_argument(
43 fname +
": Requires a parameter block with a field called "
44 "\"chi_obj_type\". The given parameter block does not seem to "
45 "have this parameter.");
47 const auto type = params.
GetParamValue<std::string>(
"chi_obj_type");
59 Chi::log.
Log() <<
"Making object with specified type";
61 const std::string fname = __PRETTY_FUNCTION__;
64 throw std::logic_error(fname +
": No registered type \"" + type +
73 "Object is not constructable since it has no registered "
76 auto input_params = object_entry.get_in_params_func();
78 input_params.SetObjectType(type);
79 input_params.SetErrorOriginScope(type);
82 Chi::log.
Log() <<
"Assigning parameters for object " << type;
84 input_params.AssignParameters(params);
89 auto new_object = object_entry.constructor_func(input_params);
91 new_object->PushOntoStack(new_object);
94 Chi::log.
Log() <<
"Done making object type " << type <<
" with handle "
95 << new_object->StackID();
97 return new_object->StackID();
107 "Object type \"" + type +
108 "\" is not registered in ChiObjectFactory.");
110 auto& reg_entry = iter->second;
112 return reg_entry.get_in_params_func();
130 if (entry.constructor_func ==
nullptr)
133 const auto in_params = entry.get_in_params_func();
134 in_params.DumpParameters();
145 const std::string& key,
const std::string& calling_function)
const
149 calling_function +
": Attempted to register Object \"" + key +
150 "\" but an object with the same name is already registered.");
#define ChiLogicalErrorIf(condition, message)
#define ChiLogicalError(message)
#define ChiInvalidArgumentIf(condition, message)
void DumpRegister() const
Dumps the object registry to stdout.
bool RegistryHasKey(const std::string &key) const
void AssertRegistryKeyAvailable(const std::string &key, const std::string &calling_function) const
size_t MakeRegisteredObject(const chi::ParameterBlock ¶ms) const
std::map< std::string, ObjectRegistryEntry > object_registry_
chi::InputParameters GetRegisteredObjectParameters(const std::string &type) const
const std::map< std::string, ObjectRegistryEntry > & Registry() const
size_t MakeRegisteredObjectOfType(const std::string &type, const chi::ParameterBlock ¶ms) const
static ChiObjectFactory & GetInstance() noexcept
LogStream Log(LOG_LVL level=LOG_0)
bool Has(const std::string ¶m_name) const
T GetParamValue(const std::string ¶m_name) const