Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Rewind in a serialize process?

Rewind in a serialize process?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jose Luis Sogorb
    wrote on last edited by
    #1

    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?

    RaviBeeR 1 Reply Last reply
    0
    • J Jose Luis Sogorb

      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?

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • RaviBeeR RaviBee

        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

        J Offline
        J Offline
        Jose Luis Sogorb
        wrote on last edited by
        #3

        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. } }

        RaviBeeR 1 Reply Last reply
        0
        • J Jose Luis Sogorb

          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. } }

          RaviBeeR Offline
          RaviBeeR Offline
          RaviBee
          wrote on last edited by
          #4

          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

          J 1 Reply Last reply
          0
          • RaviBeeR RaviBee

            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

            J Offline
            J Offline
            Jose Luis Sogorb
            wrote on last edited by
            #5

            Ok, thank you so much ;) I´ll try it.

            J 1 Reply Last reply
            0
            • J Jose Luis Sogorb

              Ok, thank you so much ;) I´ll try it.

              J Offline
              J Offline
              Jose Luis Sogorb
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups