Click here to Skip to main content
15,905,616 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC Serialization Questions.. Pin
montiee30-Dec-05 6:09
montiee30-Dec-05 6:09 
AnswerRe: MFC Serialization Questions.. Pin
Ravi Bhavnani30-Dec-05 6:59
professionalRavi Bhavnani30-Dec-05 6:59 
GeneralRe: MFC Serialization Questions.. Pin
Garth J Lancaster30-Dec-05 15:35
professionalGarth J Lancaster30-Dec-05 15:35 
GeneralRe: MFC Serialization Questions.. Pin
montiee30-Dec-05 16:54
montiee30-Dec-05 16:54 
GeneralRe: MFC Serialization Questions.. Pin
Ravi Bhavnani31-Dec-05 5:14
professionalRavi Bhavnani31-Dec-05 5:14 
AnswerRe: MFC Serialization Questions.. Pin
ToxickZero30-Dec-05 9:34
ToxickZero30-Dec-05 9:34 
GeneralRe: MFC Serialization Questions.. Pin
montiee30-Dec-05 17:04
montiee30-Dec-05 17:04 
AnswerRe: MFC Serialization Questions.. Pin
Cliff Hatch1-Jan-06 0:53
Cliff Hatch1-Jan-06 0:53 
Hi jbem

I'm not sure that your conclusion that you have to keep track of the number of items in the list is correct.

The list classes contain Serialize functions, and if you use these they keep track for you.

A while back I was builiding a simulator that contained a recursive structure of models and submodels, similar to your Cemu class. My class was CModel, of type CModelObject. It contained a list, m_ModelList, pointing to the submodels (also of type CModel).

m_ModelList was of type CModelList, declared as follows:
typedef CTypedPtrList<CObList, CModelObject*> CModelList;

And the CModel Serialize function was:
void CModel::Serialize(CArchive & ar)<br />
{<br />
	CModelObject::Serialize(ar);<br />
<br />
	//Serialize/de-serialize the submodels<br />
	m_ModelList.Serialize(ar);<br />
<br />
	if (ar.IsStoring())<br />
	{<br />
		ar << m_Name<br />
			<< m_Notes<br />
			<< m_AtomOrMacroNotes;<br />
	}<br />
	else<br />
	{<br />
		ar >> m_Name<br />
			>> m_Notes<br />
			>> m_AtomOrMacroNotes;<br />
	}<br />
}


The function saves the properties of the particular CModel object, m_Name, m_Notes, etc., and those defined in the base clase, CModelObject - and it saves the submodels by calling m_ModelList.Serialise(ar). When de-serializing, this call reinstates the list and all its associated objects.

I've stripped a lot of detail out of the example, but amongst the model properties there were also pointers to other models - so there were very many mutually recursive references, and I remember being concerned about how to tie all this back together on de-serialization. I was pleasantly suprised to find that the serialization mechanism looked after all of this for me automatically. I think it is an elegant system and a credit to its designers. It seems that all the user has to do is make sure that things are serialized and de-serialized in the same order.

Best Regards

Cliff

-- modified at 6:58 Sunday 1st January, 2006
GeneralRe: MFC Serialization Questions.. Pin
Cliff Hatch2-Jan-06 0:54
Cliff Hatch2-Jan-06 0:54 
QuestionHow to resize child window Pin
shivditya30-Dec-05 5:24
shivditya30-Dec-05 5:24 
AnswerRe: How to resize child window Pin
John R. Shaw31-Dec-05 18:55
John R. Shaw31-Dec-05 18:55 
Questionfile transfer time prblm Pin
Orell30-Dec-05 2:24
Orell30-Dec-05 2:24 
AnswerRe: file transfer time prblm Pin
Prakash Nadar30-Dec-05 5:14
Prakash Nadar30-Dec-05 5:14 
QuestionHow to check the config Pin
nripun30-Dec-05 2:11
nripun30-Dec-05 2:11 
AnswerRe: How to check the config Pin
sunit530-Dec-05 2:28
sunit530-Dec-05 2:28 
GeneralRe: How to check the config Pin
sunit530-Dec-05 2:33
sunit530-Dec-05 2:33 
GeneralRe: How to check the config Pin
nripun30-Dec-05 2:41
nripun30-Dec-05 2:41 
GeneralRe: How to check the config Pin
sunit530-Dec-05 2:58
sunit530-Dec-05 2:58 
GeneralRe: How to check the config Pin
nripun30-Dec-05 5:23
nripun30-Dec-05 5:23 
GeneralRe: How to check the config Pin
sunit530-Dec-05 3:18
sunit530-Dec-05 3:18 
QuestionHow help file(.hlp) can be integrated in my program Pin
mikobi30-Dec-05 1:46
mikobi30-Dec-05 1:46 
QuestionOLE 2.0 DB Problem Pin
ShelJo30-Dec-05 1:39
ShelJo30-Dec-05 1:39 
QuestionTo open com port thrugh window CE emulator Pin
birajendu30-Dec-05 1:25
birajendu30-Dec-05 1:25 
QuestionCustom Caption in XP Pin
Dave Regan30-Dec-05 1:25
Dave Regan30-Dec-05 1:25 
AnswerRe: Custom Caption in XP Pin
Owner drawn30-Dec-05 1:33
Owner drawn30-Dec-05 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.