2.4.3 Serializing the stroke list and the stroke
The straightforward implementation of serialize for CStrokeList and CStroke are as follows:
void CStrokeList::Serialize(
CArchiveamp; ar) {
CObject::Serialize(ar);
if (ar.IsStoring()) {
ar ‹‹ (WORD) size ();
for(list‹CStroke*›::iterator it = begin(); it!= end(); ++it) ar ‹‹ *it;
}
else {
WORD s;
ar ›› s; // get size
clear();
for (int i = 0; i!=s; i ++)
{
ar ›› temp; push_back(temp);
}
}
}
void CStroke::Serialize(
CArchiveamp; ar) {
CObject::Serialize(ar);
if (ar.IsStoring()) {
ar ‹‹ (WORD)m_nPenWidth;
ar ‹‹
(WORD) m_pointArray.size();
for (vector‹CPoint›::iterator i = m_pointArray.begin(); i!= m_pointArray.end(); ++i)
ar ‹‹ *i;
}
else {
WORD w;
ar ›› w; // pen width
m_nPenWidth = w;
m_pointArray.clear();
ar ›› w; // array size
CPoint point;
m_pointArray.reserve(w);
for (int i = 0; i ‹ w; ++i)
{
ar ›› point; m_pointArray.push_back(
point);
}
}
}