Feature request for serialization

It would be nice to be able to specify a callback that can notify how far a serialization (at loading) has come. I have a structure that can take a LONG time to load, and it would be good to be able to present a progress bar for the user. /R

This would be something that would be better to do yourself. Here is a suggestion: Suppose you've got class A { B b; C c; D d; }; and class B { std::vector<E> ve; }; Suppose you want a call back every time something is serialized template<class Archive> void serialize(Archive & ar, E & e, const unsigned int version){ ar & e; my_callback_e(); // } template<class Archive> void serialize(Archive & ar, B & b, const unsigned int version){ ar & b; my_callback_b(); // } etc. If you wanted something more generc, you could make an archive adaptor which could add the same functionalty to any archive. Robert Ramey Robert Bielik wrote:

On Thursday, October 18, 2007 at 09:01:06 (-0700) Robert Ramey writes:
I think something simpler would be to have a single callback, say progress(), and pass it the number of bytes read so far from the stream in question. This would allow a percentage complete calculation to be done based on the number of bytes in the incoming file (assuming it is not compressed). Thus, something like this: template<class Archive> void serialize(Archive & ar, E & e, const unsigned int version){ ar & e; progress(ar.stream().tellg()); } template<class Archive> void serialize(Archive & ar, B & b, const unsigned int version){ ar & b; progress(ar.stream().tellg()); } or whatever. If compressed, then you'll have to fudge things, dividing the bytes by some heuristic factor... Bill

If you want to do it for a particular type of archive or applicaiton without messing up your serialization for all the others you could use void serialize(my_archive & ar, E & e, const unsigned int version){ ar & e; progress(e); } Then it would only be applied with you included that particular header. Might be useful for debugging or whatever. So your problem now is - you've got too many ideas to choose from. Robert Ramey Peter Dimov wrote:

Robert Ramey skrev:
Yes, I see. I did however like the idea of having it at streambuf or stream level as I know how many bytes are in the stream. This I had in mind earlier also.
Perhaps in betterness, but the lower you get, lesser the info. On the archive level, it would be possible to also include names of classes/members being serialized. But progress info will be sufficient. What I do is something like this: A a; boost::archive::xml_iarchive ia(stream); ia >> boost::serialization::make_nvp("xmldoc", A); where stream is std::istream& . I'm not sure where to hook into the stream (I'm no STL lowlevel expert). Should I make my own streambuf implementation? TIA /Rob
participants (4)
-
Bill Lear
-
Peter Dimov
-
Robert Bielik
-
Robert Ramey