]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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() << doc
.GetEncoding();
105 SaveBinNode(ds
, doc
.GetRoot());
106 return stream
.LastError() == wxSTREAM_NOERROR
;
111 static wxXmlProperty
*LoadBinProp(wxDataInputStream
& ds
)
115 if (dummy
== 0) return NULL
;
117 wxString name
, value
;
119 return new wxXmlProperty(name
, value
, LoadBinProp(ds
));
125 static wxXmlNode
*LoadBinNode(wxDataInputStream
& ds
, wxXmlNode
*parent
)
128 wxString name
, content
;
132 if (dummy
== 0) return NULL
;
133 ds
>> type
>> name
>> content
;
135 wxXmlProperty
*prop
= LoadBinProp(ds
);
137 wxXmlNode
*nd
= new wxXmlNode(parent
, (wxXmlNodeType
)type
, name
, content
,
138 prop
, LoadBinNode(ds
, parent
));
145 bool wxXmlIOHandlerBin::Load(wxInputStream
& stream
, wxXmlDocument
& doc
)
148 wxDataInputStream
ds(stream
);
154 doc
.SetEncoding(tmp
);
156 doc
.SetRoot(LoadBinNode(ds
, NULL
));
158 return (doc
.GetRoot() != NULL
);