R
Ronald Landheer-Cieslak
Hello all,
We're coding a really nice implementation of a generic abstract factory
at the moment, but we've come to a slight impass we have to work around:
when automagically registering a class to be built by the builder, we
are using a class and a macro that look like this:
template<
typename ClassT,
typename ParentT = typename ClassT:arentType,
typename BuilderT = clsBuilder<typename ParentT> >
struct Initializer
{
Initializer(typename BuilderT::tKeyType oKey)
{
BuilderT::RegisterClass(oKey, ClassT::Create);
}
Initializer(typename BuilderT::tKeyType oKey,
typename BuilderT::tCreatorFunctor functor)
{
BuilderT::RegisterClass(oKey, functor);
}
};
#define REGISTER_CLASS( C, K ) \
static Initializer<C> C##__Initializer(K)
This requires a typedef (ParentType) in the class, its ancestor or (in
an alternative approach we tried) in the builder.
We were looking for a way to find the most remote - or even a direct -
ancestor of a given class C statically, but we didn't find one. However,
we're pretty sure the compiler has the information somewhere, as the
class was declared as having one or more parents. Is there any
*standard* way to gleen this information from the compiler?
Thanks,
rlc
We're coding a really nice implementation of a generic abstract factory
at the moment, but we've come to a slight impass we have to work around:
when automagically registering a class to be built by the builder, we
are using a class and a macro that look like this:
template<
typename ClassT,
typename ParentT = typename ClassT:arentType,
typename BuilderT = clsBuilder<typename ParentT> >
struct Initializer
{
Initializer(typename BuilderT::tKeyType oKey)
{
BuilderT::RegisterClass(oKey, ClassT::Create);
}
Initializer(typename BuilderT::tKeyType oKey,
typename BuilderT::tCreatorFunctor functor)
{
BuilderT::RegisterClass(oKey, functor);
}
};
#define REGISTER_CLASS( C, K ) \
static Initializer<C> C##__Initializer(K)
This requires a typedef (ParentType) in the class, its ancestor or (in
an alternative approach we tried) in the builder.
We were looking for a way to find the most remote - or even a direct -
ancestor of a given class C statically, but we didn't find one. However,
we're pretty sure the compiler has the information somewhere, as the
class was declared as having one or more parents. Is there any
*standard* way to gleen this information from the compiler?
Thanks,
rlc