Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help for collection types serialization...

Status
Not open for further replies.

MarcoMB

Programmer
Oct 24, 2006
61
0
0
IT
I have to serialize a CObArray that contains class objects made by 2 CArray elements that handles POINT struct:

CArray<POINT,POINT> myArray1;
CArray<POINT,POINT> myArray2;

how can i serialize it?
 
sorry uolj i didn't want to be repetitive... i get help from your link but my app still doesn't work like due...i assume i could send you my project via email so that u could look it...if u want of course...
 
Sorry, like I said I don't do much work in this area, and I don't really have time to figure it out for you.

If you've tried something, post it. You really haven't posted much code, so it is hard for people to help you. The more you post, the easier it is. It sounds like you should be able to make a small, one file, test program that has the same problem. Try doing that and posting all the code here. Include what you have tried and think should work. That will make it easier for those of us who don't know the answer off the top of our heads to potentially help you figure it out.
 
ok i'll try to explain better...

i have an object class

class CSpLine : public CObject
{
DECLARE_SERIAL(CSpLine)
public:
void AFXAPI SerializeElements(CArchive &ar,POINT*,int nCount);
CSpLine();
void Serialize(CArchive &ar);
void Draw(HDC& hDC);
CArray <POINT,POINT> m_ControlPoints;
CArray <POINT,POINT> m_CurvePoints;

CSpLine::CSpLine(CArray<POINT,POINT>&ControlPoints,CArray<POINT,POINT>&CurvePoints);
virtual ~CSpLine();

};

class SpLine is for handling graphic SpLine so it has ControlPoints(the node of curve) and real CurvePoints represented by 2 CArray objects of types POINT.

In my CView derived class handles MouseMove message:
void MyView::OnMouseMove(UINT nFlags, CPoint point)
{

pDoc->m_ControlPoints[m_MoveIndex] = point;
if (pDoc->m_ControlPoints.GetSize()>1)
{
Spline spline(pDoc->m_ControlPoints.GetData(),pDoc->m_ControlPoints.GetSize());
spline.Generate();

pDoc->m_CurvePoints.SetSize(spline.GetCurveCount());
int PointCount = 0;
spline.GetCurve(pDoc->m_CurvePoints.GetData(),PointCount);
}
CDC* pDC = GetDC();

OnDraw(pDC);
ReleaseDC(pDC);
CSpLine* pSpLine = pDoc->AddSpLine();
pSpLine->Draw(pDC->m_hDC);

calls AddSpLine function that add to CObArray


CSpLine* MyDocument::AddSpLine()
{

CSpLine* pSpLine = new CSpLine(m_ControlPoints,m_CurvePoints);
m_oaSpLines.Add(pSpLine);

return pSpLine;
}
where m_oaSpLines is a CObArray.

i call serialize in document class for m_oaSpLine
void mydocument::Serialize(CArchive& ar)
{

m_oaSpLines.Serialize(ar);

}

so we recall serialize in SpLine class and i don't know how to implement serialization here,i can't use << >> operators so if i write
void CSpLine::Serialize(CArchive &ar)
{
m_ControlPoints.Serialize(ar);
m_CurvePoints.Serialize(ar);
/* i can't write
if (ar.IsStoring)
ar << m_ControlPoints <<m_CurvePoints;
else
ar >> m_ControlPoints >>m_CurvePoints;
*/
}

there's no compiler error but there's no serialization and i lost data...
i hope it's quite clear...
 
Good, that should help someone. Unfortunately it doesn't help me much. What about your attempt to use SerializeElements? I thought that's what you need to use.

Also, in the future you should post code inside the [code][/code] tags so that it is easier to read.
 
i tried to use SerializeElements but i think it not resolve the problem, 'cos if i don't say wrong it makes a cycle for CArray "MyClass" Objects in CDocument class, calling once per objects the serialize function within MyClass Class.
But my problem is that i go on serialize method of MyClass from starting CObArray and so in MyClass i have CArray objects to Serialize...and i really don't know how to do...therefore the CArray variables care array of POINT structures, so not user-defined types, and so this structure hasn't a serialize method...i think i must change road...i'm doing a mistake...i'm sure but i don't know how solve...please some guru help me [shadessad]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top