]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: sercore.cpp | |
3 | // Purpose: Serialization: core classes | |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: July 1998 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Guilhem Lavaux | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "sercore.h" | |
14 | #endif | |
15 | #include <wx/objstrm.h> | |
16 | #include <wx/datstrm.h> | |
17 | #include "sercore.h" | |
18 | ||
19 | IMPLEMENT_SERIAL_CLASS(wxList,wxObject) | |
20 | ||
21 | void WXSERIAL(wxList)::StoreObject(wxObjectOutputStream& s) | |
22 | { | |
23 | wxList *lst_object = (wxList *)Object(); | |
24 | wxNode *node = lst_object->First(); | |
25 | ||
26 | if (s.FirstStage()) { | |
27 | while (node) { | |
28 | s.AddChild(node->Data()); | |
29 | node = node->Next(); | |
30 | } | |
31 | return; | |
32 | } | |
33 | ||
34 | wxDataOutputStream data_s(s); | |
35 | ||
36 | data_s.Write8(lst_object->destroy_data); | |
37 | data_s.Write8(lst_object->key_type); | |
38 | data_s.Write32( lst_object->Number() ); | |
39 | ||
40 | if (lst_object->key_type == wxKEY_INTEGER) { | |
41 | while (node) { | |
42 | data_s.Write32(node->key.integer); | |
43 | node = node->Next(); | |
44 | } | |
45 | } else { | |
46 | while (node) { | |
47 | data_s.WriteString(node->key.string); | |
48 | node = node->Next(); | |
49 | } | |
50 | } | |
51 | } | |
52 | ||
53 | void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s) | |
54 | { | |
55 | wxDataInputStream data_s(s); | |
56 | wxList *list = (wxList *)Object(); | |
57 | int number, i; | |
58 | ||
59 | list->DeleteContents( data_s.Read8() ); | |
60 | list->key_type = data_s.Read8(); | |
61 | number = data_s.Read32(); | |
62 | ||
63 | if (list->key_type == wxKEY_INTEGER) { | |
64 | for (i=0;i<number;i++) | |
65 | list->Append( data_s.Read32(), s.GetChild(i) ); | |
66 | } else { | |
67 | for (i=0;i<number;i++) | |
68 | list->Append( data_s.ReadString(), s.GetChild(i) ); | |
69 | } | |
70 | } |