[boost-users][serialization]Can I serialize wstring into text_oarchive?

Hi, all I do some tests and found it's ok to save/load wstring into/from text_oarchive, Am I very lucky? or it's safe to do this? When do I need to use text_woarchive? Thanks, Wang Yun

Wang Yun wrote:
Hi, all
I do some tests and found it's ok to save/load wstring into/from text_oarchive, Am I very lucky? or it's safe to do this?
All archives in the serialization library include code to serialize all "primitive" types. For purposes of this discussion, std::wstring is considered a primitive type. In general, we have strived to maintain archive classes independent to any particular data type. That is - any data type should work with any archive.
When do I need to use text_woarchive?
When you want to store using wide characters (ie unicode) rather than multi-byte characters of a specific locale.
Thanks,
Your welcome Robert Ramey

Robert Ramey wrote:
Wang Yun wrote:
Hi, all
I do some tests and found it's ok to save/load wstring into/from text_oarchive, Am I very lucky? or it's safe to do this?
All archives in the serialization library include code to serialize all "primitive" types. For purposes of this discussion, std::wstring is considered a primitive type. In general, we have strived to maintain archive classes independent to any particular data type. That is - any data type should work with any archive.
When do I need to use text_woarchive?
When you want to store using wide characters (ie unicode) rather than multi-byte characters of a specific locale.
Thanks,
Your welcome
Robert Ramey
I understand now, thanks. And I have another question, in the version 1.34's document(from cvs), in the Pending issues, you say "Floating point values which are number cannot be serialized to text base archives.". Is this means that if I want to save same float or double value, I can only use binary_archive? If I still want to use text or xml archive, I think maybe I can use a wrapper class like: class BinaryFloat { void serialize() { // save/load _value's binary in text string, like "0xABCDEFGH" // and also save some platform info so I can use this portablely. } private: float _value; }; Do you think this is ok? Thanks, Wang Yun

And I have another question, in the version 1.34's document(from cvs), in the Pending issues, you say "Floating point values which are number cannot be serialized to text base archives.".
It should say "Floating point values which are NOT a number (Nan) cannot be serialized to text based archives.".
Is this means that if I want to save same float or double value, I can only use binary_archive?
No it just means that you can't store the float that results from an undefined operation such as x/y where y == 0.0 . I would recommend that you using something like serialize(Archive &ar, version ..) assert(! is_nan(f)); ar << f; } or something like that. Robert Ramey

Robert Ramey wrote:
And I have another question, in the version 1.34's document(from cvs), in the Pending issues, you say "Floating point values which are number cannot be serialized to text base archives.".
It should say "Floating point values which are NOT a number (Nan) cannot be serialized to text based archives.".
Is this means that if I want to save same float or double value, I can only use binary_archive?
No it just means that you can't store the float that results from an undefined operation such as x/y where y == 0.0 . I would recommend that you using something like
serialize(Archive &ar, version ..) assert(! is_nan(f)); ar << f; }
or something like that.
Robert Ramey
I see, thanks. Wang Yun
participants (2)
-
Robert Ramey
-
Wang Yun