CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Serialize

  1. #1
    Join Date
    Apr 1999
    Posts
    32

    Serialize

    Hello there!
    Would it be possible to get the following items clarified?

    Class Schema Number
    It seems not possible to get the class Schema Number behave as specified in the C++ documentation (versions 4 and 6).
    The class Schema Number seems to be:
    common to all different classes being serialised, despite that a specific Schema Number can be defined for each class through the IMPLEMENT_SERIAL macro
    neither stored to nor read from permanent storage (just initialised to -1 during the construction of the CArchive object)

    Are the above considerations correct or is there some parameter to be set in the compiler, project, etc.?

    Object::Serialise
    Currently Object::Serialise does nothing.
    Is it worth keeping it into the code as recommended by the documentation?
    Is there some planned use? If yes, what about compatibility with old objects?

    Thanks for your prompt reply, Nicola


  2. #2
    Join Date
    Apr 1999
    Posts
    20

    Re: Serialize

    First, make sure the object you are trying to serialize is derived from CObject.

    Second,use the GetObjectSchema() and SetObjectSchema() methods of CArchive.

    SO, something like this:

    void CMyObject::Serialize(CArcive& ar)
    {
    if(ar.IsLoading())
    {
    int nSchemaVersion = ar.GetObjectSchema();

    int nData = 0;

    switch(nSchemaVersion)
    {
    case 0:
    ar >> nData;
    break;
    case 1:
    // etc...
    }
    }
    else
    {
    ar << nData;
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured