20
20
21
21
#include < sqlite3.h>
22
22
23
- #include < iostream>
24
- using namespace std ;
25
23
26
24
/* *
27
- * XML SAX handler -> while processing XML file,
28
- * stores data to specified sqlite database
25
+ * The SAX handler used for parsing input OSM XML file.
26
+ * While processing XML file it stores data to specified sqlite database.
29
27
*/
30
28
class OsmHandler : public QXmlDefaultHandler
31
29
{
32
30
public:
33
- // member variables
31
+ /* *
32
+ * Construction.
33
+ * @param f input file with OSM data
34
+ * @param database opened sqlite3 database with OSM db schema to store data in
35
+ */
36
+ OsmHandler ( QFile *f, sqlite3 *database );
34
37
35
- QFile mFile ;
36
- sqlite3 *mDatabase ;
37
- int mCnt ;
38
+ /* *
39
+ * Destruction.
40
+ */
41
+ ~OsmHandler ();
38
42
39
- int mFileSize ;
40
- QString mError ;
41
- // xml processing information
42
- QString mObjectId ; // last node, way or relation id while parsing file
43
- QString mObjectType ; // one of strings "node", "way", "relation"
44
- QString mRelationType ;
45
- float mLat ;
46
- float mLon ;
47
- double xMin, xMax, yMin, yMax;
43
+ // input OSM XML processing
48
44
49
- int mPointCnt ;
50
- int mLineCnt ;
51
- int mPolygonCnt ;
45
+ /* *
46
+ * Function is called after XML processing is started.
47
+ * @return True if start of document signal is processed without problems; False otherwise
48
+ */
49
+ bool startDocument ();
52
50
53
- int mCurrent_way_id ;
54
- int mPosId ;
55
- QString firstWayMemberId;
56
- QString lastWayMemberId;
57
- int mFirstMemberAppeared ;
51
+ /* *
52
+ * The reader of OSM file calls this function when it has parsed a start element tag.
53
+ * If this function returns false the reader stops parsing and reports an error.
54
+ * The reader uses the function errorString() to get the error message.
55
+ *
56
+ * @param pUri namespace URI of element, or an empty string if the element has no namespace URI or if no namespace processing is done
57
+ * @param pLocalName local name of element (without prefix), or an empty string if no namespace processing is done
58
+ * @param pName qualified name of element (with prefix)
59
+ * @param pAttrs attributes attached to the element; if there are no attributes, atts is an empty attributes object.
60
+ * @return True if start of element signal is processed without problems; False otherwise
61
+ */
62
+ bool startElement ( const QString & pUri, const QString & pLocalName, const QString & pName, const QXmlAttributes & pAttrs );
58
63
59
- // functions
64
+ /* *
65
+ * The reader calls this function when it has parsed an end element tag with the qualified name pName,
66
+ * the local name pLocalName and the namespace URI pURI.
67
+ * If this function returns false the reader stops parsing and reports an error.
68
+ * The reader uses the function errorString() to get the error message.
69
+ *
70
+ * @param pUri namespace URI of element, or an empty string if the element has no namespace URI or if no namespace processing is done
71
+ * @param pLocalName local name of element (without prefix), or an empty string if no namespace processing is done
72
+ * @param pName qualified name of element (with prefix)
73
+ * @return True if end of element signal is processed without problems; False otherwise
74
+ */
75
+ bool endElement ( const QString & pURI, const QString & pLocalName, const QString & pName );
60
76
61
- // object construction
62
- OsmHandler ( QFile *f, sqlite3 *database );
63
- ~OsmHandler ();
64
- // xml processing
77
+ /* *
78
+ * Function is called after end of document is reached while XML processing.
79
+ * @return True if end of document signal is processed without problems; False otherwise
80
+ */
81
+ bool endDocument ();
65
82
66
- bool startDocument ();
83
+ /* *
84
+ * Returns information on error that occures while parsing.
85
+ * @return info on error that occures while parsing
86
+ */
67
87
QString errorString ();
68
- bool startElement ( const QString & pUri, const QString & pLocalName, const QString & pName, const QXmlAttributes & pAttrs );
69
- bool endElement ( const QString & pURI, const QString & pLocalName, const QString & pName );
70
- bool endDocument ();
88
+
89
+ public:
90
+ int mPointCnt ;
91
+ int mLineCnt ;
92
+ int mPolygonCnt ;
93
+ double xMin, xMax, yMin, yMax;
71
94
72
95
private:
73
96
sqlite3_stmt *mStmtInsertNode ;
@@ -78,6 +101,17 @@ class OsmHandler: public QXmlDefaultHandler
78
101
sqlite3_stmt *mStmtInsertRelationMember ;
79
102
sqlite3_stmt *mStmtUpdateNode ;
80
103
sqlite3_stmt *mStmtInsertVersion ;
104
+
105
+ sqlite3 *mDatabase ;
106
+ int mPosId ;
107
+ QString firstWayMemberId;
108
+ QString lastWayMemberId;
109
+ int mFirstMemberAppeared ;
110
+ int mCnt ;
111
+ QString mError ;
112
+ QString mObjectId ; // last node, way or relation id while parsing file
113
+ QString mObjectType ; // one of "node", "way", "relation"
114
+ QString mRelationType ;
81
115
};
82
116
83
117
0 commit comments