|
Boost Users : |
Subject: [Boost-users] XML serialization of non-std::string types
From: Thomas Sondergaard (ts_news1_at_[hidden])
Date: 2009-01-07 15:09:56
I'm using boost::serialization with QString, and I'm having the same
problem as this poster: http://lists.boost.org/boost-users/2006/10/22940.php
boost::serialization doesn't deal ideally with non-std::strings, and
there are enough of them in use, that it is important (QString, CString,
wxString, etc).
Would it be possible to add a mechanism that would make it easy to
extend boost::serialization to handle new string types as conveniently
as std::string/std::wstring?
I'm currently using the following helper-function to do the job, but
ideally I'd want the same syntax for serializing QStrings as other strings.
template<class Archive>
inline void serializeQString(Archive &ar, const char *name, QString &s) {
if (Archive::is_saving::value) {
std::string tmp(s.toUtf8().constData());
ar & boost::serialization::make_nvp(name, tmp);
} else if (Archive::is_loading::value) {
std::string tmp;
ar & boost::serialization::make_nvp(name, tmp);
s = QString::fromUtf8(tmp.c_str());
}
}
Regards,
Thomas Sondergaard
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net