15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Serialization of Template classes

Srinivasan V S -- vasan@sunserv.cmc.stph.net
Thursday, November 28, 1996

Environment: Win95, VC 4.1

How do you serialize template classes. The macros DECLARE_SERIAL
and IMPLEMENT_SERIAL just cannot take templated classes as arguments
since you need the template parameters.

Any help or ways to get around this problem would be highly welcome.

Thanks and regards
srinivasan v s

____________________________________________________________________________

		_/_/_/_/   _/_/	  _/_/_/   _/_/_/_/                         
               _/	  _/ _/  _/  _/   _/	                            
              _/	 _/  _/ -/  _/   _/                                 
             _/         _/   _/_/  _/   _/                     		    
            _/         _/         _/   _/                     		    
           _/_/_/_/   _/         _/   _/_/_/_/                              
____________________________________________________________________________
  Srinivasan V S                     					    
  CMC Ltd., CMC Centre 		  	Tel: +091-40-259401 (Off.)         
  Old Bombay Highway, Gachibowli	     +091-40-860544 (Res.)         
  Hyderabad - 500 019		  	Fax: +091-40-259509                
  INDIA			 	        E-mail: vasan@sunserv.cmc.stph.net  
____________________________________________________________________________




Mike Blaszczak -- mikeblas@nwlink.com
Saturday, November 30, 1996

At 17:19 11/28/96 +0500, Srinivasan V S wrote:
>Environment: Win95, VC 4.1

>How do you serialize template classes. The macros DECLARE_SERIAL
>and IMPLEMENT_SERIAL just cannot take templated classes as arguments
>since you need the template parameters.

>Any help or ways to get around this problem would be highly welcome.

The templated classes have serialization stuff built-in.  Just call
their Serialize() member function, passing the CArchive object that
you need to serialize into or from.

Or did you mean to ask about the dynamic creation of these objects?

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.




Srinivasan V S -- vasan@sunserv.cmc.stph.net
Monday, December 02, 1996

Environment: Win95, VC 4.1

How do you serialize template classes. The macros DECLARE_SERIAL
and IMPLEMENT_SERIAL just cannot take templated classes as arguments
since you need the template parameters.

Any help or ways to get around this problem would be highly welcome.

Thanks and regards
srinivasan v s




Mike Blaszczak -- mikeblas@nwlink.com
Tuesday, December 03, 1996

At 14:33 12/2/96 +0500, Srinivasan V S wrote:
>Environment: Win95, VC 4.1
>
>How do you serialize template classes. The macros DECLARE_SERIAL
>and IMPLEMENT_SERIAL just cannot take templated classes as arguments
>since you need the template parameters.
>
>Any help or ways to get around this problem would be highly welcome.

Here's the answer I sent to the list on 11/30/96 (my time):

The templated classes have serialization stuff built-in.  Just call
their Serialize() member function, passing the CArchive object that
you need to serialize into or from.

Or did you mean to ask about the dynamic creation of these objects?


.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.




Ken -- goersk@fs.com
Wednesday, December 04, 1996


>----------
>From: 	Srinivasan V S[SMTP:vasan@sunserv.cmc.stph.net]
>Sent: 	Monday, December 02, 1996 3:33 AM
>To: 	mfc-l@netcom.com
>Subject: 	Serialization of Template classes 
>
>Environment: Win95, VC 4.1
>
>How do you serialize template classes. The macros DECLARE_SERIAL
>and IMPLEMENT_SERIAL just cannot take templated classes as arguments
>since you need the template parameters.
>
>Any help or ways to get around this problem would be highly welcome.
>
>Thanks and regards
>srinivasan v s
>
>
I did this not too long ago and it isn't in the least bit enjoyable.
The general answer is that you can't.  At least not the same as you can
for
non-template classes.  Whoever implemented the brain dead RUNTIME_CLASS
implementation took care of that.  It uses stringize and tokenizing
macro substitution
which will not work correctly with the runtime class implementation.
You can however get most of what you need by expanding the DECLARE_* and
IMPLEMENT_* macros your self.  I don't know if this will work for you
but here's
some code for the way I did it.  What I was doing was templatizing a
base class
in order to add the same functionality to several classes without using
multiple inheritance.

Questions,  just ask...
	- Kenny.	(keng@logicontech.com)

Sample code:

