11 #include "classdesc.h"
19 template <
class B,
class Type>
24 virtual B*
create()
const=0;
26 typedef std::map<Type, shared_ptr<CreatorBase> > Fmap;
30 struct Creator:
public CreatorBase
32 B*
create()
const {
return new T();}
41 (make_pair(t, shared_ptr<CreatorBase>(
new Creator<T>)));
45 {registerType<T>(T().type());}
66 std::ostringstream os;
67 os<<
"invalid type "<<t;
70 const char* what()
const throw() {
return s.c_str();}
77 typename Fmap::const_iterator i=fmap.find(t);
81 return i->second->create();
85 std::vector<string>
types()
const
87 std::vector<string> r;
88 for (
typename Fmap::const_iterator i=fmap.begin(); i!=fmap.end(); ++i)
89 r.push_back(i->first);
std::vector< string > types() const
return list of registered types
Definition: factory.h:85
B * create(const Type &t) const
Create a default constructed object given by the type string.
Definition: factory.h:75
void registerType(const Type &t)
register type T for use with this factory
Definition: factory.h:38
void registerType()
convenience method for registering a type.
Definition: factory.h:44
base class for exceptions thrown by classdesc
Definition: classdesc.h:391