1#ifndef CHITECH_OBJECT_FACTORY_H
2#define CHITECH_OBJECT_FACTORY_H
10#define ChiObjectFactoryJoinWordsA(x, y) x##y
12#define ChiObjectFactoryJoinWordsB(x, y) ChiObjectFactoryJoinWordsA(x, y)
22#define RegisterChiObject(namespace_name, object_name) \
23 static char ChiObjectFactoryJoinWordsB( \
24 unique_var_name_object_##object_name##_, __COUNTER__) = \
25 ChiObjectFactory::AddObjectToRegistry<object_name, ChiObject>( \
26 #namespace_name, #object_name)
38#define RegisterChiObjectParametersOnly(namespace_name, object_name) \
39 static char ChiObjectFactoryJoinWordsB( \
40 unique_var_name_object_##object_name##_, __COUNTER__) = \
41 ChiObjectFactory::AddObjectToRegistryParamsOnly<object_name>( \
42 #namespace_name, #object_name)
55#define RegisterSyntaxBlock(namespace_name, block_name, syntax_function) \
56 static char ChiObjectFactoryJoinWordsB( \
57 unique_var_name_syntax_##block_name##_, __COUNTER__) = \
58 ChiObjectFactory::AddSyntaxBlockToRegistry( \
59 #namespace_name, #block_name, syntax_function)
90 template <typename T, typename base_T>
92 const std::
string& object_name)
96 const std::string name = namespace_name +
"::" + object_name;
97 object_maker.AssertRegistryKeyAvailable(name, __PRETTY_FUNCTION__);
102 object_maker.object_registry_.insert(std::make_pair(name, reg_entry));
107 template <
typename T>
109 const std::string& object_name)
113 const std::string name = namespace_name +
"::" + object_name;
114 object_maker.AssertRegistryKeyAvailable(name, __PRETTY_FUNCTION__);
118 object_maker.object_registry_.insert(std::make_pair(name, reg_entry));
124 const std::string& block_name,
129 const std::string name = namespace_name +
"::" + block_name;
130 object_maker.AssertRegistryKeyAvailable(name, __PRETTY_FUNCTION__);
134 object_maker.object_registry_.insert(std::make_pair(name, reg_entry));
158 template <
typename T>
161 return T::GetInputParameters();
166 template <
typename T,
typename base_T>
167 static std::shared_ptr<base_T>
170 return std::make_shared<T>(params);
174 const std::string& calling_function)
const;
chi::InputParameters(*)() ObjectGetInParamsFunc
ChiObjectFactory()=default
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
static char AddSyntaxBlockToRegistry(const std::string &namespace_name, const std::string &block_name, ObjectGetInParamsFunc syntax_function)
std::map< std::string, ObjectRegistryEntry > object_registry_
chi::InputParameters GetRegisteredObjectParameters(const std::string &type) const
const std::map< std::string, ObjectRegistryEntry > & Registry() const
ChiObjectFactory(const ChiObjectFactory &)=delete
std::shared_ptr< ChiObject > ObjectPtr
static char AddObjectToRegistry(const std::string &namespace_name, const std::string &object_name)
ChiObjectFactory(const ChiObjectFactory &&)=delete
ObjectPtr(*)(const chi::InputParameters &) ObjectConstructorFunc
static chi::InputParameters CallGetInputParamsFunction()
static std::shared_ptr< base_T > CallObjectConstructor(const chi::InputParameters ¶ms)
size_t MakeRegisteredObjectOfType(const std::string &type, const chi::ParameterBlock ¶ms) const
static ChiObjectFactory & GetInstance() noexcept
ChiObjectFactory & operator=(const ChiObjectFactory &)=delete
static char AddObjectToRegistryParamsOnly(const std::string &namespace_name, const std::string &object_name)
ObjectGetInParamsFunc get_in_params_func
ObjectConstructorFunc constructor_func