blob: 294dbaf5520809976e34d67661e7d1ffcfc42fa6 (
plain)
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
|
#include "xml_element.hpp"
#include "../coding/parse_xml.hpp"
#include "../coding/reader.hpp"
#include "../std/cstdio.hpp"
#include "../std/algorithm.hpp"
bool BaseOSMParser::is_our_tag(string const & name)
{
return (find(m_tags.begin(), m_tags.end(), name) != m_tags.end());
}
bool BaseOSMParser::Push(string const & name)
{
if (!is_our_tag(name) && (m_depth != 2))
return false;
++m_depth;
if (m_depth == 1)
{
m_current = 0;
}
else if (m_depth == 2)
{
m_current = &m_element;
m_current->parent = 0;
}
else
{
m_current->childs.push_back(XMLElement());
m_current->childs.back().parent = m_current;
m_current = &m_current->childs.back();
}
if (m_depth >= 2)
m_current->name = name;
return true;
}
void BaseOSMParser::AddAttr(string const & name, string const & value)
{
if (m_current)
m_current->attrs[name] = value;
}
void BaseOSMParser::Pop(string const &)
{
--m_depth;
if (m_depth >= 2)
m_current = m_current->parent;
else if (m_depth == 1)
{
EmitElement(m_current);
m_current->Clear();
}
}
struct StdinReader
{
size_t Read(char * buffer, size_t bufferSize)
{
return fread(buffer, sizeof(char), bufferSize, stdin);
}
};
void ParseXMLFromStdIn(BaseOSMParser & parser)
{
StdinReader reader;
ParseXML(reader, parser);
}
void ParseXMLFromFile(FileReader const & reader, BaseOSMParser & parser)
{
ReaderSource<FileReader> src(reader);
ParseXML(src, parser);
}
|