Code::Blocks  SVN r11506
tinywxuni.cpp
Go to the documentation of this file.
1 #include "sdk_precomp.h"
2 
3 #ifndef CB_PRECOMP
4  #include <wx/file.h>
5  #include <wx/string.h>
6  #include "filemanager.h"
7  #include "manager.h"
8 #endif
9 
10 #include "tinywxuni.h"
11 #include <tinyxml.h>
12 
13 bool TinyXML::LoadDocument(const wxString& filename, TiXmlDocument *doc)
14 {
15 
16  if (!doc || !wxFile::Access(filename, wxFile::read))
17  return false;
18 
19  wxFile file(filename);
20  size_t len = file.Length();
21 
22  if (!len)
23  return false;
24 
25  char *input = new char[len+1];
26  input[len] = '\0';
27  file.Read(input, len);
28 
29  doc->Parse(input);
30  delete[] input;
31  return !doc->Error();
32 }
33 
34 TiXmlDocument* TinyXML::LoadDocument(const wxString& filename)
35 {
36  TiXmlDocument* doc = new TiXmlDocument();
37 
38  if (TinyXML::LoadDocument(filename, doc))
39  return doc;
40 
41  delete doc;
42  return 0;
43 }
44 
45 bool TinyXML::SaveDocument(const wxString& filename, TiXmlDocument* doc)
46 {
47  if (!doc)
48  return false;
49 
50  TiXmlPrinter printer;
51  printer.SetIndent("\t");
52  doc->Accept(&printer);
53 
54  return Manager::Get()->GetFileManager()->SaveUTF8(filename, printer.CStr(), printer.Size());
55 }
56 
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
wxFileOffset Length() const
FileManager * GetFileManager() const
Definition: manager.cpp:479
bool LoadDocument(const wxString &filename, TiXmlDocument *doc)
Definition: tinywxuni.cpp:13
static bool Access(const wxString &name, wxFile::OpenMode mode)
ssize_t Read(void *buffer, size_t count)
bool SaveUTF8(const wxString &file, const char *data, size_t len)
bool SaveDocument(const wxString &, TiXmlDocument *)
Definition: tinywxuni.cpp:45