]>
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"
19 #include "wx/serbase.h"
20 #include "wx/datstrm.h"
21 #include "wx/objstrm.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 IMPLEMENT_DYNAMIC_CLASS(wxObject_Serialize
,wxObject
)
35 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
36 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
38 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
40 wxList
*lst_object
= (wxList
*)Object();
41 wxNode
*node
= lst_object
->First();
45 s
.AddChild(node
->Data());
51 wxDataOutputStream
data_s(s
);
53 data_s
.Write8(lst_object
->GetDeleteContents());
54 data_s
.Write8(lst_object
->GetKeyType());
55 data_s
.Write32( lst_object
->Number() );
57 if (lst_object
->GetKeyType() == wxKEY_INTEGER
) {
59 data_s
.Write32((size_t)node
->GetKeyInteger());
64 data_s
.WriteString(node
->GetKeyString());
70 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
72 wxDataInputStream
data_s(s
);
73 wxList
*list
= (wxList
*)Object();
76 list
->DeleteContents( data_s
.Read8() );
77 list
->SetKeyType( (wxKeyType
) data_s
.Read8() );
78 number
= data_s
.Read32();
80 if (list
->GetKeyType() == wxKEY_INTEGER
) {
81 for (i
=0;i
<number
;i
++)
82 list
->Append( data_s
.Read32(), s
.GetChild() );
84 for (i
=0;i
<number
;i
++)
85 list
->Append( data_s
.ReadString(), s
.GetChild() );
89 // ----------------------------------------------------------------------------
91 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
93 wxHashTable
*table
= (wxHashTable
*)Object();
97 for (i
=0;i
<table
->n
;i
++)
98 s
.AddChild(table
->hash_table
[i
]);
102 wxDataOutputStream
data_s(s
);
104 data_s
.Write8(table
->key_type
);
105 data_s
.Write32(table
->n
);
108 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
110 wxHashTable
*table
= (wxHashTable
*)Object();
111 wxDataInputStream
data_s(s
);
114 key
= data_s
.Read8();
117 table
->Create(key
, n
);
120 table
->hash_table
[i
] = (wxList
*)s
.GetChild();
123 #endif // wxUSE_SERIAL