summaryrefslogtreecommitdiff
path: root/include/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-05 16:31:03 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-08 13:48:57 -0700
commitbaaae99a03202641ae5b8024e57b691fe61a6688 (patch)
tree459045e56197696aa1312594f1e452b03931775d /include/mbgl/style
parente34d8b5c802186008e49364668e4a7bd5668d0fd (diff)
downloadqtlocation-mapboxgl-baaae99a03202641ae5b8024e57b691fe61a6688.tar.gz
[core, android] Factor JSON string conversions
This adds a `convertJSON` template, to be used like: Error error optional<Foo> foo = convertJSON<Foo>(string, error); Internally, it parses the string with RapidJSON and then calls `convert<Foo>(parsed, error)`. While here, rationalize GeoJSON converters and fix error handling for Tileset conversion in OfflineDownload.
Diffstat (limited to 'include/mbgl/style')
-rw-r--r--include/mbgl/style/conversion/geojson.hpp14
-rw-r--r--include/mbgl/style/conversion/source.hpp2
2 files changed, 12 insertions, 4 deletions
diff --git a/include/mbgl/style/conversion/geojson.hpp b/include/mbgl/style/conversion/geojson.hpp
index 6e6e97dbc0..0b594f066c 100644
--- a/include/mbgl/style/conversion/geojson.hpp
+++ b/include/mbgl/style/conversion/geojson.hpp
@@ -1,14 +1,22 @@
#pragma once
#include <mbgl/style/conversion.hpp>
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/util/geojson.hpp>
namespace mbgl {
namespace style {
namespace conversion {
-template <class V>
-optional<GeoJSON> convertGeoJSON(const V& value, Error& error);
+template <>
+struct Converter<GeoJSON> {
+public:
+ optional<GeoJSON> operator()(const std::string&, Error&) const;
+
+ // This is explicitly specialized in the .cpp file for JSValue. It may also be explicitly
+ // specialized for SDK-specific types (e.g. mbgl::android::Value).
+ template <class V>
+ optional<GeoJSON> operator()(const V&, Error&) const;
+};
} // namespace conversion
} // namespace style
diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp
index 2371183b1c..dc7cdc0d42 100644
--- a/include/mbgl/style/conversion/source.hpp
+++ b/include/mbgl/style/conversion/source.hpp
@@ -122,7 +122,7 @@ private:
auto result = std::make_unique<GeoJSONSource>(id, *options);
if (isObject(*dataValue)) {
- optional<GeoJSON> geoJSON = convertGeoJSON(*dataValue, error);
+ optional<GeoJSON> geoJSON = convert<GeoJSON>(*dataValue, error);
if (!geoJSON) {
return {};
}