MFC技术内幕系列之(五)---MFC文档序列化内幕[7]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 bigwhite20xx 的 blog

  m_nobjectschema = nschema;

 // store obtag for later examination
 if (pobtag != null)
  *pobtag = obtag;

 // return the resulting cruntimeclass*
 return pclassref;
  }
--->
 cruntimeclass* pascal cruntimeclass::load(carchive& ar, uint* pwschemanum)
 // loads a runtime class description
{
 word nlen;
 char szclassname[64];

 word wtemp;
 ar >> wtemp; *pwschemanum = wtemp;//读入版本号
 ar >> nlen;//读入类名称字符串中的字符个数

 // load the class name,读入类名称
 if (nlen >= _countof(szclassname) ||
  ar.read(szclassname, nlen*sizeof(char)) != nlen*sizeof(char))
 {
  return null;
 }
 szclassname[nlen] = '\0';

 // match the string against an actual cruntimeclass
 cruntimeclass* pclass = fromname(szclassname);
 if (pclass == null)
 {
  // not found, trace a warning for diagnostic purposes
  trace(traceappmsg, 0, "warning: cannot load %hs from archive.  class not                         defined.\n",
   szclassname);
 }

 return pclass;
 }
 
---〉在carchive::readobject函数中有pob->serialize(*this);即调用cstroke类的serialize函数。以此类推。
  总结:我们看看本程序到底从硬盘中读了什么?
   按顺序应该是:ctypedptrlist中的元素个数---〉新旧类标志---〉版本号(m_wschema)---〉
                类名称字符串中的字符个数----〉类名称(ansi码)---〉调用其它成员的                                 serialize 函数。---〉以此类推。
  由此可以看出读入数据的顺序与写入数据时的顺序完全相同。
                       /////////////////////////////////////
                       /*         4.结局             */
                       /////////////////////////////////////
   至此,mfc技术内幕系列文章都已结束,文章中肯定有很多纰漏和错误,希望读者们批评指点。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


本文关键:文档序列化
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top