Home » U++ Library support » U++ Core » (Possible) Serialization issue
Re: (Possible) Serialization issue [message #17132 is a reply to message #17131] |
Wed, 30 July 2008 10:23 |
|
mirek
Messages: 13976 Registered: November 2005
|
Ultimate Member |
|
|
Mindtraveller wrote on Wed, 30 July 2008 01:14 | Short description: while loading binary data from file, stream.IsStoring() returns true and stream.IsLoading() returns false.
Compatible testcase:class TestClass
{
public:
void Serialize (Stream &stream);
private:
int b;
};
void TestClass::Serialize(Stream &stream)
{
if (stream.IsStoring())
{
int a = 0; //BREAKPOINT STOP HERE!
}
if (!stream.IsLoading())
{
int a = 1; //BREAKPOINT STOP HERE!
}
stream % b;
}
CONSOLE_APP_MAIN
{
TestClass testClass;
LoadFromFile(testClass, ".config");
}
Recommended behaviour: in a number of situations it is vital to know if one loads or saves data. Correct IsStoring/IsLoading behaviour here is welcome.
|
It is a little bit more complicated.
This is "load failure" protection. LoadFromFile first *stores* data in temporary String buffer, then attempts to load them from the file. If load fails, it restores the backup copy.
bool Load(Callback1<Stream&> serialize, Stream& stream) {
StringStream backup;
backup.SetStoring(); // <<<< this is it :)
serialize(backup);
ASSERT(!backup.IsError());
stream.SetLoading();
stream.LoadThrowing();
try {
CheckedSerialize(serialize, stream);
}
catch(LoadingError) {
backup.Seek(0);
backup.SetLoading();
serialize(backup);
ASSERT(!backup.IsError());
return false;
}
return true;
}
Note that if this is not what you want, do not use LoadFromFile
Mirek
[Updated on: Wed, 30 July 2008 10:25] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 11 17:13:25 CEST 2024
Total time taken to generate the page: 0.01970 seconds
|