By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

virtual binding surviving stream transport of objects

P: n/a
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

Apr 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
noone wrote:
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?

Use a map, key = type, value = simple factory object to create the
appropriate subclass.

--
Ian Collins.
Apr 11 '06 #2

P: n/a
On Tue, 11 Apr 2006 13:19:01 +1200, Ian Collins wrote:

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?

Use a map, key = type, value = simple factory object to create the
appropriate subclass.


thanks for the input but doesn't this action simply implement option
number (1) listed above? I'm trying to figure out a way to not have to
"register" each class type.

If there is no way around registering each type then so be it. How would
you implement such a map to cast the returned object to the correct type?

"message* get()" reads a stream of characters then must construct and
return an object of the (correct) subclass.
Apr 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.