Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-11-18 07:32:07


On Monday, November 18, 2002, at 01:04 PM, Jeff Garland wrote:

>> Let me give one example: we store parameters in a class
>>
>> typedef std::map<std::string,std::string> ParameterMap
> ...
>> If instead of typdef-ing ParameterMap as a std::map, I derive
>> ParameterMap from it then I can easily write a save and load function
>> to write and read that output. Thus XML can be included.
>>
>> There is however the problem that I cannot just write
>>
>> for (ParameterMap::const_iterator it=m.begin();it!=m.end();++it)
>> ar << *it;
>>
>> since the default serializing of a std::pair does not give my my
>> PARAMETER element above. Instead I have to write things explicitly:
>>
>> for (ParameterMap::const_iterator it=m.begin();it!=m.end();++it)
>> ar << "<PARAMETER name="\"" << it->first
>> << "\">" << it->second << "</PARAMETER>\n";
>>
>> and reading is more involved.
>
> Well, if this can't be done in a general fashion so that you
> don't have to be aware of the 'ParameterMap' in the archive
> code then the serialization design is broken. That's not to
> say that the XML backend might not need additional information
> that is not normally supplied by the framework. For example, a
> mapping between the type info and the XML element name.

The problem here is that the way you want to serialize a
std::pair<std::string,std::string> into XML might depend on the
context. Sure, we can design an XML schema that is not context
dependent, but most XML schemas are application specific and the way to
serialize the data IS context sensitive.

For me XML I/O of class data using an application specific schema is a
completely different application than just serializing a class object
for persistent storage or transmission to another process. I don't
think that any serialization library will be able to accomodate the
variety of XML schemas that a user could come up with and still be able
to factorize the output into context-insensitive serializations of all
classes. See just my example above: the way I serialize the std::pair
into XML is very application-specific and I might have other occurences
of std::pair that should be serialized differently.

Nevertheless, if you want XML, surely we can wrap the text archive
between XML tags to get an XML file, but what is the point of that?

Matthias


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