• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Serialization

How can I serialize the mixed implementation data structure of Graph? Thanks!
0
st2599
Asked:
st2599
  • 3
1 Solution
 
RONSLOWCommented:
Assuming Graph is a class then you simple write a Serialize function that checks if ar.IsStoring and then either does ar << xxx or ar >> xxx for each member var xxx depending on whether storing or not.

If you are using MFC doc/view model, then you would (probably) need to serialise the Graph as part of your document.  Or you can attach a CArchive to a CFile and archive it yourself.

0
 
MarkusLoiblCommented:
Additional info: If you have e.g. a nonfixed number of "objects", you can do the following:
CMyDoc::Serialize(CArchive& ar)
{
 CGraph::Serialize(ar)
 // ... continue with normal serialize-stuff
}

CGraph::Serialize(CArchive& ar)
{
 if (ar.IsStoring())
 {
  ar << m_amountOfObjects;
  for( int i=0 ; i< m_amountOfObjects ; i++ )
  {
    CMyObject *pObject = GetMyObject(i);
    pObject->Serialize(ar);
  }
 }
 else
 {
  ar >> m_amountOfObjects;
  for( int i=0 ; i< m_amountOfObjects ; i++ )
  {
    CMyObject *pObject = new CMyObject();
    pObject->Serialize(ar);
    AddMyObject(pObject);
   }
 }
}

CMyObject::Serialize() ...
0
 
RONSLOWCommented:
I suggest you post further info about your particular case if the more general answer/comments are not detailed enough.
0
 
RONSLOWCommented:
I suggest you post further info about your particular case if the more general answer/comments are not detailed enough.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now