]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xmlbin.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxXmlIOHandlerBin
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 // nothing, already in xml.cpp
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/datstrm.h"
26 #include "wx/xrc/xmlio.h"
31 bool wxXmlIOHandlerBin::CanLoad(wxInputStream
& stream
)
34 canread
= (ReadHeader(stream
) == wxT("XMLBIN "));
35 stream
.SeekI(-9, wxFromCurrent
);
41 wxString
wxXmlIOHandlerBin::ReadHeader(wxInputStream
& stream
)
46 stream
.Read(cheader
, 8);
48 stream
.Read(&version
, 1);
50 if (version
!= 1) return wxEmptyString
;
51 else return wxString(cheader
);
56 void wxXmlIOHandlerBin::WriteHeader(wxOutputStream
& stream
, const wxString
& header
)
62 for (i
= 0; i
< header
.Length(); i
++) cheader
[i
] = header
[i
];
63 for (; i
< 7; i
++) cheader
[i
] = ' ';
65 stream
.Write(cheader
, 8);
66 stream
.Write(&version
, 1);
71 static bool SaveBinNode(wxDataOutputStream
& ds
, wxXmlNode
*node
)
76 (wxUint8
)node
->GetType() <<
77 node
->GetName() << node
->GetContent();
79 wxXmlProperty
*prop
= node
->GetProperties();
83 ds
<< prop
->GetName() << prop
->GetValue();
84 prop
= prop
->GetNext();
89 SaveBinNode(ds
, node
->GetNext());
90 SaveBinNode(ds
, node
->GetChildren());
100 bool wxXmlIOHandlerBin::Save(wxOutputStream
& stream
, const wxXmlDocument
& doc
)
102 WriteHeader(stream
, "XMLBIN ");
103 wxDataOutputStream
ds(stream
);
104 ds
<< doc
.GetVersion();
106 ds
<< wxString(wxT("UTF-8"));
108 ds
<< doc
.GetEncoding();
110 SaveBinNode(ds
, doc
.GetRoot());
111 return stream
.LastError() == wxSTREAM_NOERROR
;
116 static wxXmlProperty
*LoadBinProp(wxDataInputStream
& ds
)
120 if (dummy
== 0) return NULL
;
122 wxString name
, value
;
124 return new wxXmlProperty(name
, value
, LoadBinProp(ds
));
130 static wxXmlNode
*LoadBinNode(wxDataInputStream
& ds
, wxXmlNode
*parent
)
133 wxString name
, content
;
137 if (dummy
== 0) return NULL
;
138 ds
>> type
>> name
>> content
;
140 wxXmlProperty
*prop
= LoadBinProp(ds
);
142 wxXmlNode
*nd
= new wxXmlNode(parent
, (wxXmlNodeType
)type
, name
, content
,
143 prop
, LoadBinNode(ds
, parent
));
150 bool wxXmlIOHandlerBin::Load(wxInputStream
& stream
, wxXmlDocument
& doc
,
151 const wxString
& encoding
)
154 wxDataInputStream
ds(stream
);
160 doc
.SetFileEncoding(tmp
);
162 doc
.SetRoot(LoadBinNode(ds
, NULL
));
164 return (doc
.GetRoot() != NULL
);