Skip to content

Commit 4a84bcc

Browse files
committed
Added osmChange JSON parser
1 parent 38b6de1 commit 4a84bcc

24 files changed

+1526
-150
lines changed

include/cgimap/api06/changeset_upload/changeset_input_format.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace api06 {
6060
if (element == "osm")
6161
m_context = context::top;
6262
else
63-
throw xml_error{ "Unknown top-level element, expecting osm" };
63+
throw payload_error{ "Unknown top-level element, expecting osm" };
6464

6565
break;
6666

@@ -70,7 +70,7 @@ namespace api06 {
7070
changeset_element_found = true;
7171
}
7272
else
73-
throw xml_error{ "Unknown element, expecting changeset" };
73+
throw payload_error{ "Unknown element, expecting changeset" };
7474
break;
7575

7676
case context::in_changeset:
@@ -79,7 +79,7 @@ namespace api06 {
7979
add_tag(attrs);
8080
}
8181
else
82-
throw xml_error{ "Unknown element, expecting tag" };
82+
throw payload_error{ "Unknown element, expecting tag" };
8383
break;
8484

8585
case context::in_tag:
@@ -100,7 +100,7 @@ namespace api06 {
100100
assert(element == "osm");
101101
m_context = context::root;
102102
if (!changeset_element_found)
103-
throw xml_error{ "Cannot parse valid changeset from xml string. XML doesn't contain an osm/changeset element" };
103+
throw payload_error{ "Cannot parse valid changeset from xml string. XML doesn't contain an osm/changeset element" };
104104
break;
105105
case context::in_changeset:
106106
assert(element == "changeset");
@@ -116,7 +116,7 @@ namespace api06 {
116116

117117
try {
118118
throw;
119-
} catch (const xml_error& e) {
119+
} catch (const payload_error& e) {
120120
throw_with_context(e, location);
121121
}
122122
}
@@ -128,13 +128,13 @@ namespace api06 {
128128
void add_tag(const std::string &key, const std::string &value) {
129129

130130
if (key.empty())
131-
throw xml_error("Key may not be empty");
131+
throw payload_error("Key may not be empty");
132132

133133
if (unicode_strlen(key) > 255)
134-
throw xml_error("Key has more than 255 unicode characters");
134+
throw payload_error("Key has more than 255 unicode characters");
135135

136136
if (unicode_strlen(value) > 255)
137-
throw xml_error("Value has more than 255 unicode characters");
137+
throw payload_error("Value has more than 255 unicode characters");
138138

139139
m_tags[key] = value;
140140

@@ -166,10 +166,10 @@ namespace api06 {
166166
});
167167

168168
if (!k)
169-
throw xml_error{"Mandatory field k missing in tag element"};
169+
throw payload_error{"Mandatory field k missing in tag element"};
170170

171171
if (!v)
172-
throw xml_error{"Mandatory field v missing in tag element"};
172+
throw payload_error{"Mandatory field v missing in tag element"};
173173

174174
add_tag(*k, *v);
175175
}

include/cgimap/api06/changeset_upload/node.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Node : public OSMObject {
3636
try {
3737
_lat = std::stod(lat);
3838
} catch (std::invalid_argument &e) {
39-
throw xml_error("Latitude is not numeric");
39+
throw payload_error("Latitude is not numeric");
4040
} catch (std::out_of_range &e) {
41-
throw xml_error("Latitude value is too large");
41+
throw payload_error("Latitude value is too large");
4242
}
4343

4444
set_lat(_lat);
@@ -51,27 +51,27 @@ class Node : public OSMObject {
5151
try {
5252
_lon = std::stod(lon);
5353
} catch (std::invalid_argument &e) {
54-
throw xml_error("Longitude is not numeric");
54+
throw payload_error("Longitude is not numeric");
5555
} catch (std::out_of_range &e) {
56-
throw xml_error("Longitude value is too large");
56+
throw payload_error("Longitude value is too large");
5757
}
5858

5959
set_lon(_lon);
6060
}
6161

6262
void set_lat(double lat) {
6363
if (lat < -90 || lat > 90)
64-
throw xml_error("Latitude outside of valid range");
64+
throw payload_error("Latitude outside of valid range");
6565
else if (!std::isfinite(lat))
66-
throw xml_error("Latitude not a valid finite number");
66+
throw payload_error("Latitude not a valid finite number");
6767
m_lat = lat;
6868
}
6969

7070
void set_lon(double lon) {
7171
if (lon < -180 || lon > 180)
72-
throw xml_error("Longitude outside of valid range");
72+
throw payload_error("Longitude outside of valid range");
7373
else if (!std::isfinite(lon))
74-
throw xml_error("Longitude not a valid finite number");
74+
throw payload_error("Longitude not a valid finite number");
7575
m_lon = lon;
7676
}
7777

@@ -86,7 +86,13 @@ class Node : public OSMObject {
8686
}
8787
}
8888

89-
std::string get_type_name() override { return "Node"; }
89+
std::string get_type_name() const override { return "Node"; }
90+
91+
bool operator==(const Node &o) const {
92+
return (OSMObject::operator==(o) &&
93+
o.m_lat == m_lat &&
94+
o.m_lon == m_lon);
95+
}
9096

9197
private:
9298
std::optional<double> m_lat;

0 commit comments

Comments
 (0)