]> git.saurik.com Git - wxWidgets.git/blame - src/common/serbase.cpp
Converting uninitialized data is not a Good Idea
[wxWidgets.git] / src / common / serbase.cpp
CommitLineData
09cf7c58
RR
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__
907789a0 13#pragma implementation "serbase.h"
09cf7c58
RR
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
ff0ea71c
GT
18#if defined(__WINDOWS__)
19#include "wx/msw/private.h"
20#endif
09cf7c58 21
907789a0
RR
22#include "wx/serbase.h"
23#include "wx/datstrm.h"
24#include "wx/objstrm.h"
09cf7c58
RR
25
26#ifdef __BORLANDC__
27#pragma hdrstop
28#endif
29
9838df2c 30#if wxUSE_SERIAL
e107d053 31
09cf7c58
RR
32// ----------------------------------------------------------------------------
33// wxObject_Serialize
34// ----------------------------------------------------------------------------
35
09cf7c58 36IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize,wxObject)
60df2e7d 37
907789a0
RR
38IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
39IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
907789a0
RR
40
41void 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) {
13111b2a 62 data_s.Write32((size_t)node->GetKeyInteger());
907789a0
RR
63 node = node->Next();
64 }
65 } else {
66 while (node) {
67 data_s.WriteString(node->GetKeyString());
68 node = node->Next();
69 }
70 }
71}
72
73void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s)
74{
75 wxDataInputStream data_s(s);
76 wxList *list = (wxList *)Object();
77 int number, i;
78
e2c27123 79 list->DeleteContents( data_s.Read8() != 0 );
907789a0
RR
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
94void 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
111void 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}
926c550d 125
e107d053 126#endif // wxUSE_SERIAL