Solved

Serialization

Posted on 1998-06-01
4
286 Views
Last Modified: 2013-11-19
How can I serialize the mixed implementation data structure of Graph? Thanks!
0
Comment
Question by:st2599
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

636 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