]>
git.saurik.com Git - wxWidgets.git/blob - src/common/serbase.cpp
1f2ea96f9c00f8b5b884169b75a6878d8bf05d3d
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"
19 #include "wx/serbase.h"
20 #include "wx/datstrm.h"
21 #include "wx/objstrm.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize
,wxObject
)
33 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
34 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
37 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
39 wxList
*lst_object
= (wxList
*)Object();
40 wxNode
*node
= lst_object
->First();
44 s
.AddChild(node
->Data());
50 wxDataOutputStream
data_s(s
);
52 data_s
.Write8(lst_object
->GetDeleteContents());
53 data_s
.Write8(lst_object
->GetKeyType());
54 data_s
.Write32( lst_object
->Number() );
56 if (lst_object
->GetKeyType() == wxKEY_INTEGER
) {
58 data_s
.Write32(node
->GetKeyInteger());
63 data_s
.WriteString(node
->GetKeyString());
69 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
71 wxDataInputStream
data_s(s
);
72 wxList
*list
= (wxList
*)Object();
75 list
->DeleteContents( data_s
.Read8() );
76 list
->SetKeyType( (wxKeyType
) data_s
.Read8() );
77 number
= data_s
.Read32();
79 if (list
->GetKeyType() == wxKEY_INTEGER
) {
80 for (i
=0;i
<number
;i
++)
81 list
->Append( data_s
.Read32(), s
.GetChild() );
83 for (i
=0;i
<number
;i
++)
84 list
->Append( data_s
.ReadString(), s
.GetChild() );
88 // ----------------------------------------------------------------------------
90 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
92 wxHashTable
*table
= (wxHashTable
*)Object();
96 for (i
=0;i
<table
->n
;i
++)
97 s
.AddChild(table
->hash_table
[i
]);
101 wxDataOutputStream
data_s(s
);
103 data_s
.Write8(table
->key_type
);
104 data_s
.Write32(table
->n
);
107 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
109 wxHashTable
*table
= (wxHashTable
*)Object();
110 wxDataInputStream
data_s(s
);
113 key
= data_s
.Read8();
116 table
->Create(key
, n
);
119 table
->hash_table
[i
] = (wxList
*)s
.GetChild();