文档与串行化小结

  1. 数据持久性-串行化

     

    Constructs a CArchive object and specifies whether it will be used for loading or storing objects.

    CArchive(
       CFile* pFile,
       UINT nMode,
       int nBufSize = 4096,
       void* lpBuf = NULL
    );

     

    nMode

    A flag that specifies whether objects will be loaded from or stored to the archive. The nMode parameter must have one of the following values:

    • CArchive::load   Loads data from the archive. Requires only CFile read permission.
    • CArchive::store   Saves data to the archive. Requires CFile write permission.
    • CArchive::bNoFlushOnDelete   Prevents the archive from automatically calling Flush when the archive destructor is called. If you set this flag, you are responsible for explicitly calling Close before the destructor is called. If you do not, your data will be corrupted.

     

    CArchive does not have a base class.

    Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called "serialization."

    You can think of an archive object as a kind of binary stream. Like an input/output stream, an archive is associated with a file and permits the buffered writing and reading of data to and from storage. An input/output stream processes sequences of ASCII characters, but an archive processes binary object data in an efficient, nonredundant format.

    You must create a CFile object before you can create a CArchive object. In addition, you must ensure that the archive's load/store status is compatible with the file's open mode. You are limited to one active archive per file.

    When you construct a CArchive object, you attach it to an object of class CFile (or a derived class) that represents an open file. You also specify whether the archive will be used for loading or storing. A CArchive object can process not only primitive types but also objects of CObject-derived classes designed for serialization. A serializable class usually has a Serialize member function, and it usually uses the DECLARE_SERIAL and IMPLEMENT_SERIAL macros, as described under class CObject.

    The overloaded extraction (>>) and insertion (<<) operators are convenient archive programming interfaces that support both primitive types and CObject-derived classes.

    CArchive also supports programming with the MFC Windows Sockets classes CSocket and CSocketFile. The IsBufferEmpty member function supports that usage.

     

    文件读取代码:

    CFile file("1.txt",CFile::modeRead);

    CArchive ar(&file,CArchive::load);

    int i;

    char ch;

    float f;

    CString str;

    CString strResult;

    ar>>i>>ch>>f>>str;

    strResult.Format("%d,%c,%f,%s",i,ch,f,str);

    MessageBox(strResult);

     

    文件写入代码:

    CFile file("1.txt",CFile::modeCreate | CFile::modeWrite);

    CArchive ar(&file,CArchive::store);

    int i=4;

    char ch='a';

    float f=1.3f;

    CString str("Test Archive Usage");

    ar<<i<<ch<<f<<str;

     

     

    设置文档标题

    在OnNewDocument中调用SetTitle("新文档标题");

    String TableIDR_MAINFRAME字符串资源中各子串的含义:

    Retrieves a string associated with the document type.

    virtual BOOL GetDocString(
       CString& rString,
       enum DocStringIndex index
    ) const;

     

  2. (1)CDocTemplate::windowTitle,主窗口标题栏上的字符串,MDI程序不需要指定,将以IDR_MAINFRAME字符串为默认值。
  3. (2)CDocTemplate::docName,缺省文档的名称。如果没有指定,缺省文档的名称是无标题。
  4. (3)CDocTemplate::fileNewName,文档类型的名称。如果应用程序支持多种类型的文档,此字符串将显示在"File/New"对话框中。如果没有指定,就不能够在"File/New"对话框处理这种文件。
  5. (4)CDocTemplate::filterName,文档类型的描述和一个适用于此类型的通配符过滤器。这个字符串将出现在File/Open对话框中的文件类型列表框中。要和CDocTemplate::filterExt一起使用。
  6. (5)CDocTemplate::filterExt,文档的扩展名。如果没有指定,就不能够在File/Open对话框中处理这种文档。要和CDocTemplate::filterName一起使用。
  7. (6)CDocTemplate::regFileTypeId,如果你以::RegisterShellFileTypes向系统的注册表注册文件类型,此值会出现在HEY_CLASSES_ROOT之下成为其子项,并仅供Windows内部使用。如果没有指定,这种文件类型就无法注册。
  8. (7)CDocTemplate::regFileTypeName,这也是存储在注册表中的文件类型名称。它会显示于程序中用以访问注册表的对话框内。
  9.  

  10.  
  11. POSITION   A value used to denote the position of an element in a collection; used by MFC collection classes.

    Call this function to get the position of the first view in the list of views associated with the document.

    virtual POSITION GetFirstViewPosition( ) const;

    Call this function to iterate through all of the document's views.

    virtual CView* GetNextView(
       POSITION& rPosition
    ) const;

     

     

    在文档中得到视图类对象的指针

    POSITION pos=GetFirstViewPosition();

    CGraphicView *pView=(CGraphicView*)GetNextView(pos);

     

     

    Document/View结构

  12. MFC中,文档类负责管理数据,提供保存和加载数据的功能视类负责数据的显示,以及给用户提供对数据的编辑和修改功能
  13. MFC给我们提供Document/View结构,将一个应用程序所需要的数据处理与显示函数空壳都设计好了,这些函数都是虚函数,我们可以在派生类中重写这些函数。有关文件读写的操作在CDocumentSerialize函数中进行,有关数据和图形显示的操作在CViewOnDraw函数中进行。我们在其派生类中,只需要去关注SerializeOnDraw函数就可以了,其它的细节我们不需要去理会,程序就可以良好地运行。
  14. 当我们按下File/OpenApplication Framework会激活文件打开对话框,让你指定文件名,然后自动调用CGraphicDoc::Serialize读取文件。Application Framework还会调用CGraphicView::OnDraw,传递一个显示DC,让你重新绘制窗口内容。
  15. MFC给我们提供Document/View结构,是希望我们将精力放在数据结构的设计和数据显示的操作上,而不要把时间和精力花费在对象与对象之间、模块与模块之间的通信上。
  16. 一个文档对象可以和多个视类对象相关联,而一个视类对象只能和一个文档对象相关联
  17.  

    在文件的打开和销毁以及重复使用都会调用DeleteContents。需要在文档类中重载该虚函数,在其中销毁在堆上分配的内存。

     

    Called by the framework to delete the document's data without destroying the CDocument object itself.

    virtual void DeleteContents( );

     

    It is called just before the document is to be destroyed. It is also called to ensure that a document is empty before it is reused. This is particularly important for an SDI application, which uses only one document; the document is reused whenever the user creates or opens another document. Call this function to implement an "Edit Clear All" or similar command that deletes all of the document's data. The default implementation of this function does nothing. Override this function to delete the data in your document.

     

 
内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池全局池)、NAT转换(静态动态)、静态路由、RIPOSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值