]>
git.saurik.com Git - wxWidgets.git/blob - src/common/serbase.cpp
cf00ab21d534be9d4dc1d0a18b460ab96d6e7bdf
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"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 #if !USE_SHARED_LIBRARY
34 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize
,wxObject
)
35 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
36 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
39 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
41 wxList
*lst_object
= (wxList
*)Object();
42 wxNode
*node
= lst_object
->First();
46 s
.AddChild(node
->Data());
52 wxDataOutputStream
data_s(s
);
54 data_s
.Write8(lst_object
->GetDeleteContents());
55 data_s
.Write8(lst_object
->GetKeyType());
56 data_s
.Write32( lst_object
->Number() );
58 if (lst_object
->GetKeyType() == wxKEY_INTEGER
) {
60 data_s
.Write32(node
->GetKeyInteger());
65 data_s
.WriteString(node
->GetKeyString());
71 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
73 wxDataInputStream
data_s(s
);
74 wxList
*list
= (wxList
*)Object();
77 list
->DeleteContents( data_s
.Read8() );
78 list
->SetKeyType( (wxKeyType
) data_s
.Read8() );
79 number
= data_s
.Read32();
81 if (list
->GetKeyType() == wxKEY_INTEGER
) {
82 for (i
=0;i
<number
;i
++)
83 list
->Append( data_s
.Read32(), s
.GetChild() );
85 for (i
=0;i
<number
;i
++)
86 list
->Append( data_s
.ReadString(), s
.GetChild() );
90 // ----------------------------------------------------------------------------
92 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
94 wxHashTable
*table
= (wxHashTable
*)Object();
98 for (i
=0;i
<table
->n
;i
++)
99 s
.AddChild(table
->hash_table
[i
]);
103 wxDataOutputStream
data_s(s
);
105 data_s
.Write8(table
->key_type
);
106 data_s
.Write32(table
->n
);
109 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
111 wxHashTable
*table
= (wxHashTable
*)Object();
112 wxDataInputStream
data_s(s
);
115 key
= data_s
.Read8();
118 table
->Create(key
, n
);
121 table
->hash_table
[i
] = (wxList
*)s
.GetChild();
124 #endif // wxUSE_SERIAL