Boost logo

Boost Users :

From: Robert Dailey (rcdailey_at_[hidden])
Date: 2008-03-29 16:30:39


On Sat, Mar 29, 2008 at 3:21 PM, Steven Watanabe <watanabesj_at_[hidden]>
wrote:

> AMDG
>
> Robert Dailey wrote:
> > Is there any reason why the ID needs to be available at runtime?
> > Instead of your specialization, I do:
> >
> > class WalkPacket : Packet
> > {
> > static const PacketId ID = PID_WALKPACKET;
> > };
> >
> > Is there any reason why this isn't sufficient?
>
> The dispatcher needs to know what the ID of a packet is to
> do its job. The idea is that instead of passing the ID and the packet
> separately,
> the packet knows its own ID. It is possible, though to replace the ID
> type with
> std::string in the dispatcher and use std::string(typeid(packet).name())
> avoiding the ID's entirely inside the dispatcher.

It seems that so far we've gotten everything done without RTTI, I would hate
to introduce it here. I see what you're saying now. Something like this
might be in order:

struct Packet
{
    virtual PacketId GetId() const = 0;
};

struct WalkPacket : Packet
{
    static const PacketId ID = PID_WALKPACKET;
    virtual PacketId GetId() const { return ID; }
};



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