forked from EasyRPG/liblcf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_xml.h
143 lines (120 loc) · 2.82 KB
/
writer_xml.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* This file is part of liblcf. Copyright (c) liblcf authors.
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
*
* liblcf is Free/Libre Open Source Software, released under the MIT License.
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code.
*/
#ifndef LCF_WRITER_XML_H
#define LCF_WRITER_XML_H
#include <string>
#include <vector>
#include <memory>
#include <cstdio>
#include <stdint.h>
#include "lcf/string_view.h"
#include "lcf/saveopt.h"
#include "lcf/span.h"
namespace lcf {
/**
* XmlWriter class.
*/
class XmlWriter {
public:
/**
* Constructs a new XML File Writer.
*
* @param filestream already opened filestream.
* @param engine Which engine format to write.
*/
XmlWriter(std::ostream& filestream, EngineVersion engine);
/**
* Destructor. Closes the opened file.
*/
~XmlWriter();
/**
* Closes the opened file.
*/
void Close();
/**
* Writes an integer to the stream.
*
* @param val the integer.
*/
void WriteInt(int val);
/**
* Writes a primitive value to the stream.
*
* @param val the value.
*/
template <class T>
void Write(const T& val);
/**
* Writes a primitive value in a node to the stream.
* Calls BeginElement, Write and EndElement.
*
* @param name the node name string.
* @param val the value.
*/
template <class T>
void WriteNode(const std::string& name, const T& val);
/**
* Writes element starting tag to the stream.
*
* @param name the element name string.
*/
void BeginElement(const std::string& name);
/**
* Writes element starting tag and attribute id to the stream.
*
* @param name the element name string.
* @param ID the attribute ID integer.
*/
void BeginElement(const std::string& name, int ID);
/**
* Writes element ending tag to the stream.
*
* @param name the element name string.
*/
void EndElement(const std::string& name);
/**
* Writes a line break to the stream.
*/
void NewLine();
/**
* Checks if the file is writable and if no error
* occured.
*
* @return true if the stream is okay.
*/
bool IsOk() const;
/** @return true if 2k3 format, false if 2k format */
bool Is2k3() const;
protected:
/** File-stream managed by this Writer. */
std::ostream& stream;
/** Stores indentation level. */
int indent;
/** Indicates if writer cursor is at the beginning of the line. */
bool at_bol;
/** Writing which engine format */
EngineVersion engine;
/**
* Writes an indentation to the stream.
*/
void Indent();
/**
* Writes a vector of primitive values to the stream.
*
* @param val vector to write.
*/
template <class ArrayType>
void WriteVector(const ArrayType& val);
void WriteString(StringView s);
};
inline bool XmlWriter::Is2k3() const {
return engine == EngineVersion::e2k3;
}
} //namespace lcf
#endif