]> git.saurik.com Git - wxWidgets.git/blame - src/common/serbase.cpp
added some utils (tex2rtf, helpgen, makegen) to make system
[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"
18
907789a0
RR
19#include "wx/serbase.h"
20#include "wx/datstrm.h"
21#include "wx/objstrm.h"
09cf7c58
RR
22
23#ifdef __BORLANDC__
24#pragma hdrstop
25#endif
26
9838df2c 27#if wxUSE_SERIAL
e107d053 28
09cf7c58
RR
29// ----------------------------------------------------------------------------
30// wxObject_Serialize
31// ----------------------------------------------------------------------------
32
09cf7c58 33IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize,wxObject)
60df2e7d 34
907789a0
RR
35IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
36IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
907789a0
RR
37
38void 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) {
13111b2a 59 data_s.Write32((size_t)node->GetKeyInteger());
907789a0
RR
60 node = node->Next();
61 }
62 } else {
63 while (node) {
64 data_s.WriteString(node->GetKeyString());
65 node = node->Next();
66 }
67 }
68}
69
70void 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
91void 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
108void 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}
926c550d 122
e107d053 123#endif // wxUSE_SERIAL