|
Boost Users : |
Subject: Re: [Boost-users] Problem with binary serialization using std::wstring
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-10-19 00:20:39
Before we get too serious,
a) double check that you're opening the stream with binary switch
b) check the TRAC data base. There is a ticket which refers to
wstring serialization in non-w archives. Check to see if this
is your situation.
Robert Ramey
Macumber, Daniel wrote:
> 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