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