CArchive::GetObjectSchema
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

CArchive::GetObjectSchema

Call this function from the Serialize function to determine the version of the object that is currently being deserialized.

UINT GetObjectSchema( );

Return Value

During deserialization, the version of the object being read.

Remarks

Calling this function is only valid when the CArchive object is being loaded (CArchive::IsLoading returns nonzero). It should be the first call in the Serialize function and called only once. A return value of (UINT)–1 indicates that the version number is unknown).

A CObject-derived class may use VERSIONABLE_SCHEMA combined (using bitwise OR) with the schema version itself (in the IMPLEMENT_SERIAL macro) to create a "versionable object," that is, an object whose Serialize member function can read multiple versions. The default framework functionality (without VERSIONABLE_SCHEMA) is to throw an exception when the version is mismatched.

Example

IMPLEMENT_SERIAL(CMyObject, CObject, VERSIONABLE_SCHEMA|1)

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

      switch(nVersion)
      {
      case 0:
         // read in previous version of 
         // this object
         break;
      case 1:
         // read in current version of
         // this object
         break;
      default:
         // report unknown version of 
         // this object
         break;
      }
   }
   else
   {
      // Normal storing code goes here
   }
}

See Also

CArchive Overview | Class Members | Hierarchy Chart | CObject::Serialize | CObject::IsSerializable | IMPLEMENT_SERIAL | DECLARE_SERIAL | CArchive::IsLoading

Show:
© 2016 Microsoft