17#include "../../math.hpp"
26 throw XMLException(
"XML reader: Can't read input data from C++ stream.");
27 return input->gcount();
33 throw XMLException(
"XML reader: Can't read input data from C file.");
39void XMLReader::startTag(
void *data,
const char *element,
const char **attribute) {
41 for (
int i = 0; attribute[i]; i += 2) {
42 state.attributes[attribute[i]] = attribute[i+1];
46void XMLReader::endTag(
void *data,
const char *element) {
54XMLReader::State& XMLReader::appendState(
NodeType type,
const std::string& text) {
55 if (!states.empty() && states.back().type ==
NODE_TEXT) {
57 states.back().text.append(text);
60 if (states.back().hasWhiteText())
67bool XMLReader::readSome() {
76 throw XMLException(
"XML line " +
77 boost::lexical_cast<std::string>(line) +
": parse error: "
84void XMLReader::initParser() {
94 if (((required_types &
result) == 0) ||
107 if (!
msg.empty())
msg +=
" or ";
110 msg +=
"</" + path[path.size()-2] +
">";
112 msg +=
"</" + path.back() +
">";
115 if (!
msg.empty())
msg +=
" or ";
116 msg +=
"content of <" + path.back() +
"> tag";
123#define DEFAULT_PARSERS &XMLReader::strToBool, &parse_complex<double>, &XMLReader::strToUnsigned
149#if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__)
155 read_attributes(
std::move(
to_move.read_attributes)),
156 stringInterpreter(
std::move(
to_move.stringInterpreter)),
157 check_if_all_attributes_were_read(
to_move.check_if_all_attributes_were_read)
162XMLReader &XMLReader::operator=(XMLReader &&
to_move)
181 std::swap(check_if_all_attributes_were_read,
to_swap.check_if_all_attributes_were_read);
185 if (!states.empty()) {
187 if (check_if_all_attributes_were_read && (
getAttributeCount() != read_attributes.size())) {
189 for (
const std::pair<const std::string, std::string>&
a: getCurrent().attributes)
190 if (read_attributes.find(
a.first) == read_attributes.end()) {
191 if (!attr.empty()) attr +=
", ";
196 read_attributes.clear();
202 check_if_all_attributes_were_read =
true;
204 while (!hasCurrent() && readSome())
208 if (getCurrent().type ==
NODE_ELEMENT) path.push_back(getCurrent().text);
218 std::map<std::string, std::string>
parsed;
219 for (
const auto& attr: getCurrent().attributes) {
222 }
catch (
const std::exception&
e) {
223 unsigned line = this->getCurrent().lineNr;
224 throw XMLException(
"XML line " + boost::lexical_cast<std::string>(line) +
225 " in <" + this->getCurrent().text +
"> attribute '" + attr.first +
226 "': Bad parsed expression",
e.what(),
int(line));
231 return getCurrent().attributes;
238 auto iter = states.front().attributes.begin();
239 while (iter != states.front().attributes.end()) {
240 if (iter->first.find(
' ') != std::string::npos)
241 states.front().attributes.erase(iter++);
254 return getCurrent().text;
267 }
catch (
const std::exception&
e) {
268 unsigned line = this->getCurrent().lineNr;
269 throw XMLException(
"XML line " + boost::lexical_cast<std::string>(line) +
270 ": Bad parsed expression",
e.what(),
int(line));
273 return getCurrent().text;
277 auto res_it = this->getCurrent().attributes.find(name);
278 if (
res_it == this->getCurrent().attributes.end())
280 read_attributes.insert(name);
284 }
catch (
const std::exception&
e) {
285 unsigned line = this->getCurrent().lineNr;
286 throw XMLException(
"XML line " + boost::lexical_cast<std::string>(line) +
287 " in <" + this->getCurrent().text +
"> attribute '" + name +
288 "': Bad parsed expression",
e.what(),
int(line));