CArchive::GetObjectSchema
UINTGetObjectSchema();
Return Value
During deserialization, the version of the object being read.
Remarks
Call this function from the Serialize function to determine the version of the object that is currently being deserialized. 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
}
}
CArchive Overview | Class Members | Hierarchy Chart
See Also CObject::Serialize, CObject::IsSerializable, IMPLEMENT_SERIAL, DECLARE_SERIAL, CArchive::IsLoading