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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CArchive, Serializing & Schema

CArchive, Serializing & Schema

Scheduled Pinned Locked Moved C / C++ / MFC
databasebusinessxmljsonquestion
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
    Jason Teagle
    wrote on last edited by
    #1

    I have a situation where I need to serialize several parts of a document-derived class. Because the standard doc loading / saving mechanism is not quite what I need, I have to construct the CArchive manually. All the serialization is working fine in itself, but the one thing I can't seem to get to work now I need it is the schema business. My doc-derived class uses IMPLEMENT_SERIAL() with the current schema number correctly. I create the archive correctly and then start serializing out (when saving, this is)... but for some reason it never saves the schema in the binary file. I tried SetObjectSchema() immediately after constructing the CArchive, which certainly sets the internal schema value... but that never gets written to file. I looked at the code for CDocument where it calls our overriden Serialize() to see how it did it - from that I see it sets the archive's m_pDocument and another member. So I did this also... STILL doesn't save the schema in the file. Since CDocument::Serialize() does not do anything, calling the base class has no effect. Any clues as to what I'm missing? Otherwise I'll have to do the schema bit myself. But I'd rather use the built-in stuff as much as possible.

    T 1 Reply Last reply
    0
    • J Jason Teagle

      I have a situation where I need to serialize several parts of a document-derived class. Because the standard doc loading / saving mechanism is not quite what I need, I have to construct the CArchive manually. All the serialization is working fine in itself, but the one thing I can't seem to get to work now I need it is the schema business. My doc-derived class uses IMPLEMENT_SERIAL() with the current schema number correctly. I create the archive correctly and then start serializing out (when saving, this is)... but for some reason it never saves the schema in the binary file. I tried SetObjectSchema() immediately after constructing the CArchive, which certainly sets the internal schema value... but that never gets written to file. I looked at the code for CDocument where it calls our overriden Serialize() to see how it did it - from that I see it sets the archive's m_pDocument and another member. So I did this also... STILL doesn't save the schema in the file. Since CDocument::Serialize() does not do anything, calling the base class has no effect. Any clues as to what I'm missing? Otherwise I'll have to do the schema bit myself. But I'd rather use the built-in stuff as much as possible.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      How are you serializing document members? Using m_foo.Serialize(ar) or ar << m_pFoo? Tomasz Sowinski -- http://www.shooltz.com

      J 2 Replies Last reply
      0
      • T Tomasz Sowinski

        How are you serializing document members? Using m_foo.Serialize(ar) or ar << m_pFoo? Tomasz Sowinski -- http://www.shooltz.com

        J Offline
        J Offline
        Jason Teagle
        wrote on last edited by
        #3

        Everything is done using ar << m_pFoo (no objects other than CString are serilaized - most of what is saved is structures, and I do the members of each by hand). You sound as if you're hinting that each object (class) has its own schema... which I can understand... but should there not be an overall schema for the document / doc-derived object? It does, after all, have IMPLEMENT_SERIAL()... Basically, I'm not interested in the individual schemas of each thing I serialize - all serializing is done from one class (the doc-derived) (since there are no child objects being serialized, not even CXXXArrays). I want one overall schema that is used in all serializing operations so that I can check it on loading to avoid loading new data from old-schema files...

        1 Reply Last reply
        0
        • T Tomasz Sowinski

          How are you serializing document members? Using m_foo.Serialize(ar) or ar << m_pFoo? Tomasz Sowinski -- http://www.shooltz.com

          J Offline
          J Offline
          Jason Teagle
          wrote on last edited by
          #4

          Everything is done using ar << m_pFoo (no objects other than CString are serilaized - most of what is saved is structures, and I do the members of each by hand). You sound as if you're hinting that each object (class) has its own schema... which I can understand... but should there not be an overall schema for the document / doc-derived object? It does, after all, have IMPLEMENT_SERIAL()... Basically, I'm not interested in the individual schemas of each thing I serialize - all serializing is done from one class (the doc-derived) (since there are no child objects being serialized, not even CXXXArrays). I want one overall schema that is used in all serializing operations so that I can check it on loading to avoid loading new data from old-schema files...

          T 1 Reply Last reply
          0
          • J Jason Teagle

            Everything is done using ar << m_pFoo (no objects other than CString are serilaized - most of what is saved is structures, and I do the members of each by hand). You sound as if you're hinting that each object (class) has its own schema... which I can understand... but should there not be an overall schema for the document / doc-derived object? It does, after all, have IMPLEMENT_SERIAL()... Basically, I'm not interested in the individual schemas of each thing I serialize - all serializing is done from one class (the doc-derived) (since there are no child objects being serialized, not even CXXXArrays). I want one overall schema that is used in all serializing operations so that I can check it on loading to avoid loading new data from old-schema files...

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #5

            Schema number is written to file only if you use CArchive::WriteObject (operator << for CObject pointers calls this method). WriteObject uses CArchive::WriteClass for sort of 'metadata' (class name, schema version). Default serialization implemented in CDocument::OnSaveDocument uses plain Serialize. This means that you can't call GetObjectSchema to get document schema number in CYourDoc::Serialize - it's not in the file. You've mentioned that you're creating CArchive yourself - if you're replacing OnSaveDocument you can also try to replace CYourDoc::Serialize() with ar << pDoc. Tomasz Sowinski -- http://www.shooltz.com

            J 1 Reply Last reply
            0
            • T Tomasz Sowinski

              Schema number is written to file only if you use CArchive::WriteObject (operator << for CObject pointers calls this method). WriteObject uses CArchive::WriteClass for sort of 'metadata' (class name, schema version). Default serialization implemented in CDocument::OnSaveDocument uses plain Serialize. This means that you can't call GetObjectSchema to get document schema number in CYourDoc::Serialize - it's not in the file. You've mentioned that you're creating CArchive yourself - if you're replacing OnSaveDocument you can also try to replace CYourDoc::Serialize() with ar << pDoc. Tomasz Sowinski -- http://www.shooltz.com

              J Offline
              J Offline
              Jason Teagle
              wrote on last edited by
              #6

              An excellent suggestion - I will try that trick tomorrow and let you know. Thanks for the help.

              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