Serializing subclass-objects problem 
Author Message
 Serializing subclass-objects problem

I seem to have problems serializing subclass-objects in a pointer-list. I've
implemented the macro in every class ensuring that the second parameter in
IMPLEMENT_SERIAL is the parentclass to the subclass. The baseclass ofcourse
inherits from CObject. In the baseclass is a CTypedPtrList<CObList,
BaseClass*> which holds all the pointers to the subclass-objects. This is
the one I want to serialize and save to disk.

I've included default constructors as well in all classes. In the doc I've
placed a pointer to the baseclass and the doc's Serialize(CArchive& ar)
looks like this:

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

if (ar.IsStoring())
 {
  m_pBaseClass->Serialize(ar);
 }
 else
 {
  m_pBaseClass->Serialize(ar);
 }

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

The BaseClass' Serialize(..) looks like this:

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

CObject::Serialize(ar);

 if(ar.IsStoring())
 {
  m_CTypedPtrList.Serialize(ar);
  ar << m_someData << m_someOtherData << m_someOtherData;;
 }
 else
 {
  rg_listOfComponents.Serialize(ar);
  ar >> m_someData >> m_someOtherData >> m_someOtherData;
 }

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

And in every subclass' Serialize(..) is implemented

BaseClass::Serialize(ar);

or

Parentclass_to_Subclass::Serialize(ar);

according to which class it inherits from.

If a given subclass introduce new membervariables I've included this in
their Serialze(..) after :

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

 if(ar.IsStoring())
 {
  m_SubClass_specific_member_data.Serialize(ar);
 }
 else
 {
  m_SubClass_specific_member_data.Serialize(ar);
 }
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Hope I clarified what I've done so far, and that someone is able to help me
solve this. The file saved do hold some data but but it's not working.

Regards
JB



Sat, 10 Sep 2005 13:16:44 GMT  
 Serializing subclass-objects problem
Hmmm...

A clean and a rebuild solved the problem. Well. At least I got a chance to
improve my written english :)


Quote:
> I seem to have problems serializing subclass-objects in a pointer-list.
I've
> implemented the macro in every class ensuring that the second parameter in
> IMPLEMENT_SERIAL is the parentclass to the subclass. The baseclass
ofcourse
> inherits from CObject. In the baseclass is a CTypedPtrList<CObList,
> BaseClass*> which holds all the pointers to the subclass-objects. This is
> the one I want to serialize and save to disk.

> I've included default constructors as well in all classes. In the doc I've
> placed a pointer to the baseclass and the doc's Serialize(CArchive& ar)
> looks like this:

> ////////////////////////////////////////////////////////////////////////

> if (ar.IsStoring())
>  {
>   m_pBaseClass->Serialize(ar);
>  }
>  else
>  {
>   m_pBaseClass->Serialize(ar);
>  }

> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

> The BaseClass' Serialize(..) looks like this:

> ////////////////////////////////////////////////////////////////////////

> CObject::Serialize(ar);

>  if(ar.IsStoring())
>  {
>   m_CTypedPtrList.Serialize(ar);
>   ar << m_someData << m_someOtherData << m_someOtherData;;
>  }
>  else
>  {
>   rg_listOfComponents.Serialize(ar);
>   ar >> m_someData >> m_someOtherData >> m_someOtherData;
>  }

> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

> And in every subclass' Serialize(..) is implemented

> BaseClass::Serialize(ar);

> or

> Parentclass_to_Subclass::Serialize(ar);

> according to which class it inherits from.

> If a given subclass introduce new membervariables I've included this in
> their Serialze(..) after :

> ////////////////////////////////////////////////////////////////////////

>  if(ar.IsStoring())
>  {
>   m_SubClass_specific_member_data.Serialize(ar);
>  }
>  else
>  {
>   m_SubClass_specific_member_data.Serialize(ar);
>  }
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

> Hope I clarified what I've done so far, and that someone is able to help
me
> solve this. The file saved do hold some data but but it's not working.

> Regards
> JB



Sat, 10 Sep 2005 13:23:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. problem serializing remote client activate object

2. problems sending objects across network using serialize/deserialize

3. Problem serializing object of type CObList

4. Serializing Derived Objects problem

5. Serializing objects with multiple pointers to the same object

6. CDialog, subclass or not to subclass?

7. Visual inheritance - new window objects in subclass

8. Serializing/deserializing nested objects

9. Serialize Complex Object - How?

10. reading/Writting a serialized object to an Access database

11. serialize a collection as an array object

12. Need help serializing object in managed c++

 

 
Powered by phpBB® Forum Software