[core] Internalize rapidjson.hpp
This commit is contained in:
committed by
Konstantin Käfer
parent
321d820a87
commit
9b39013ce4
@@ -302,6 +302,7 @@ set(MBGL_CORE_FILES
|
||||
include/mbgl/style/conversion/source.hpp
|
||||
include/mbgl/style/conversion/tileset.hpp
|
||||
include/mbgl/style/conversion/transition_options.hpp
|
||||
src/mbgl/style/conversion/geojson.cpp
|
||||
src/mbgl/style/conversion/stringify.hpp
|
||||
|
||||
# style/function
|
||||
|
||||
@@ -5,45 +5,23 @@
|
||||
#include <mapbox/geojson.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
template <>
|
||||
optional<GeoJSON> convertGeoJSON(const mbgl::android::Value& value, Error& error) {
|
||||
|
||||
// Value should be a string wrapped in an object
|
||||
mbgl::android::Value jsonValue = value.get("data");
|
||||
if(value.isNull()) {
|
||||
error = { "no json data found" };
|
||||
return {};
|
||||
}
|
||||
std::string jsonString = value.get("data").toString();
|
||||
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
|
||||
d.Parse(jsonString.c_str());
|
||||
|
||||
if (d.HasParseError()) {
|
||||
std::stringstream message;
|
||||
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
|
||||
error = { message.str() };
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
|
||||
if (!geoJSON) {
|
||||
error = { error.message };
|
||||
return {};
|
||||
}
|
||||
|
||||
return geoJSON;
|
||||
return convertGeoJSON(value.get("data").toString(), error);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <mapbox/geojson.hpp>
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
|
||||
#include <QMapbox>
|
||||
|
||||
@@ -10,7 +9,6 @@
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace QMapbox {
|
||||
@@ -197,29 +195,8 @@ optional<GeoJSON> convertGeoJSON(const QVariant& value, Error& error) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto data = value.toByteArray();
|
||||
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
|
||||
if (data.endsWith(char(0))) {
|
||||
d.Parse<0>(value.toByteArray().data());
|
||||
} else {
|
||||
d.Parse<0>(value.toByteArray().constData());
|
||||
}
|
||||
|
||||
if (d.HasParseError()) {
|
||||
std::stringstream message;
|
||||
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
|
||||
error = { message.str() };
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<GeoJSON> geoJSON = convertGeoJSON<JSValue>(d, error);
|
||||
if (!geoJSON) {
|
||||
error = { error.message };
|
||||
return {};
|
||||
}
|
||||
|
||||
return geoJSON;
|
||||
QByteArray data = value.toByteArray();
|
||||
return convertGeoJSON(std::string(data.constData(), data.size()), error);
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
|
||||
35
src/mbgl/style/conversion/geojson.cpp
Normal file
35
src/mbgl/style/conversion/geojson.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
template <>
|
||||
optional<GeoJSON> convertGeoJSON(const std::string& string, Error& error) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
|
||||
d.Parse(string.c_str());
|
||||
|
||||
if (d.HasParseError()) {
|
||||
std::stringstream message;
|
||||
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
|
||||
error = { message.str() };
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
|
||||
if (!geoJSON) {
|
||||
error = { error.message };
|
||||
return {};
|
||||
}
|
||||
|
||||
return geoJSON;
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user