Solved

Serialization

Posted on 1998-06-01
4
254 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
Best tools for Backup and restore of Wordpress site 6 55
My project did see openJDK that I installed. What could be the problem 7 122
Not needed 13 93
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now