33 #ifndef __H__UG_factory
34 #define __H__UG_factory
36 #include <boost/static_assert.hpp>
37 #include <boost/mpl/for_each.hpp>
38 #include <boost/mpl/vector.hpp>
39 #include <boost/type_traits/is_base_of.hpp>
40 #include "../boost_serialization.h"
48 template <
class TBase,
class TDerived>
73 template <
class TBase,
class TPairSeq = boost::mpl::vector<> >
80 boost::mpl::for_each<TPairSeq>(
func);
85 return create(className.c_str());
100 typename class_map_t::iterator iclass =
m_classMap.find(std::string(className));
102 "Unregistered class-name used in 'Factory::create_raw': " << className);
103 return iclass->second.factory();
106 template <
class TDerived>
110 BOOST_STATIC_ASSERT((boost::is_base_of<TBase, TDerived>::value));
112 std::string className(
name);
116 &detail::factory::DerivedClassFactory<TBase, TDerived>);
118 std::string typeName(
typeid(TDerived).
name());
128 std::string typeName =
typeid(cls).
name();
129 class_name_map_t::const_iterator i =
m_classNameMap.find(typeName);
132 static const std::string defaultName (
"");
137 typedef TBase* (*factory_sig)();
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:108
A factory class which creates instances given a class-name.
Definition: factory.h:75
std::map< std::string, ClassInfo > class_map_t
Definition: factory.h:151
class_name_map_t m_classNameMap
key: type-name, value: class-names
Definition: factory.h:154
std::vector< std::string > m_classNames
Definition: factory.h:155
std::map< std::string, std::string > class_name_map_t
Definition: factory.h:152
class_map_t m_classMap
contains ClassInfo objects accessible by class-name.
Definition: factory.h:153
SmartPtr< TBase > create(const std::string &className)
Definition: factory.h:83
TBase * create_raw(const char *className)
Definition: factory.h:98
SmartPtr< TBase > create(const char *className)
Definition: factory.h:88
void register_class(const char *name)
Definition: factory.h:107
TBase * create_raw(const std::string &className)
Definition: factory.h:93
size_t num_classes() const
Definition: factory.h:124
TBase *(* factory_sig)()
Definition: factory.h:137
const std::string & class_name(const TBase &cls) const
Definition: factory.h:126
Factory()
Definition: factory.h:77
const std::string & class_name(const size_t i) const
Definition: factory.h:125
string ClassInfo(const IExportedClass &c)
Prints the (const) method of one class.
Definition: class_helper.cpp:376
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
TBase * DerivedClassFactory()
used internally to construct derived classes of a given type
Definition: factory.h:49
function func(x, y, z, t, si)
Definition: factory.h:139
factory_sig factory
Definition: factory.h:148
const char * name
Definition: factory.h:147
ClassInfo()
Definition: factory.h:140
ClassInfo(const char *_name, factory_sig _factory)
Definition: factory.h:141
Definition: register_type_pair_functor.h:43