]> git.saurik.com Git - wxWidgets.git/blob - src/common/serbase.cpp
added default ctor for wxDirDialog
[wxWidgets.git] / src / common / serbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: serbase.cpp
3 // Purpose: wxStream base classes
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 11/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "serbase.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #include "wx/serbase.h"
20 #include "wx/datstrm.h"
21 #include "wx/objstrm.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_SERIAL
28
29 // ----------------------------------------------------------------------------
30 // wxObject_Serialize
31 // ----------------------------------------------------------------------------
32
33 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize,wxObject)
34
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
37 IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
38 #endif
39
40 void WXSERIAL(wxList)::StoreObject(wxObjectOutputStream& s)
41 {
42 wxList *lst_object = (wxList *)Object();
43 wxNode *node = lst_object->First();
44
45 if (s.FirstStage()) {
46 while (node) {
47 s.AddChild(node->Data());
48 node = node->Next();
49 }
50 return;
51 }
52
53 wxDataOutputStream data_s(s);
54
55 data_s.Write8(lst_object->GetDeleteContents());
56 data_s.Write8(lst_object->GetKeyType());
57 data_s.Write32( lst_object->Number() );
58
59 if (lst_object->GetKeyType() == wxKEY_INTEGER) {
60 while (node) {
61 data_s.Write32(node->GetKeyInteger());
62 node = node->Next();
63 }
64 } else {
65 while (node) {
66 data_s.WriteString(node->GetKeyString());
67 node = node->Next();
68 }
69 }
70 }
71
72 void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s)
73 {
74 wxDataInputStream data_s(s);
75 wxList *list = (wxList *)Object();
76 int number, i;
77
78 list->DeleteContents( data_s.Read8() );
79 list->SetKeyType( (wxKeyType) data_s.Read8() );
80 number = data_s.Read32();
81
82 if (list->GetKeyType() == wxKEY_INTEGER) {
83 for (i=0;i<number;i++)
84 list->Append( data_s.Read32(), s.GetChild() );
85 } else {
86 for (i=0;i<number;i++)
87 list->Append( data_s.ReadString(), s.GetChild() );
88 }
89 }
90
91 // ----------------------------------------------------------------------------
92
93 void WXSERIAL(wxHashTable)::StoreObject(wxObjectOutputStream& s)
94 {
95 wxHashTable *table = (wxHashTable *)Object();
96 int i;
97
98 if (s.FirstStage()) {
99 for (i=0;i<table->n;i++)
100 s.AddChild(table->hash_table[i]);
101 return;
102 }
103
104 wxDataOutputStream data_s(s);
105
106 data_s.Write8(table->key_type);
107 data_s.Write32(table->n);
108 }
109
110 void WXSERIAL(wxHashTable)::LoadObject(wxObjectInputStream& s)
111 {
112 wxHashTable *table = (wxHashTable *)Object();
113 wxDataInputStream data_s(s);
114 int i, key, n;
115
116 key = data_s.Read8();
117 n = data_s.Read32();
118
119 table->Create(key, n);
120
121 for (i=0;i<n;i++)
122 table->hash_table[i] = (wxList *)s.GetChild();
123 }
124
125 #endif // wxUSE_SERIAL