]> git.saurik.com Git - wxWidgets.git/blame - utils/serialize/sercore.cpp
Changed to use new wxWindow->Reparent call to allow build with current cvs
[wxWidgets.git] / utils / serialize / sercore.cpp
CommitLineData
123a7fdd
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: sercore.cpp
3// Purpose: Serialization: core classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: July 1998
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
9fdd8384
GL
12#ifdef __GNUG__
13#pragma implementation "sercore.h"
14#endif
15#include <wx/objstrm.h>
16#include <wx/datstrm.h>
8d43638d
GL
17#include <wx/list.h>
18#include <wx/hash.h>
9fdd8384
GL
19#include "sercore.h"
20
8d43638d
GL
21IMPLEMENT_SERIAL_CLASS(wxList, wxObject)
22IMPLEMENT_SERIAL_CLASS(wxHashTable, wxObject)
9fdd8384
GL
23
24void WXSERIAL(wxList)::StoreObject(wxObjectOutputStream& s)
25{
26 wxList *lst_object = (wxList *)Object();
27 wxNode *node = lst_object->First();
28
29 if (s.FirstStage()) {
30 while (node) {
31 s.AddChild(node->Data());
32 node = node->Next();
33 }
34 return;
35 }
36
37 wxDataOutputStream data_s(s);
38
39 data_s.Write8(lst_object->destroy_data);
40 data_s.Write8(lst_object->key_type);
41 data_s.Write32( lst_object->Number() );
42
43 if (lst_object->key_type == wxKEY_INTEGER) {
44 while (node) {
45 data_s.Write32(node->key.integer);
46 node = node->Next();
47 }
48 } else {
49 while (node) {
50 data_s.WriteString(node->key.string);
51 node = node->Next();
52 }
53 }
54}
55
56void WXSERIAL(wxList)::LoadObject(wxObjectInputStream& s)
57{
58 wxDataInputStream data_s(s);
59 wxList *list = (wxList *)Object();
60 int number, i;
61
62 list->DeleteContents( data_s.Read8() );
63 list->key_type = data_s.Read8();
64 number = data_s.Read32();
65
66 if (list->key_type == wxKEY_INTEGER) {
67 for (i=0;i<number;i++)
8d43638d 68 list->Append( data_s.Read32(), s.GetChild() );
9fdd8384
GL
69 } else {
70 for (i=0;i<number;i++)
8d43638d 71 list->Append( data_s.ReadString(), s.GetChild() );
9fdd8384
GL
72 }
73}
8d43638d
GL
74
75// ----------------------------------------------------------------------------
76
77void WXSERIAL(wxHashTable)::StoreObject(wxObjectOutputStream& s)
78{
79 wxHashTable *table = (wxHashTable *)Object();
80 int i;
81
82 if (s.FirstStage()) {
83 for (i=0;i<table->n;i++)
84 s.AddChild(table->hash_table[i]);
85 return;
86 }
87
88 wxDataOutputStream data_s(s);
89
90 data_s.Write8(table->key_type);
91 data_s.Write32(table->n);
92}
93
94void WXSERIAL(wxHashTable)::LoadObject(wxObjectInputStream& s)
95{
96 wxHashTable *table = (wxHashTable *)Object();
97 wxDataInputStream data_s(s);
98 int i, key, n;
99
100 key = data_s.Read8();
101 n = data_s.Read32();
102
103 table->Create(key, n);
104
105 for (i=0;i<n;i++)
106 table->hash_table[i] = (wxList *)s.GetChild();
107}