Click here to Skip to main content
16,007,843 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Howto Serialize a STL container? Pin
Alex Dong26-Nov-01 18:45
Alex Dong26-Nov-01 18:45 
GeneralRe: Howto Serialize a STL container? Pin
Christian Graus26-Nov-01 18:49
protectorChristian Graus26-Nov-01 18:49 
GeneralRe: Howto Serialize a STL container? Pin
Alex Dong26-Nov-01 18:52
Alex Dong26-Nov-01 18:52 
GeneralRe: Howto Serialize a STL container? Pin
Christian Graus26-Nov-01 18:59
protectorChristian Graus26-Nov-01 18:59 
GeneralRe: Howto Serialize a STL container? Pin
Alex Dong26-Nov-01 19:04
Alex Dong26-Nov-01 19:04 
AnswerRe: Howto Serialize a STL container? Pin
Ravi Bhavnani26-Nov-01 18:45
professionalRavi Bhavnani26-Nov-01 18:45 
GeneralRe: Howto Serialize a STL container? Pin
Alex Dong26-Nov-01 18:49
Alex Dong26-Nov-01 18:49 
GeneralRe: Howto Serialize a STL container? Pin
Ravi Bhavnani26-Nov-01 19:14
professionalRavi Bhavnani26-Nov-01 19:14 
The DECLARE_SERIAL and IMPLEMENT_SERIAL macros come in handy when you want to fit into MFC's doc-view architecture. However, imho you can keep your code general (and therefore less error prone) if you perform serialization manually. You can even still use MFC's doc-view support - just do the serialization yourself.

  1. In your collection class, add a method like long serialize (CArchive* pArchive);

  2. When you want to serialize to/from a file, open the file (for read/write as the case may be), create a CArchive object and attach it to the file, and finally pass it to your collection's serialize() method.

  3. Serialization will "magically" occur (see my previous note) since the top level collection class will delegate the work to its contents, as necessary.

  4. When you deserialize from an older version of an object, be sure to adjust your "latest version" object as necessary. When you serialize, always save the latest version of the object. For example:
    long nVersion << *pArchive;
    if (nVersion < CURRENT_VERSION) {
       m_someMember = 0;
    } else {
       m_someMember << *pArchive; // member only present in this version!
    }
    
The only "drawback" with this method is that you have to do some work to implement a "Save As Old Version" feature in your app. This not so bad, since it's usually enough to be able to *read* older versions of your data.

/ravi

"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
GeneralActiveX Control Path Pin
Yong Haur TAY26-Nov-01 16:40
Yong Haur TAY26-Nov-01 16:40 
GeneralCHtmlView, Access Violation On Resize.. aaiiieeee!!! Pin
foobat26-Nov-01 16:38
foobat26-Nov-01 16:38 
GeneralSorting ComboBox items ! Pin
Hadi Rezaee26-Nov-01 15:21
Hadi Rezaee26-Nov-01 15:21 
GeneralRemoving the sunken border in a CFormView Pin
26-Nov-01 15:16
suss26-Nov-01 15:16 
GeneralRe: Removing the sunken border in a CFormView Pin
Joshua Guy27-Nov-01 8:14
Joshua Guy27-Nov-01 8:14 
GeneralRe: Removing the sunken border in a CFormView Pin
foobat27-Nov-01 15:53
foobat27-Nov-01 15:53 
GeneralRight-aligned text in CStatic Pin
LukeV26-Nov-01 13:30
LukeV26-Nov-01 13:30 
GeneralRe: Right-aligned text in CStatic Pin
Christian Graus26-Nov-01 13:40
protectorChristian Graus26-Nov-01 13:40 
GeneralRe: Right-aligned text in CStatic Pin
LukeV26-Nov-01 14:25
LukeV26-Nov-01 14:25 
GeneralRe: Right-aligned text in CStatic Pin
Michael Dunn26-Nov-01 15:19
sitebuilderMichael Dunn26-Nov-01 15:19 
GeneralRe: Right-aligned text in CStatic Pin
LukeV26-Nov-01 15:54
LukeV26-Nov-01 15:54 
GeneralRe: IDC_STATIC? Pin
Masaaki Onishi26-Nov-01 17:50
Masaaki Onishi26-Nov-01 17:50 
GeneralFlex grid - ActiveX Control Pin
sassiecode26-Nov-01 13:05
sassiecode26-Nov-01 13:05 
GeneralRe: Flex grid - ActiveX Control Pin
Christian Graus26-Nov-01 13:38
protectorChristian Graus26-Nov-01 13:38 
GeneralExporting classes in dll Pin
Stormwind26-Nov-01 11:59
Stormwind26-Nov-01 11:59 
GeneralRe: Exporting classes in dll Pin
Joaquín M López Muñoz26-Nov-01 12:38
Joaquín M López Muñoz26-Nov-01 12:38 
GeneralDocking windows WHY!! Pin
26-Nov-01 11:56
suss26-Nov-01 11:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.