亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch22.htm

?? 24小時學(xué)會vc++
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>		<META NAME="GENERATOR" Content="Symantec Visual Page Mac 1.1">	<TITLE>Teach Yourself Visual C++&#174; 5 in 24 Hours -- Hour 22 -- Serialization</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><H1 ALIGN="CENTER"><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM"BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself Visual C++&#174; 5 in 24 Hours</FONT></H1><CENTER><P><A HREF="../ch21/ch21.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch23/ch23.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><H1 ALIGN="CENTER"><FONT COLOR="#000077">- Hour 22 -<BR>Serialization</FONT></H1><P>Serialization is the method used by MFC programs to read and write applicationdata to files. In this hour, you will learn about<UL>	<LI>Persistence and serialization	<LI>Serialization support in commonly used MFC classes	<LI>Macros and other MFC features that are used when implementing serialization</UL><P>You will also create an example that uses serialization in a Document/View application.<H2><FONT COLOR="#000077"><B>What Is Serialization?</B></FONT></H2><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B><I>Serialization</I> is theprocess of storing the state of an object for the purpose of loading it at anothertime.</P><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>The property of an objectto be stored and loaded is <I>persistence</I>, which is also defined as the capabilityof an object to remember its state between executions.</P><P>Serialization is the way in which classes derived from <TT>CDocument</TT> storeand retrieve data from an archive, which is usually a file. Figure 22.1 shows theinteraction between a serialized object and an archive.</P><P><A NAME="01"></A><A HREF="01.htm"><B>Figure 22.1.</B></A> <I><BR>Serializing an object to and from an archive.</I></P><P>When an object is serialized, information about the type of object is writtento the storage along with information and data about the object. When an object isdeserialized, the same process happens in reverse, and the object is loaded and createdfrom the input stream.<H2><FONT COLOR="#000077"><B>Why Use Serialization?</B></FONT></H2><P>The goal behind serialization is to make the storage of complex objects as simpleand reliable as the storage of the basic data types available in C++. You can storea basic type, such as an <TT>int</TT>, in a file in the following way:</P><PRE><FONT COLOR="#0066FF"><TT>int nFoo = 5;</TT><TT>fileStream &lt;&lt; nFoo;</TT></FONT></PRE><P>If a file contains an <TT>int</TT> value, it can be read from the stream in thefollowing way:</P><PRE><FONT COLOR="#0066FF"><TT>fileStream &gt;&gt; nFoo;</TT></FONT></PRE><P>A persistent object can be serialized and deserialized using a similar syntax,no matter how complicated the object's internal structure. The alternative is tocreate routines that understand how every object is implemented and handle the processof storing and retrieving data from files.</P><P>Using serialization to store objects is much more flexible than writing specializedfunctions that store data in a fixed format. Objects that are persistent are capableof storing themselves, instead of relying on an external function to read and writethem to disk. This makes a persistent object much easier to reuse because the objectis more self-contained.</P><P>Persistent objects also help you easily write programs that are saved to storage.An object that is serialized might be made up of many smaller objects that are alsoserialized. Because individual objects are often stored in a collection, serializingthe collection also serializes all objects contained in the collection.<H2><FONT COLOR="#000077"><B>A Document/View Serialization Example</B></FONT></H2><P>Using AppWizard, create an MDI project named Customers. This project uses serializationto store a very simple list of customer names and email addresses, using a persistentclass named <TT>CUser</TT>. This project will serve as the basis for examples andsource code used in the remainder of this hour.<H3><FONT COLOR="#000077"><B>Serializing the Customers Project</B></FONT></H3><P>In Hour 1, &quot;Introducing Visual C++ 5,&quot; you used the insertion operator,or <TT>&lt;&lt;</TT>, to output a value to the screen. This operator is actuallythe C++ left-shift operator, but it is overloaded so that whenever an output objectand variable are separated by a <TT>&lt;&lt;</TT>, as in the following code line,the variable is written to the output object:</P><PRE><FONT COLOR="#0066FF"><TT>file_object &lt;&lt; data</TT></FONT></PRE><P>In a similar way, whenever input is performed and the objects are separated bya <TT>&gt;&gt;</TT>, as in the following code line, a new value for the variableis retrieved from the input object:</P><PRE><FONT COLOR="#0066FF"><TT>file_object &gt;&gt; data</TT></FONT></PRE><P>In C++, unlike some other languages, input and output are controlled by the interactionbetween file and variable objects. The exact process used for input and output iscontrolled by the way in which the classes implement the <TT>&gt;&gt;</TT> and <TT>&lt;&lt;</TT>operators.</P><P>For the topics in this hour, you create a persistent class named <TT>CUser</TT>,along with the helper functions required to serialize a collection of <TT>CUser</TT>objects. Each <TT>CUser</TT> object contains a customer name and email address.<H3><FONT COLOR="#000077"><B>The MFC Classes Used for Serialization</B></FONT></H3><P>You use two MFC classes to serialize objects:<UL>	<LI><TT>CArchive</TT> is almost always a file and is the object that other persistent	objects are serialized to or from.<BR>	<BR>		<LI><TT>CObject</TT> defines all the interfaces used to serialize objects to or from	a <TT>CArchive</TT> object.</UL><P>Objects are serialized in one of two ways. As a rule of thumb, if an object isderived from <TT>CObject</TT>, that object's <TT>Serialize</TT> member function iscalled in the following way:</P><PRE><FONT COLOR="#0066FF"><TT>myObject.Serialize( ar );</TT></FONT></PRE><P>If the object isn't derived from <TT>CObject</TT>--such as a <TT>CRect</TT> object--youshould use the inser-tion operator in the following way:</P><PRE><FONT COLOR="#0066FF"><TT>ar &lt;&lt; rcWnd;</TT></FONT></PRE><P>This insertion operator is overloaded in the same way it is for <TT>cout</TT>,<TT>cin</TT>, and <TT>cerr</TT>, which were used in the first two hours for consolemode input and output.<H4><FONT COLOR="#000077">Using the CObject Class</FONT></H4><P>You must use the <TT>CObject</TT> class for all classes that use the MFC classlibrary's built-in support for serialization. The <TT>CObject</TT> class containsvirtual functions that are used during serialization. In addition, the <TT>CArchive</TT>class is declared as a &quot;friend&quot; class for <TT>CObject</TT>, providing itaccess to private and protected member variables.</P><P>The most commonly used virtual function in <TT>CObject</TT> is <TT>Serialize</TT>,which is called to serialize or deserialize the object from a <TT>CArchive</TT> object.This function is declared as virtual so that any persistent object can be calledthrough a pointer to <TT>CObject</TT> in the following way:</P><PRE><FONT COLOR="#0066FF"><TT>CObject* pObj = GetNextObject();</TT><TT>pObj-&gt;Serialize( ar );</TT></FONT></PRE><P>As discussed later in the section &quot;Using the Serialization Macros,&quot;when you're deriving a persistent class from <TT>CObject</TT>, you must use two macrosto help implement the serialization functions.<H4><FONT COLOR="#000077">The CArchive Class</FONT></H4><P>The <TT>CArchive</TT> class is used to model a generic storage object. In mostcases, a <TT>CArchive</TT> object is attached to a disk file. In some cases, however,the object might be connected to an object that only seems to be a file, like a memorylocation or another type of storage.</P><P>When a <TT>CArchive</TT> object is created, it is defined as used for either inputor output but never both. You can use the <TT>IsStoring</TT> and <TT>IsLoading</TT>functions to determine whether a <TT>CArchive</TT> object is used for input or output,as shown in Listing 22.1.<H4><FONT COLOR="#000077">TYPE: Listing 22.1. Using the CArchive::IsStoring functionto determine the serialization direction.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>CMyObject:Serialize( CArchive&amp; ar )</TT><TT>{</TT><TT>    if( ar.IsStoring() )</TT><TT>        // Write object state to ar</TT><TT>    else</TT><TT>        // Read object state from ar</TT><TT>}</TT></FONT></PRE><H3><FONT COLOR="#000077"><B>Using the Insertion and Extraction Operators</B></FONT></H3><P>The MFC class library overloads the insertion and extraction operators for manycommonly used classes and basic types. You often use the insertion operator, <TT>&lt;&lt;</TT>,to serialize--or store--data to the <TT>CArchive</TT> object. You use the extractionoperator, <TT>&gt;&gt;</TT>, to deserialize--or load--data from a <TT>CArchive</TT>object.</P><P>These operators are defined for all basic C++ types, as well as a few commonlyused classes not derived from <TT>CObject</TT>, such as the <TT>CString</TT>, <TT>CRect</TT>,and <TT>CTime</TT> classes. The insertion and extraction operators return a referenceto a <TT>CArchive</TT> object, enabling them to be chained together in the followingway:</P><PRE><FONT COLOR="#0066FF"><TT>archive &lt;&lt; m_nFoo &lt;&lt; m_rcClient &lt;&lt; m_szName;</TT></FONT></PRE><P>When used with classes that are derived from <TT>CObject</TT>, the insertion andextraction operators allocate the memory storage required to contain an object andthen call the object's <TT>Serialize</TT> member function. If you don't need to allocatestorage, you should call the <TT>Serialize</TT> member function directly.</P><P>As a rule of thumb, if you know the type of the object when it is deserialized,call the <TT>Serialize</TT> function directly. In addition, you must always call<TT>Serialize</TT> exclusively. If you use <TT>Serialize</TT> to load or store anobject, you must not use the insertion and extraction operators at any other timewith that object.<H3><FONT COLOR="#000077"><B>Using the Serialization Macros</B></FONT></H3><P>There are two macros that you must use when creating a persistent class basedon <TT>CObject</TT>. Use the <TT>DECLARE_SERIAL</TT> macro in the class declarationfile and the <TT>IMPLEMENT_SERIAL</TT> macro in the class implementation file.<H4><FONT COLOR="#000077">Declaring a Persistent Class</FONT></H4><P>The <TT>DECLARE_SERIAL</TT> macro takes a single parameter: the name of the classto be serialized. An example of a class that can be serialized is provided in Listing22.2. Save this source code in the Customers project directory in a file named <TT>Users.h</TT>.<BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Time Saver:</B></FONT><B> </B>A good place to put	the <TT>DECLARE_SERIAL</TT> macro is on the first line of the class declaration,	where it serves as a reminder that the class can be serialized. <HR></BLOCKQUOTE><H4><FONT COLOR="#000077">TYPE: Listing 22.2. The CUser class declaration.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#ifndef CUSER</TT><TT>#define CUSER</TT><TT>class CUser : public CObject</TT><TT>{</TT><TT>    DECLARE_SERIAL(CUser);</TT><TT>public:</TT><TT>    // Constructors</TT><TT>    CUser();</TT><TT>    CUser( const CString&amp; szName, const CString&amp; szAddr );</TT><TT>    // Attributes</TT><TT>    void Set( const CString&amp; szName, const CString&amp; szAddr );</TT><TT>    CString GetName() const;</TT><TT>    CString GetAddr() const;</TT><TT>    // Operations</TT><TT>    virtual void Serialize( CArchive&amp; ar );</TT><TT>    // Implementation</TT><TT>private:</TT><TT>    // The user's name</TT><TT>    CString m_szName;</TT><TT>    // The user's e-mail addresss</TT><TT>    CString m_szAddr;</TT><TT>};</TT><TT>#endif CUSER</TT></FONT></PRE><H4><FONT COLOR="#000077">Defining a Persistent Class</FONT></H4><P>The <TT>IMPLEMENT_SERIAL</TT> macro takes three parameters and is usually placedbefore any member functions are defined for a persistent class. The parameters for<TT>IMPLEMENT_SERIAL</TT> are the following:<UL>	<LI>The class to be serialized	<LI>The immediate base class of the class being serialized	<LI>The schema, or version number</UL><P>The schema number is a version number for the class layout used when you're serializingand deserializing objects. If the schema number of the data being loaded doesn'tmatch the schema number of the object reading the file, the program throws an exception.The schema number should be incremented when changes are made that affect serialization,such as adding a class member or changing the serialization order.</P><P>The member functions for the <TT>CUser</TT> class, including the <TT>IMPLEMENT_SERIAL</TT>macro, are provided in Listing 22.3. Save this source code in the Customers projectdirectory as <TT>Users.cpp</TT>.<H4><FONT COLOR="#000077">TYPE: Listing 22.3. The CUser member functions.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#include &quot;stdafx.h&quot;</TT><TT>#include &quot;Users.h&quot;</TT><TT>IMPLEMENT_SERIAL( CUser, CObject, 1 );</TT><TT>CUser::CUser() { }</TT><TT>CUser::CUser( const CString&amp; szName, const CString&amp; szAddr )</TT><TT>{</TT><TT>    Set( szName, szAddr );</TT>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品传媒在线观看| av在线不卡电影| 日韩一区二区三| 中文字幕永久在线不卡| 国产一区不卡视频| 欧美国产精品一区| 不卡的av电影| 亚洲欧洲国产日韩| 91高清视频在线| 亚洲一区二区美女| 欧美日韩精品欧美日韩精品| 欧美aⅴ一区二区三区视频| 欧美日韩性生活| 日韩伦理电影网| 欧美福利电影网| 蜜乳av一区二区| 欧美国产乱子伦| 在线视频一区二区免费| 亚洲观看高清完整版在线观看 | 日韩免费在线观看| 看电视剧不卡顿的网站| 久久久99久久精品欧美| 91免费观看在线| 亚洲在线观看免费视频| 欧美一级在线视频| 高清不卡一区二区| 一区二区三区小说| 欧美色电影在线| 国产在线播放一区三区四| 久久精品亚洲一区二区三区浴池 | 亚洲成a人片在线观看中文| 欧美精选一区二区| 蜜桃av一区二区在线观看| 一区视频在线播放| 欧美日韩你懂得| 五月综合激情网| 久久精品视频网| 91麻豆自制传媒国产之光| 亚洲第一主播视频| 国产欧美日韩精品在线| 91在线porny国产在线看| 一区二区不卡在线播放| 精品日本一线二线三线不卡| 粉嫩13p一区二区三区| www.欧美亚洲| 亚洲午夜视频在线| 欧美一区二区三区视频免费播放 | 免费观看91视频大全| 国产精品视频观看| 欧美剧在线免费观看网站| 成人综合日日夜夜| 日韩黄色一级片| 国产精品久久久久一区| 久久亚区不卡日本| 欧美日韩中文精品| 成人国产在线观看| 国产精品资源网站| 午夜久久久久久久久久一区二区| 国产成人精品免费视频网站| 视频一区在线播放| 国产精品欧美精品| 国产日韩欧美麻豆| 欧美剧在线免费观看网站| 成人黄页毛片网站| 精品一区二区三区免费观看| 亚洲成av人片一区二区梦乃| 亚洲摸摸操操av| 国产女主播一区| 日韩欧美123| 日韩午夜小视频| 欧美性高清videossexo| 国产·精品毛片| 美女视频一区二区| 亚洲va中文字幕| 亚洲不卡av一区二区三区| 国产精品国产三级国产专播品爱网| 日韩三级视频在线看| 日韩欧美中文字幕精品| 欧美高清精品3d| 无码av免费一区二区三区试看| 亚洲在线观看免费| 亚洲欧美激情在线| 亚洲六月丁香色婷婷综合久久 | 精品久久免费看| 日韩欧美国产综合在线一区二区三区| 色婷婷香蕉在线一区二区| av一区二区不卡| 色呦呦一区二区三区| 成人性生交大片免费看视频在线 | 国产精品午夜在线| 国产欧美一区二区精品久导航 | 8v天堂国产在线一区二区| 欧美精品国产精品| 在线观看91av| 5858s免费视频成人| 精品少妇一区二区三区 | 另类中文字幕网| 一区二区三区欧美久久| 亚洲老司机在线| 一区二区三区加勒比av| 视频一区二区中文字幕| 老司机一区二区| 免费成人在线网站| 成人免费不卡视频| 91视频一区二区三区| 成人成人成人在线视频| 91影视在线播放| 欧美日韩精品欧美日韩精品| 欧美videossexotv100| 久久久精品人体av艺术| 日韩三级.com| 日韩一区欧美小说| 亚洲曰韩产成在线| 狠狠色丁香久久婷婷综合丁香| 国产在线国偷精品产拍免费yy| 国产成人一区在线| 欧美日韩在线播放三区| 日韩一级二级三级| 日韩免费一区二区| 亚洲欧美怡红院| 日韩专区中文字幕一区二区| 福利一区在线观看| 91久久精品一区二区二区| 在线观看日韩精品| 久久综合狠狠综合| 中文字幕一区二区三区四区不卡| 天天操天天干天天综合网| 国内精品伊人久久久久av一坑| 成人深夜视频在线观看| 欧美肥妇毛茸茸| 国产欧美一区二区在线| 亚洲天堂精品视频| 精品一区二区三区免费视频| 成人高清伦理免费影院在线观看| 欧美人伦禁忌dvd放荡欲情| 久久女同精品一区二区| 亚洲精品成人在线| 成人福利视频网站| 欧美一区二区久久| 国产精品久久久久久久久免费樱桃 | 亚洲欧洲中文日韩久久av乱码| 日本亚洲最大的色成网站www| 国产成人午夜精品影院观看视频| 91麻豆精品视频| 欧美精品一区男女天堂| 亚洲一二三级电影| 色综合久久久久综合体| 精品国产乱码久久久久久久久| 成人欧美一区二区三区视频网页| 老鸭窝一区二区久久精品| 日本高清免费不卡视频| 中文字幕一区在线观看视频| 久久99精品久久只有精品| 在线观看www91| 亚洲欧美另类图片小说| 国产一区二区三区日韩| 日韩欧美亚洲国产精品字幕久久久| 综合精品久久久| 国产aⅴ综合色| 亚洲精品在线三区| 五月婷婷激情综合网| 精品视频1区2区| 亚洲精品ww久久久久久p站| 亚洲乱码国产乱码精品精小说| 成人黄色电影在线| 久久久久久久久一| 国产成人免费视频网站 | 精品在线播放免费| 91精品一区二区三区久久久久久| 日韩一区中文字幕| 丁香婷婷综合激情五月色| 欧美一区二区三区视频在线观看| 日本在线不卡一区| 欧美福利电影网| 国产精品对白交换视频| 99国产精品久久久久| 国产精品久久久一本精品| 色综合久久综合| 亚洲日本电影在线| 成人国产一区二区三区精品| 中文字幕一区二区三区不卡在线| 成人看片黄a免费看在线| 亚洲视频一二区| 99久久er热在这里只有精品15 | 国产精品久久久久久久裸模| 粉嫩嫩av羞羞动漫久久久| 久久久精品免费网站| 国产精品影视天天线| 国产喂奶挤奶一区二区三区| 成a人片国产精品| 亚洲六月丁香色婷婷综合久久 | 丁香婷婷综合色啪| 中文字幕日韩av资源站| 欧美中文一区二区三区| 亚洲高清视频中文字幕| 欧美亚洲国产bt| 国产精选一区二区三区 | 中文字幕 久热精品 视频在线| 国产91丝袜在线播放九色| 国产精品欧美一区喷水|