You can write a parser and have the class process the input file, but I doubt that's what you want.
You can also use the crtp pattern to your advantage:
template<class T>
struct Base
{
Base()
{
reg;
}
virtual std::string name() = 0;
static bool reg;
static bool init()
{
T t;
Factory::registerClass(t.name());
return true;
}
};
template<class T>
bool Base<T>::reg = Base<T>::init();
You'd then derive classes as
struct Derived1 : Base<Derived1>
{
...
}
This would automatically register your class with Factory
given its name (you have to implement name
in non-abstract classes because it's pure).
Additionally, you can pass a callback to registerClass
that knows how to create your derived class.