I have what I believe is a common problem. I must pull protocol messages
in from a data stream and save them as subclassed objects. the messages
vary in length and only share a fixed length header of common format.
consider:
struct message {}
struct m_reset: public message {}
struct m_shutdown: public message {}
struct receiver {
message* get(); // read message from stream
}
The problem is that message* needs to point to an object of the correct
subclass when it is received, based on the content of the message. there
will be literally hundreds of subclassed message types. is there a sneaky
way to do this other than
1) coding a lookup table in my get() method that knows all message types?
2) using a complicated object brokerage framework?
suggestions, or references to resources that address this issue?
thanks