DocClass Implement Serial
Well I have done a bit more study and experimenting and I have 3 questions.
Appreciate input from everyone as usual and hopefully Goran will also reply
since he has helped me the most on serialization and from going back and
rereading the context of his replies (after I studying and experimenting enough
to even understand them) I can tell the he has a firm grasp on what is going on
in MFC's serialization process. ,
My first question is, I can not help but wonder why MFC does not
generate the Doc class (derived from CDocument) with the Serial macros
as opposed to the Dyncreate. Like at first I was thinking of creating a whole
other class derived from CObject with implement serial just to hold members
I wanted a schema to, but then Goran gave an example of the mfc schema
with creating the DocClass with SERIAL and after he showed this to me I began
to wonder why MFC did not generate it that way ? Maybe because of ......
( Goran did not recommend it since this ties serialization with your document
class name, so you could have trouble changing it using of serializeClass or
operator<</>> and might be a problem if a major overhaul of serialization occurs)
2 other questions below, denoted with ************
one simple mfc comment queston and
another question on 2nd set of code at bottom.
-------Implementing DocClass Serial instead of Dyncreate------
class CFileHandlingDoc : public CDocument
{
// RB question what exactly does this MFC generated comment mean ?
// | | | ************
protected: // create from serialization only
CFileHandlingDoc();
// DECLARE_DYNCREATE(CFileHandlingDoc)
// RB doc creation with serial instead
DECLARE_SERIAL(CFileHandlingDoc)
..........
..........
}
// CFileHandlingDoc implementations
// IMPLEMENT_DYNCREATE(CFileHandlingDoc, CDocument)
// RB creating doc with serial instead
IMPLEMENT_SERIAL(CFileHandlingDoc, CDocument, 0)
// And in my DocClass serialize function
void CFileHandlingDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar.SerializeClass(RUNTIME_CLASS(CFileHandlingDoc));
ar << VerData.Ver << VerData.CpyRt << VerData.Corp;
ar.SerializeClass(RUNTIME_CLASS(CMapStringToString));
ExpMap1.Serialize(ar);
}
else
{
ar.SerializeClass(RUNTIME_CLASS(CFileHandlingDoc));
ar >> VerData.Ver >> VerData.CpyRt >> VerData.Corp;
ar.SerializeClass(RUNTIME_CLASS(CMapStringToString));
ExpMap1.Serialize(ar);
}
}
// The above compiles and works on writes and reads doc class
// CRuntime Data with no problems
++++++++appreciate comments on below +++++++++++++
So then I am later reading in MFC Under the Hood by
Laura Draxler on page 255 on the use of the SERIAL
macros for user classes derived from CObject, she says:
"It may seem inconsistent to you at first that document
class does not need the SERIAL macros, and it uses the
DYNCREATE macros instead, but the framework provides this
support automatically for the document class."
----
And I am thinking yes it does seem that document class
would use SERIAL. But I obviously have misunderstood
the the context of her saying the framework provides
serial for the doc class, since when I expanded the
dyncreate macro and inserted my schema of 0 (instead of
the default FFFF for dyncreate) the SerializeClass call
failed on a read in. So she must be referring to another
aspect of this. (see code expansion below)
///////////////////////////////////////////////////
// CFileHandlingDoc
// Seeing if framework provides serial under implement dyncreate ?
// IMPLEMENT_DYNCREATE(CFileHandlingDoc, CDocument)
// Expanded
CObject* __stdcall CFileHandlingDoc::CreateObject()
{
return new CFileHandlingDoc;
}
const CRuntimeClass CFileHandlingDoc::classCFileHandlingDoc =
{ "CFileHandlingDoc", sizeof(class CFileHandlingDoc),
0x0000, // !RB replaced the 0xFFFF,! ****************
CFileHandlingDoc::CreateObject,
((CRuntimeClass*)(&CDocument::classCDocument)), 0
};
CRuntimeClass* CFileHandlingDoc::GetRuntimeClass() const
{
return ((CRuntimeClass*)(&CFileHandlingDoc::classCFileHandlingDoc));
}
// End Implement_Dyncreate expansion