|
Boost Users : |
Subject: [Boost-users] Problem with binary serialization using std::wstring
From: Macumber, Daniel (Daniel.Macumber_at_[hidden])
Date: 2009-10-17 16:34:16
My project is using std::wstring extensively and I have been able to get both the text and xml serialization archives to work with it. However, I am getting a stream_error when trying to deserialize objects written to a binary archive. I think the serialization may be missing some objects. I have tracked the problem down to serializing a std::map<std::wstring, shared_ptr<IddKey>, iStringCompare> where IddKey is a class that supports serialization and iStringCompare is:
struct iStringCompare{
bool operator()(const std::wstring& x, const std::wstring& y) const{
return boost::lexicographical_compare(x, y, boost::is_iless());
};
};
I have tried to replicate this problem in a simple test case to submit but have not been able to reproduce it outside of my real code. Here is the code that serializes to a binary archive:
boost::filesystem::wpath path = iddPath;
path.replace_extension(L"idd.bin");
{
boost::filesystem::ofstream ofs(path);
boost::archive::binary_oarchive out(ofs);
out << iddFilePtr;
}
IddFilePtr newIddFilePtr;
{
boost::filesystem::ifstream ifs(path);
boost::archive::binary_iarchive in(ifs);
in >> newIddFilePtr;
}
I am not using binary_woarchive or binary_wiarchive because they don't compile with shared_ptr serialization and I have seen that you are not really supposed to use them. I am using the wstring versions of the text and xml archives that are working. Does anyone have any suggestions on how to track down my problem?
Dan
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