Markus Werle wrote:
Robert Ramey
writes:
The easiest would be just to define non-untrusive serialize templates for these classes.
Unfortunately this approach still requires an extra nvp for xml files, so for the code below we obtain e.g.
<SomeTag><value>SomeText</value><SomeTag>
The extra tag is what I would like to avoid.
Note that usage of std::string rather than CString will have the same "extra" tag.
If you want limited functionality (e.g. no tracking, versioning) then assign a lower implementation level - but one higher than primitive.
I was not aware of the side effect of limited functionality. This is probably not what I want ... unsure. Can you provide code which avoids the extra tag in xml files and does the same job as for std::string?
As I said - I don't see that std::string elminates the "value" tag. Other primitives e.g. int have their own tags. So the issue of making a type primitive seems to me to be totally unrelated to whether a type is tagged in an xml file. All data elements in an xml archive are tagged and this in enforced by the interface implementation. But the larger answer to your question is that it seems to me that what you want is a variation on the xml_[i/o]archive. Your variation would handle certain types specially - thereby skipping the tagging for certain types. This can be implemented by making your own derivation from xml_[i/o]archive. Examples of making derivation of an existing archive can be found in the documentation and demos.
I wished the UI of boost::serialization could provide some mechanism that allows the plug in of types for which a string representation can be generated and evaluated, or in other words: if the following functions are available:
std::istream & operator>>(std::istream &is, MyType & T); std::ostream & operator<<(std::ostream &os, MyType const & T);
what's the matter with adding to MyType a common string cast operator and using: template<class Archive> void save(Archive &ar, const MyType &t, const unsigned version){ std::string s = t; ar << t; } and std::ostream & operator<<(std::ostream &os, MyType const & T){ std::string s = t; *this << t; } If you don't like the temporaty string you can make a converter which generates an iterator over the string representation of MyType and uses this same iterator for both stream output and serialization. Robert Ramey