18 #ifndef FIELD_RECORD_FACTORY_HH_
19 #define FIELD_RECORD_FACTORY_HH_
25 #include <boost/functional/factory.hpp>
26 #include <boost/any.hpp>
39 <<
" isn't registered in factory for type " << EI_TypeName::val <<
"!");
63 typedef SomeBase FactoryBaseType;
66 static const Input::Type::Record & get_input_type();
77 const int SomeDescendant::reg =
78 Input::register_class< SomeDescendant >("SomeDescendant") +
79 SomeDescendant::get_input_type().size();
82 * Factory allow to accept constructor with one or more parameters. In this case Factory is
83 * also templated by these parameters. For example Factory< SomeBase, int, double > accepts
84 * constructors with two parameters (int, double).
86 * If registered class is templated the following design have to be used:
89 template <int dimension>
90 class SomeDescendant : public SomeBase<dimension>
95 SomeDescendant(double time) {}
100 const int SomeDescendant::reg =
101 Input::register_class< SomeDescendant<dimension>, double >("SomeDescendant") +
102 SomeDescendant<dimension>::get_input_type().size();
105 * Factory can be used in two ways:
106 * - through Factory::create method
107 * Example for constructor with one parameter:
109 SomeBase * sb = Input::Factory< SomeBase, double >::instance()->create("SomeDescendant", 0.1);
111 * - through AbstractRecord::factory method. This possibility can be used if base class has defined
112 * AbstractRecord and its descendants contain Record derived from this AbstractRecord.
113 * Example for same constructor:
115 AbstractRecord a_rec = record.val<AbstractRecord>("problem");
116 SomeBase * sb = a_rec.factory< SomeBase, double>(0.25);
117 // If arguments types can be deduced (by compiler) from actual arguments one can even use:
118 SomeBase * sb = a_rec.factory< SomeBase >(0.25);
121 * For correct functionality must be used two macros defined in global_defs.h:
122 * - FLOW123D_FORCE_LINK_IN_CHILD(x)
123 * - FLOW123D_FORCE_LINK_IN_PARENT(x)
124 * First is used in C source file of descendant class out of class methods, e.g.:
125 * FLOW123D_FORCE_LINK_IN_CHILD(gmsh)
126 * Second is used in C source file of parent class in any of class method with same parameter as in
128 * FLOW123D_FORCE_LINK_IN_PARENT(gmsh)
131 template <
class Type,
class... Arguments>
140 template <
class Child>
145 shared_ptr<Type>
const create(
string name, Arguments... arguments)
const;
170 template <
class ChildType,
class... Arguments>
179 #endif // FIELD_RECORD_FACTORY_HH_