Solved

Serialization

Posted on 1998-06-01
4
265 Views
Last Modified: 2013-11-19
How can I serialize the mixed implementation data structure of Graph? Thanks!
0
Comment
Question by:st2599
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1315881
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
 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1315882
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1315883
I suggest you post further info about your particular case if the more general answer/comments are not detailed enough.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1315884
I suggest you post further info about your particular case if the more general answer/comments are not detailed enough.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 61
Process filename extension 3 186
substring method in java 1 123
zeroFront challenge 7 99
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question