This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathXMLFileSerializer.cpp
More file actions
executable file
·94 lines (84 loc) · 2.26 KB
/
XMLFileSerializer.cpp
File metadata and controls
executable file
·94 lines (84 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "XMLFileSerializer.h"
#include "..\Helpers\Helpers.h"
#include "XMLContainer.h"
namespace star
{
XMLFileSerializer::XMLFileSerializer(
const tstring & path, DirectoryMode mode)
: m_File(path, mode)
{
}
XMLFileSerializer::~XMLFileSerializer() {}
void XMLFileSerializer::Write(
XMLContainer & container
)
{
tstring buffer = WriteFile(container);
WriteTextFile(m_File.GetLocalPath(), buffer, m_File.GetDirectoryMode());
}
void XMLFileSerializer::Write(
XMLContainer & container,
const tstring & binaryPath
)
{
Write(container);
container.Serialize(binaryPath, m_File.GetDirectoryMode());
}
tstring XMLFileSerializer::WriteFile(XMLContainer & container)
{
tstringstream strstrResult;
strstrResult << _T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") << std::endl;
uint32 tabs(0);
WriteChild(strstrResult, container, tabs);
return strstrResult.str();
}
void XMLFileSerializer::WriteAtributes(tstringstream & strstr, XMLContainer & element)
{
auto attributes = element.GetAttributes();
for(auto attribute : attributes)
{
strstr << _T(" ") << attribute.first << _T("=\"") << attribute.second << _T("\"");
}
}
void XMLFileSerializer::WriteChild(tstringstream & strstr, XMLContainer & element, uint32 & tabs)
{
strstr << GetTabString(tabs) << _T("<") << element.GetName();
WriteAtributes(strstr, element);
if(element.size() == 0 && element.GetValue() == EMPTY_STRING)
{
strstr << _T("/>") << std::endl;
}
else
{
strstr << _T(">");
if(element.GetValue() != EMPTY_STRING)
{
strstr << element.GetValue();
strstr << _T("</") << element.GetName();
strstr << _T(">") << std::endl;
}
else if(element.size() > 0)
{
++tabs;
strstr << std::endl;
for(auto child : element)
{
XMLContainer child_value;
child_value = *(child.second);
WriteChild(strstr, child_value, tabs);
}
--tabs;
strstr << GetTabString(tabs) << _T("</") << element.GetName() << _T(">") << std::endl;
}
}
}
tstring XMLFileSerializer::GetTabString(uint32 & tabs)
{
tstring tab_string(EMPTY_STRING);
for(uint32 i = 0 ; i < tabs ; ++i)
{
tab_string += TAB;
}
return tab_string;
}
}