]>
git.saurik.com Git - wxWidgets.git/blob - utils/serialize/sercore.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Serialization: core classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "sercore.h"
15 #include <wx/objstrm.h>
16 #include <wx/datstrm.h>
21 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
22 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
24 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
26 wxList
*lst_object
= (wxList
*)Object();
27 wxNode
*node
= lst_object
->First();
31 s
.AddChild(node
->Data());
37 wxDataOutputStream
data_s(s
);
39 data_s
.Write8(lst_object
->destroy_data
);
40 data_s
.Write8(lst_object
->key_type
);
41 data_s
.Write32( lst_object
->Number() );
43 if (lst_object
->key_type
== wxKEY_INTEGER
) {
45 data_s
.Write32(node
->key
.integer
);
50 data_s
.WriteString(node
->key
.string
);
56 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
58 wxDataInputStream
data_s(s
);
59 wxList
*list
= (wxList
*)Object();
62 list
->DeleteContents( data_s
.Read8() );
63 list
->key_type
= data_s
.Read8();
64 number
= data_s
.Read32();
66 if (list
->key_type
== wxKEY_INTEGER
) {
67 for (i
=0;i
<number
;i
++)
68 list
->Append( data_s
.Read32(), s
.GetChild() );
70 for (i
=0;i
<number
;i
++)
71 list
->Append( data_s
.ReadString(), s
.GetChild() );
75 // ----------------------------------------------------------------------------
77 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
79 wxHashTable
*table
= (wxHashTable
*)Object();
83 for (i
=0;i
<table
->n
;i
++)
84 s
.AddChild(table
->hash_table
[i
]);
88 wxDataOutputStream
data_s(s
);
90 data_s
.Write8(table
->key_type
);
91 data_s
.Write32(table
->n
);
94 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
96 wxHashTable
*table
= (wxHashTable
*)Object();
97 wxDataInputStream
data_s(s
);
100 key
= data_s
.Read8();
103 table
->Create(key
, n
);
106 table
->hash_table
[i
] = (wxList
*)s
.GetChild();