[xsd-users] virtual insertion/extraction

Boris Kolpackov boris at codesynthesis.com
Wed Feb 28 16:15:03 EST 2007


Hi Ray,

Ray Lischner <rlischner at proteus-technologies.com> writes:

> When I use --generate-polymorphic, xsd warns me that stream
> insertion/extraction operators are not yet polymorphism-aware.
> This is not surprising because these operators are templated,
> and virtual template member functions are not allowed. Nonetheless,
> is there some way to write virtual insertion functions? (Extraction
> is less important to us right now.)

You are right, the current architecture with templates does not
work well for the polymorphic case. The reason for this somewhat
elaborate template-based architecture is (1) to allow for user-
defined streams and (2) to make insertion and extraction efficient.

A more straightforward architecture would be to define a stream
interface which can be implemented for different formats. The
drawback of this approach is that it will require a virtual
function call for every insertion and extraction, even for
simple things like int or bool. I am not sure whether it would
be a significant overhead or not but I didn't like it then and
I am not sure I like it now ;-).

The only other option that I can think of right now is to generate
hard-wired insertion operators and extraction c-tors with the stream
type (or types) provided by the user via a command line option. This
approach is also not ideal since it is not clear how to provide such
hard-wired extraction c-tors for built-in types which are pre-defined
in the runtime library.

Also note that we are not using the virtual function mechanism
for things like parsing and serialization in order to keep things
modular. In case of XML, we generate type factory/serialization
maps that are used to find the right type (there is no other way
for parsing and serialization is using the same method for symmetry
and modularity). I was planning to use the same approach for binary
insertion and extraction. The reason why templates won't do here is
because we need to store pointers to actual functions in those maps.
Maybe the user could provide the stream types for which such functions
be instantiated and registered? I will need to think some more on this.


-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20070228/10bebbc3/attachment.pgp


More information about the xsd-users mailing list