|
Boost Users : |
Subject: Re: [Boost-users] XML serialization of non-std::string types
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-01-07 20:41:04
try
template<class Archive>
inline void save(Archive &ar, const Qstring & t, const unsigned int
version){
// your own code here
ar << length of qstring
ar << qstring characters
}
template<class Archive>
inline void load(Archive &ar, Qstring & t, const unsigned int version){
// your own code here
unsigned int l;
ar >> l;
ar << qstring characters
t = QString(l, characters);
}
BOOST_CLASS_TRACKING(QString, track_never)
Thomas Sondergaard wrote:
> 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