template
class CFSTemplateControlDocument : public BASE_CLASS
{

public:
// Dynamic creation
   static CObject* PASCAL CreateObject();

// These are used as normal when 
   DECLARE_DISPATCH_MAP()
   DECLARE_MESSAGE_MAP()

public:
// @cmember
// Constructor
   CFSTemplateControlDocument();

//////////////////////////////////////////////////////////////////
//
// MESSAGE MAP IMPLEMENTATION
//
//////////////////////////////////////////////////////////////////
#ifdef _AFXDLL
template
const AFX_MSGMAP* PASCAL
CFSTemplateControlDocument::_GetBaseMessageMap()
{
	return &BASE_CLASS::messageMap;
}
#endif

template
AFX_DATADEF const AFX_MSGMAP CFSTemplateControlDocument::
messageMap =
{
#ifdef _AFXDLL
   &_GetBaseMessageMap,
   &_messageEntries[0]
#else
   &BASE_CLASS::messageMap,
   &_messageEntries[0]
#endif
};

template
const AFX_MSGMAP*
CFSTemplateControlDocument::GetMessageMap() const
{
   return &messageMap;
}

// Empty for now.....
template
const AFX_MSGMAP_ENTRY
CFSTemplateControlDocument::_messageEntries[] =
{
	{0, 0, 0, 0, AfxSig_end, (AFX_PMSG) 0}
};

//////////////////////////////////////////////////////////////////
//
// DISPATCH MAP Implementation
//
//////////////////////////////////////////////////////////////////

template
const AFX_DISPMAP*
CFSTemplateControlDocument::GetDispatchMap() const
{
   return &CFSTemplateControlDocument::dispatchMap;
}


#ifdef _AFXDLL

template
const AFX_DISPMAP* PASCAL
CFSTemplateControlDocument::_GetBaseDispatchMap() \
{
	return &BASE_CLASS::dispatchMap;
}

template
const AFX_DISPMAP CFSTemplateControlDocument::dispatchMap =
{
  &CFSTemplateControlDocument::_GetBaseDispatchMap,
  &CFSTemplateControlDocument::_dispatchEntries[0],
  &CFSTemplateControlDocument::_dispatchEntryCount,
  &CFSTemplateControlDocument::_dwStockPropMask
};

#else // _AFXDLL

template
const AFX_DISPMAP CFSTemplateControlDocument::dispatchMap =
{
   &BASE_CLASS::dispatchMap,
   &CFSTemplateControlDocument::_dispatchEntries[0],
   &CFSTemplateControlDocument::_dispatchEntryCount,
   &CFSTemplateControlDocument::_dwStockPropMask
};

#endif // _AFXDLL

template
UINT CFSTemplateControlDocument::_dispatchEntryCount =
(UINT)-1; \

template
DWORD CFSTemplateControlDocument::_dwStockPropMask =
(DWORD)-1; \

template
const AFX_DISPMAP_ENTRY
CFSTemplateControlDocument::_dispatchEntries[] =
{

	// Dispatch entries go here.....

   DISP_FUNCTION_ID(CFSTemplateControlDocument, )

   { VTS_NONE, DISPID_UNKNOWN, VTS_NONE, VT_VOID, (AFX_PMSG)NULL,
(AFX_PMSG)NULL, (size_t)-1, afxDispCustom }
};


////////////////////////////////////////////////////////////////////////
///////
//
////////////////////////////////////////////////////////////////////////
///////

class CFSControlDocument : public
CFSTemplateControlDocument
{
   DECLARE_DYNAMIC(CFSControlDocument)
};


class CFSRichEditCtlDoc : public
CFSTemplateControlDocument
{
   DECLARE_DYNAMIC(CFSRichEditCtlDoc)
};




// Implementation definitions
// Notice the jump from the base class to the derived class this is
neccassary to keep
// the message map chain together.

IMPLEMENT_DYNAMIC(CFSControlDocument, CFSDocument)
IMPLEMENT_DYNAMIC(CFSRichEditCtlDoc, CFSRichEditDoc);



>



Ash Williams -- ash@digitalworkshop.co.uk
Monday, December 09, 1996

Mike Blascszak wrote:
>>
Here's the answer I sent to the list on 11/30/96 (my time):

The templated classes have serialization stuff built-in.  Just call
their Serialize() member function, passing the CArchive object that
you need to serialize into or from.

Or did you mean to ask about the dynamic creation of these objects?
<<

Did Srinivasan mean his own templated classes??

Srinivasan, 

I've just had a look at afxtempl.h and none of the template classes had 
any of the DECLARE_* macros in them, which isn't suprising really 
because the IMPLEMENT_* macros expand into function bodies, none of 
which are preceded by a neccesary template declarator (a mere forward 
reference to give the compiler a clue - shouldn't really be our 
business to help the compiler like this should it, although I suppose 
it gives the compiler less workload, hence fewer bugs and higher speeds 
).

Anyway, I didn't see any template orientated macros either, but there 
was an override for Serialize.

So I think that's the only option available to you, to override 
Serialize, and you don't get any of the runtime support etc supported 
by the macros.

You could always roll your own template-orientated equivalent macros, 
but microsoft may change how these work in a future version which would 
give you more to worry about before you go to sleep!

Ash





| Вернуться в корень Архива |