Re: Request final critique
On Jun 16, 4:02 pm, "RB" <NoMail@NoSpam> wrote:
Albeit I do understand what you are saying about tieing to the
serialization, this brings to bear a whole cloud that I have been confuse=
d
on (but aware of ) for some time, and I know you explained this to me
before. But I have not completely parameritized all of the logistical
operations in the macros when I would expand them. Please see
below. My input and/or questions are in the // comments
/////////////////////////////////////////////////////
// CFileHandlingDoc
IMPLEMENT_DYNCREATE(CFileHandlingDoc, CDocument)
// Results in below macro, which appears to me to create the
// MyDocDerivative object passing FFFF as the schema (which is not
// a valid schema value but the default of -1 )
#define IMPLEMENT_DYNCREATE(class_name, base_class_name) \
CObject* PASCAL class_name::CreateObject( ) \
{ return new class_nam=
e; } \
IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \
class_name::CreateObject)
//---------------------------------------------------------------
// So I though all I had to do was set the schema from inside my doc
// as in:
CRuntimeClass* pMyDocRT = GetRuntimeClass( );
pMyDocRT->m_wSchema = 1; // set my schema
//---------------------------------------------------------------
Obviously, if you want to use SerializeClass, you'd change
XXX_DYNCREATE to XXX_SERIAL and set schema there.
// But if I run the IMPLEMENT_SERIAL macro on on MyDocDerivative
// after it is already in existence, isn't this going to create another o=
ccurance
// of it's CRuntimeClass ?
I am not quite sure what you mean by that, but none of DECLARE/
IMPLEMENT_XXX must not be "run" multiple times. You do that once, in
your class's *.cpp. (Does MFC assert in _DEBUG if you do it twice?
Perhaps).
I personally like to put _DYNAMIC at the top of the file, _DYNCREATE
next to the empty constructor (because, _DYNCREATE needs that), and
_SERIALIZE next to Serialize function (because I want my schema
numbers close to Serialize). All these should be close to each other
anyhow, but...
// I feel that I am still missing something in the structure here.
DECLARE/IMPLEMENT_XXX distilled:
_DYNAMIC gives you CRuntimeClass* for your class (GetRuntimeClass
method), and, as a consequence, STATIC/DYNAMIC_DOWNCAST and IsKindOf.
_DYNCREATE gives you _DYNAMIC + the ability to create an "empty"
object by knowing it's class. This is used by MFC, e.g. to create
"your" doc/view/frame classes, or in serialization (in ar >> pObject).
_SERIAL gives you _DYNCREATE + serialization schema number and >> <<
operators with CArchive.
All of them must have correct base class (don't forget that if you
"insert" class in your class hierarchy; I made that mistake, and it's
not pretty :-) ). If base class is a template (happens, but rarely),
then you must use first non-template base of that template class.
Well if it is terribly expensive, how about a shot of Tequila with lime.
No problem with that either ;-). I am a drunken bastard, what can I
say!
Good luck,
Goran.