source: subversion/applications/lib/libosm/Parser.h @ 34393

Last change on this file since 34393 was 17744, checked in by nienhueser, 10 years ago

Verbose error message on parsing errors. Make sure error string is reset it parsing succeeds.

File size: 1.1 KB
Line 
1#include "Object.h"
2#include "Components.h"
3
4#include <expat.h>
5
6#include <cstdio>
7#include <cstdlib>
8#include <iostream>
9#include <string>
10
11namespace OSM
12{
13
14/**
15 * Xml parser for OSM
16 */
17class Parser
18{
19public:
20        /**
21         * Parses xml provided by the given stream and returns the OSM components contained
22         * @param stream Input stream containing OSM xml (e.g. read from an OSM server or a local file)
23         * @return The OSM components contained in the stream, or NULL if the stream cannot be parsed
24         * @sa getError
25         */
26        static Components* parse(std::istream &stream);
27
28        /**
29         * @return An empty string if no error occurred in the last parse call,
30         * or a description of the error otherwise
31         */
32        static std::string getError();
33
34private:
35        static void startElement(void *d, const XML_Char* name,
36                        const XML_Char** attrs);
37        static void endElement(void *d, const XML_Char* name);
38        static void characters(void*, const XML_Char* txt, int txtlen);
39
40        static Object *curObject;
41        static int curID;
42        static bool inNode, inWay;
43        static Components* components;
44        static std::string error;
45};
46
47}
Note: See TracBrowser for help on using the repository browser.