Rewind in a serialize process?
-
When we are extracting data with serialize( ar >> some_variable >> another_one >> etc. ) is it possible to 'rewind' and begin again, for instance, if we don´t find a desired value?
-
When we are extracting data with serialize( ar >> some_variable >> another_one >> etc. ) is it possible to 'rewind' and begin again, for instance, if we don´t find a desired value?
Yes. But you should destruct the file's CArchive before rewinding the CFile, and create a new CArchive after rewinding. This will ensure the archive's data integrity. "There is always one more bug..." ravib@ravib.com http://www.ravib.com
-
Yes. But you should destruct the file's CArchive before rewinding the CFile, and create a new CArchive after rewinding. This will ensure the archive's data integrity. "There is always one more bug..." ravib@ravib.com http://www.ravib.com
Thanks. So, how could I do it in this small sample code: void CMeteoGraficaDoc::Serialize(CArchive& ar) { CDocument::Serialize(ar); if (ar.IsStoring()) { ar<>datosF.dia>>datosF.mes; // if (datosF.dia != some_value) ...... rewind and begin to serialize. } }
-
Thanks. So, how could I do it in this small sample code: void CMeteoGraficaDoc::Serialize(CArchive& ar) { CDocument::Serialize(ar); if (ar.IsStoring()) { ar<>datosF.dia>>datosF.mes; // if (datosF.dia != some_value) ...... rewind and begin to serialize. } }
Hmmm, I must have been brain dead when I posted my earlier reply. You can rewind the file during serialization.
void CMeteoGraficaDoc::Serialize(CArchive& ar)
{
CDocument::Serialize(ar);
if (ar.IsStoring()) {
ar<> datosF.dia>>datosF.mes;
if (datosF.dia != some_value) {
CFile* pFile = ar.GetFile();
ASSERT (pFile != NULL);
pFile->SeekToBegin(); // rewind
ar >> datosF.dia>>datosF.mes; // retry
}
}
}/ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com
-
Hmmm, I must have been brain dead when I posted my earlier reply. You can rewind the file during serialization.
void CMeteoGraficaDoc::Serialize(CArchive& ar)
{
CDocument::Serialize(ar);
if (ar.IsStoring()) {
ar<> datosF.dia>>datosF.mes;
if (datosF.dia != some_value) {
CFile* pFile = ar.GetFile();
ASSERT (pFile != NULL);
pFile->SeekToBegin(); // rewind
ar >> datosF.dia>>datosF.mes; // retry
}
}
}/ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com
Ok, thank you so much ;) I´ll try it.
-
Ok, thank you so much ;) I´ll try it.
I get it working, but I´ve had to add: CFile* pFile = ar.GetFile(); ASSERT (pFile != NULL); pFile->SeekToBegin(); // rewind ar >> datosF.dia>>datosF.mes; // retry CArchive ar(pFile, CArchive::load); //this one added Thank you, so much.