|
Boost Users : |
From: Allen Gooch (agooch_at_[hidden])
Date: 2004-09-01 13:33:16
Given the following
#include <boost/preprocessor/repetition/enum_params.hpp>
#ifndef TYPELIST_MAX_SIZE
# define TYPELIST_MAX_SIZE 7
#endif
template <BOOST_PP_ENUM_PARAMS(TYPELIST_MAX_SIZE, class T)>
class ObjectImpl : BOOST_PP_ENUM_PARAMS(TYPELIST_MAX_SIZE, public T), public
ObjectBase<REFCNTR>
{
public:
virtual Refcount acquire() const
{
return Base::acquire();
}
virtual Refcount release() const
{
return Base::release();
}
virtual Refcount getRefcount() const
{
return Base::getRefcount();
}
virtual bool hasInterface(InterfaceID const & iid) const
{
return Base::hasInterface(iid);
}
virtual IObject * getInterface(InterfaceID const & iid)
{
IObject const * const_this = (IObject const *) this;
return (IObject *) const_this->getInterface(iid);
}
virtual IObject const * getInterface(InterfaceID const & iid)
{
IObject const * obj = 0;
switch (iid)
{
case IObject::IID :
{
this->acquire();
obj = static_cast<IObject const *>(this);
break;
}
// Desired: for each type T in typelist generate the following
case block
// case T::IID :
// {
// this->acquire();
// obj = static_cast<T const *>(this);
// break;
// }
default :
{
throw InterfaceUnsupportedException(iid)
break
}
}
return obj;
}
protected:
ObjectImpl()
{
}
virtual ~ObjectImpl()
{
}
typedef ObjectBase<REFCNTR> Base;
};
What is the best way to generate a case block for each type in the typelist?
I've been looking at the Preprocessor appendix from the "C++ Template
Metaprogramming" book (can't wait!) and see three different approaches to
vertical repetition: local, file and self; however, I'm not clean on how to
express what I want using these approaches. Can someone shed some light, or
point me to an example in the Boost PP docs which solves a similar problem?
Many thanks in advance.
-allen
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net