Serialization: storing different representations in different archive types

I have a program that saves program state in both binary and XML archives. I'd like to store one of the model objects in my program in different formats, depending on whether the output archive is XML or binary: for XML archives, I'd like to use a human readable-format, and for binary archives I'd like to use a much more compact representation. I don't see any methods on Archive that let me ask if the output is a textual format (text or XML). I could dynamic_cast in my load/save methods, but that doesn't extend to new kinds of archives that may be implemented in future. Is there a way to do what I want to do? Thanks Simon

use separate specialzations for different archive types: // default method template<class Archive> void serialize(Archive & ar, mydatatype t, const unsigned version){ ... } // special method for xml_oarchive void serialize( xml_oarchive & ar, mydatatype t, const unsigned version){ ... } Robert Ramey Simon Fraser wrote:
I have a program that saves program state in both binary and XML archives. I'd like to store one of the model objects in my program in different formats, depending on whether the output archive is XML or binary: for XML archives, I'd like to use a human readable-format, and for binary archives I'd like to use a much more compact representation. I don't see any methods on Archive that let me ask if the output is a textual format (text or XML). I could dynamic_cast in my load/save methods, but that doesn't extend to new kinds of archives that may be implemented in future.
Is there a way to do what I want to do?
Thanks Simon
participants (2)
-
Robert Ramey
-
Simon Fraser