]>
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 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_SERIAL_CLASS(wxList
, wxObject
)
37 IMPLEMENT_SERIAL_CLASS(wxHashTable
, wxObject
)
40 void WXSERIAL(wxList
)::StoreObject(wxObjectOutputStream
& s
)
42 wxList
*lst_object
= (wxList
*)Object();
43 wxNode
*node
= lst_object
->First();
47 s
.AddChild(node
->Data());
53 wxDataOutputStream
data_s(s
);
55 data_s
.Write8(lst_object
->GetDeleteContents());
56 data_s
.Write8(lst_object
->GetKeyType());
57 data_s
.Write32( lst_object
->Number() );
59 if (lst_object
->GetKeyType() == wxKEY_INTEGER
) {
61 data_s
.Write32(node
->GetKeyInteger());
66 data_s
.WriteString(node
->GetKeyString());
72 void WXSERIAL(wxList
)::LoadObject(wxObjectInputStream
& s
)
74 wxDataInputStream
data_s(s
);
75 wxList
*list
= (wxList
*)Object();
78 list
->DeleteContents( data_s
.Read8() );
79 list
->SetKeyType( (wxKeyType
) data_s
.Read8() );
80 number
= data_s
.Read32();
82 if (list
->GetKeyType() == wxKEY_INTEGER
) {
83 for (i
=0;i
<number
;i
++)
84 list
->Append( data_s
.Read32(), s
.GetChild() );
86 for (i
=0;i
<number
;i
++)
87 list
->Append( data_s
.ReadString(), s
.GetChild() );
91 // ----------------------------------------------------------------------------
93 void WXSERIAL(wxHashTable
)::StoreObject(wxObjectOutputStream
& s
)
95 wxHashTable
*table
= (wxHashTable
*)Object();
99 for (i
=0;i
<table
->n
;i
++)
100 s
.AddChild(table
->hash_table
[i
]);
104 wxDataOutputStream
data_s(s
);
106 data_s
.Write8(table
->key_type
);
107 data_s
.Write32(table
->n
);
110 void WXSERIAL(wxHashTable
)::LoadObject(wxObjectInputStream
& s
)
112 wxHashTable
*table
= (wxHashTable
*)Object();
113 wxDataInputStream
data_s(s
);
116 key
= data_s
.Read8();
119 table
->Create(key
, n
);
122 table
->hash_table
[i
] = (wxList
*)s
.GetChild();
125 #endif // wxUSE_SERIAL