]>
git.saurik.com Git - wxWidgets.git/blob - src/common/serbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxStream base classes
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "serbase.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18 #if defined(__WINDOWS__)
19 #include "wx/msw/private.h"
22 #include "wx/serbase.h"
23 #include "wx/datstrm.h"
24 #include "wx/objstrm.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize
,wxObject
)
38 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
39 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
41 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
43 wxList
*lst_object
= (wxList
*)Object();
44 wxNode
*node
= lst_object
->First();
48 s
.AddChild(node
->Data());
54 wxDataOutputStream
data_s(s
);
56 data_s
.Write8(lst_object
->GetDeleteContents());
57 data_s
.Write8(lst_object
->GetKeyType());
58 data_s
.Write32( lst_object
->Number() );
60 if (lst_object
->GetKeyType() == wxKEY_INTEGER
) {
62 data_s
.Write32((size_t)node
->GetKeyInteger());
67 data_s
.WriteString(node
->GetKeyString());
73 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
75 wxDataInputStream
data_s(s
);
76 wxList
*list
= (wxList
*)Object();
79 list
->DeleteContents( data_s
.Read8() );
80 list
->SetKeyType( (wxKeyType
) data_s
.Read8() );
81 number
= data_s
.Read32();
83 if (list
->GetKeyType() == wxKEY_INTEGER
) {
84 for (i
=0;i
<number
;i
++)
85 list
->Append( data_s
.Read32(), s
.GetChild() );
87 for (i
=0;i
<number
;i
++)
88 list
->Append( data_s
.ReadString(), s
.GetChild() );
92 // ----------------------------------------------------------------------------
94 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
96 wxHashTable
*table
= (wxHashTable
*)Object();
100 for (i
=0;i
<table
->n
;i
++)
101 s
.AddChild(table
->hash_table
[i
]);
105 wxDataOutputStream
data_s(s
);
107 data_s
.Write8(table
->key_type
);
108 data_s
.Write32(table
->n
);
111 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
113 wxHashTable
*table
= (wxHashTable
*)Object();
114 wxDataInputStream
data_s(s
);
117 key
= data_s
.Read8();
120 table
->Create(key
, n
);
123 table
->hash_table
[i
] = (wxList
*)s
.GetChild();
126 #endif // wxUSE_SERIAL