Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-06-05 12:55:10


Jeff Garland wrote:

> > Robert Ramey wrote:
> >
> > >Russell Balest wrote
> > >
> > >>Does someone know where in the code I can implement this easily.
> > >>I just want to ignore the comments.
> > >>
> > >easy to accommodate. Just create a use the following in your
> > >serialize
> > >functions:
> > >
> > >Template<class Archive>
> > >Void serialize(Archive, my_class & t){
> > > std::string comment;
> > > ar & BOOST_NVP("comment", comment);
> > > ar & BOOST_NVP("myclass_data", t);;
> > >}
> > >
> > >In which case your XML output will look like:
> > >
> > >...
> > ><comment></comment>
> > ><myclass_data>..contents of t</myclass_data> ...
> > >
> > >
> > >
> > Good idea. I'll probably do that.

> Another approach would be to preprocess your input files and strip the
> added comments using XSLT, perl, or a simple regex program. That way you
> don't have to modify the data structures under test.

Someone might complain that my original method has 2 inconvenience features

a) it requires modification to the serializations
b) it includes the (null) comment string place holder in all the archives
including the binary one.

So another alternative would be to derive from the included xml_?archive
classes included in the package and redefine the override for named-value
pair so that it inserts/extracts <!-- and --> before or after every tag.

This method has the following features:

a) doesn't require any kluging up of class serializations
b) has the advantage of automatically includes the <!-- --> for all object
instances
c) has the disadvantage of automatically includes the <!-- --> for all
object instances
d) doesn't add any overhead in other archives.

If c) above is intolerable you would have the option of making your own
wrapper similar to NVP - (NVT) that you would use in your serializations
rather than NVP whenever you wanted a comment place holder. That's really a
variation on my first suggestion.

Take your pick and good luck

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk