removed USE_SHARED_LIBRARY(IES)
[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 IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
36 IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
37
38 void WXSERIAL(wxList)::StoreObject(wxObjectOutputStream& s)
39 {
40 wxList *lst_object = (wxList *)Object();
41 wxNode *node = lst_object->First();
42
43 if (s.FirstStage()) {
44 while (node) {
45 s.AddChild(node->Data());
46 node = node->Next();
47 }
48 return;
49 }
50
51 wxDataOutputStream data_s(s);
52
53 data_s.Write8(lst_object->GetDeleteContents());
54 data_s.Write8(lst_object->GetKeyType());
55 data_s.Write32( lst_object->Number() );
56
57 if (lst_object->GetKeyType() == wxKEY_INTEGER) {
58 while (node) {
59 data_s.Write32(node->GetKeyInteger());
60 node = node->Next();
61 }
62 } else {
63 while (node) {
64 data_s.WriteString(node->GetKeyString());
65 node = node->Next();
66 }
67 }
68 }
69
70 void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s)
71 {
72 wxDataInputStream data_s(s);
73 wxList *list = (wxList *)Object();
74 int number, i;
75
76 list->DeleteContents( data_s.Read8() );
77 list->SetKeyType( (wxKeyType) data_s.Read8() );
78 number = data_s.Read32();
79
80 if (list->GetKeyType() == wxKEY_INTEGER) {
81 for (i=0;i<number;i++)
82 list->Append( data_s.Read32(), s.GetChild() );
83 } else {
84 for (i=0;i<number;i++)
85 list->Append( data_s.ReadString(), s.GetChild() );
86 }
87 }
88
89 // ----------------------------------------------------------------------------
90
91 void WXSERIAL(wxHashTable)::StoreObject(wxObjectOutputStream& s)
92 {
93 wxHashTable *table = (wxHashTable *)Object();
94 int i;
95
96 if (s.FirstStage()) {
97 for (i=0;i<table->n;i++)
98 s.AddChild(table->hash_table[i]);
99 return;
100 }
101
102 wxDataOutputStream data_s(s);
103
104 data_s.Write8(table->key_type);
105 data_s.Write32(table->n);
106 }
107
108 void WXSERIAL(wxHashTable)::LoadObject(wxObjectInputStream& s)
109 {
110 wxHashTable *table = (wxHashTable *)Object();
111 wxDataInputStream data_s(s);
112 int i, key, n;
113
114 key = data_s.Read8();
115 n = data_s.Read32();
116
117 table->Create(key, n);
118
119 for (i=0;i<n;i++)
120 table->hash_table[i] = (wxList *)s.GetChild();
121 }
122
123 #endif // wxUSE_SERIAL