473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

virtual binding surviving stream transport of objects

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
2 1517
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: A. Saksena | last post by:
Hi all, I am trying to compile following code :- ======================================= #include <iostream.h> #include <string> namespace tlm { template <typename REQUEST, typename RESPONSE >...
1
by: google | last post by:
I have created a simple HelloWorld application in WSE2.0 SP3. When I browse to the endpoint url over http (e.g. http://localhost/TestService.ashx) the WSDL is fine and I can create a client...
0
by: Steven Bolard | last post by:
Hello, I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am trying to get my webservices to run and although i can compile them and and get wsdl and service descriptions...
7
by: Markus Svilans | last post by:
Hello, My question involves virtual functions and inheritance. Suppose we have a class structure, that consists of "data" classes, and "processor" classes. The data classes are derived from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.