Boost logo

Boost Users :

From: Asif Lodhi (asif.lodhi_at_[hidden])
Date: 2008-03-29 09:49:54


Hi Robert,

On 3/29/08, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> AMDG
>
> Robert Dailey wrote:
> > The problem is that the type of the packet is not known until runtime.
> > This makes it very difficult to make things "type safe" at compile
> > time. What Steven has presented is about as type-safe as you can make
> > it. However, the system does not prevent you from mismatching ID's
> > with actual packet types, but that's just a natural problem with data
> > driven designs.
> You could put the ID in the base Packet type. That should minimize the
> chances of mismatch.

YES.

> > Right now there is no possible way to have a factory that returns the
> > original type of the packet, since what is being passed in (the ID) is
> > not known at compile time, as I've already stated.
> It seems like a problem in multiple dispatching, which C++ just doesn't
> support very well natively.

Don't you think you could have a protected data member (packet_type,
for example) for storing the type ID of the packet in the base class
AND a public virtual function in the base class (subsquently
overridden in all the derived packet classes) to return the ACTUAL
type "ID of the packet (if that's what you want)? This will give you
the type ID of the actual type of packet simply and easily. As I have
said before, you CAN do it using a simple class/object model and
simple application of patterns.

--
Best regards,
Asif

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