]> git.saurik.com Git - wxWidgets.git/blob - src/common/serbase.cpp
corrected blind fix of missing .c_str()s
[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 #if defined(__WINDOWS__)
19 #include "wx/msw/private.h"
20 #endif
21
22 #include "wx/serbase.h"
23 #include "wx/datstrm.h"
24 #include "wx/objstrm.h"
25
26 #ifdef __BORLANDC__
27 #pragma hdrstop
28 #endif
29
30 #if wxUSE_SERIAL
31
32 // ----------------------------------------------------------------------------
33 // wxObject_Serialize
34 // ----------------------------------------------------------------------------
35
36 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize,wxObject)
37
38 IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
39 IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
40
41 void WXSERIAL(wxList)::StoreObject(wxObjectOutputStream& s)
42 {
43 wxList *lst_object = (wxList *)Object();
44 wxNode *node = lst_object->First();
45
46 if (s.FirstStage()) {
47 while (node) {
48 s.AddChild(node->Data());
49 node = node->Next();
50 }
51 return;
52 }
53
54 wxDataOutputStream data_s(s);
55
56 data_s.Write8(lst_object->GetDeleteContents());
57 data_s.Write8(lst_object->GetKeyType());
58 data_s.Write32( lst_object->Number() );
59
60 if (lst_object->GetKeyType() == wxKEY_INTEGER) {
61 while (node) {
62 data_s.Write32((size_t)node->GetKeyInteger());
63 node = node->Next();
64 }
65 } else {
66 while (node) {
67 data_s.WriteString(node->GetKeyString());
68 node = node->Next();
69 }
70 }
71 }
72
73 void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s)
74 {
75 wxDataInputStream data_s(s);
76 wxList *list = (wxList *)Object();
77 int number, i;
78
79 list->DeleteContents( data_s.Read8() != 0 );
80 list->SetKeyType( (wxKeyType) data_s.Read8() );
81 number = data_s.Read32();
82
83 if (list->GetKeyType() == wxKEY_INTEGER) {
84 for (i=0;i<number;i++)
85 list->Append( data_s.Read32(), s.GetChild() );
86 } else {
87 for (i=0;i<number;i++)
88 list->Append( data_s.ReadString(), s.GetChild() );
89 }
90 }
91
92 // ----------------------------------------------------------------------------
93
94 void WXSERIAL(wxHashTable)::StoreObject(wxObjectOutputStream& s)
95 {
96 wxHashTable *table = (wxHashTable *)Object();
97 int i;
98
99 if (s.FirstStage()) {
100 for (i=0;i<table->n;i++)
101 s.AddChild(table->hash_table[i]);
102 return;
103 }
104
105 wxDataOutputStream data_s(s);
106
107 data_s.Write8(table->key_type);
108 data_s.Write32(table->n);
109 }
110
111 void WXSERIAL(wxHashTable)::LoadObject(wxObjectInputStream& s)
112 {
113 wxHashTable *table = (wxHashTable *)Object();
114 wxDataInputStream data_s(s);
115 int i, key, n;
116
117 key = data_s.Read8();
118 n = data_s.Read32();
119
120 table->Create(key, n);
121
122 for (i=0;i<n;i++)
123 table->hash_table[i] = (wxList *)s.GetChild();
124 }
125
126 #endif // wxUSE_SERIAL