[xsd-users] New idea for stream insertion & extraction

Boris Kolpackov boris at codesynthesis.com
Mon Apr 2 08:31:01 EDT 2007


Hi Ray,

I've CC'ed xsd-users to my reply in case others are interested
in this.

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

> > I think the right approach here is to implement custom stream
> > support in the generated code. For your BME format it should be
> > trivial to do, especially now when I moved all the serialization
> > logic from optional and sequence containers to the generated
> > code. Furthermore, I think, you can reuse all the stream insertion
> > and extraction infrastructure for built-in types so that you
> > do not need to change anything in libxsd. Let me know if you
> > are interested in this approach and I will give you a more
> > detailed guidelines on what needs to be done.
>
> I'm very interested.

The actual code is generated in the following files (all in xsd/cxx/tree)

insertion
  stream-insertion-header.?xx
  stream-insertion-source.?xx

extraction
  tree-header.cxx
  stream-extraction-source.?xx

Note that for extraction, the declarations are generated in tree-header.cxx
since for extraction we use constructors and they have to be generated
in class definitions.

To generate your own insertion/extraction operators/c-tors you would
probably want to copy the above files (except tree-header.cxx where
you will just add your code inline).

The code generation is pretty simple. There are four "type" traversers:
List, Union, Enumeration and Complex. For Complex there are also
Element and Attribute traversers that each have cases for one, optional
and sequence cardinality classes. Things are a bit complicated by
the presence of the polymorphic case. What you may want to do is to
implement non-polymorphic case first and then add support for
polymorphism later. In the tree-header.cxx file you only need to touch
List, Union, Enumeration and Complex where you add declaration of
your extraction c-tors.

Once you've done all this, you will need to call the generators
as well as generate #include directives etc. To find all the places
where you may need to add your code simply search for generate_insertion
and generate_extraction in xsd/cxx/tree. You can either add a command
line option for your own streams or, if you need to always generate
them, simply call generators unconditionally.

Finally, you will need to provide ostream/istream specializations
for your stream types, similar to what is found in the ace-cdr-* files
in libxsd. I believe you already know how to do that.


hth,
-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/20070402/763f85f6/attachment.pgp


More information about the xsd-users mailing list