summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-07 17:00:53 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-23 13:31:13 -0700
commitd7227e13a7a87cf50a4c8c1f0615fc565f5a2679 (patch)
treeeda76a2da3220f3cfeec901400369cf9c8361f58 /src/mbgl
parent1c757cce34344dfecc9a724034680225143f92b7 (diff)
downloadqtlocation-mapboxgl-d7227e13a7a87cf50a4c8c1f0615fc565f5a2679.tar.gz
[all] Replace Result<T> with optional<T> plus out Error parameter
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/style/parser.cpp22
-rw-r--r--src/mbgl/style/property_parsing.cpp29
-rw-r--r--src/mbgl/style/property_parsing.hpp26
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp10
-rw-r--r--src/mbgl/style/tile_source_impl.cpp5
5 files changed, 21 insertions, 71 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 926c243733..d970d8bbc0 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -116,10 +116,11 @@ void Parser::parseSources(const JSValue& value) {
for (const auto& property : value.GetObject()) {
std::string id = *conversion::toString(property.name);
- conversion::Result<std::unique_ptr<Source>> source =
- conversion::convert<std::unique_ptr<Source>>(property.value, id);
+ conversion::Error error;
+ optional<std::unique_ptr<Source>> source =
+ conversion::convert<std::unique_ptr<Source>>(property.value, error, id);
if (!source) {
- Log::Warning(Event::ParseStyle, source.error().message);
+ Log::Warning(Event::ParseStyle, error.message);
continue;
}
@@ -222,9 +223,10 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
layer = reference->baseImpl->cloneRef(id);
conversion::setPaintProperties(*layer, value);
} else {
- conversion::Result<std::unique_ptr<Layer>> converted = conversion::convert<std::unique_ptr<Layer>>(value);
+ conversion::Error error;
+ optional<std::unique_ptr<Layer>> converted = conversion::convert<std::unique_ptr<Layer>>(value, error);
if (!converted) {
- Log::Warning(Event::ParseStyle, converted.error().message);
+ Log::Warning(Event::ParseStyle, error.message);
return;
}
layer = std::move(*converted);
@@ -232,20 +234,20 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
}
std::vector<FontStack> Parser::fontStacks() const {
- std::set<FontStack> result;
+ std::set<FontStack> optional;
for (const auto& layer : layers) {
if (layer->is<SymbolLayer>()) {
PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont();
if (textFont.isUndefined()) {
- result.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
+ optional.insert({"Open Sans Regular", "Arial Unicode MS Regular"});
} else if (textFont.isConstant()) {
- result.insert(textFont.asConstant());
+ optional.insert(textFont.asConstant());
} else if (textFont.isCameraFunction()) {
textFont.asCameraFunction().stops.match(
[&] (const auto& stops) {
for (const auto& stop : stops.stops) {
- result.insert(stop.second);
+ optional.insert(stop.second);
}
}
);
@@ -253,7 +255,7 @@ std::vector<FontStack> Parser::fontStacks() const {
}
}
- return std::vector<FontStack>(result.begin(), result.end());
+ return std::vector<FontStack>(optional.begin(), optional.end());
}
} // namespace style
diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp
deleted file mode 100644
index 16ce0f4adc..0000000000
--- a/src/mbgl/style/property_parsing.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <mbgl/style/property_parsing.hpp>
-
-namespace mbgl {
-namespace style {
-
-optional<TransitionOptions> parseTransitionOptions(const char *, const JSValue& value) {
- if (!value.IsObject()) {
- return {};
- }
-
- optional<Duration> duration;
- if (value.HasMember("duration") && value["duration"].IsNumber()) {
- duration.emplace(Milliseconds(value["duration"].GetUint()));
- }
-
- optional<Duration> delay;
- if (value.HasMember("delay") && value["delay"].IsNumber()) {
- delay.emplace(Milliseconds(value["delay"].GetUint()));
- }
-
- if (!duration && !delay) {
- return {};
- }
-
- return TransitionOptions { duration, delay };
-}
-
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp
deleted file mode 100644
index b542c8ae47..0000000000
--- a/src/mbgl/style/property_parsing.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include <mbgl/style/property_value.hpp>
-#include <mbgl/style/transition_options.hpp>
-#include <mbgl/style/rapidjson_conversion.hpp>
-#include <mbgl/style/conversion/property_value.hpp>
-
-#include <mbgl/util/logging.hpp>
-
-namespace mbgl {
-namespace style {
-
-template <typename T>
-PropertyValue<T> parseProperty(const char* name, const JSValue& value) {
- conversion::Result<PropertyValue<T>> result = conversion::convert<PropertyValue<T>>(value);
- if (!result) {
- Log::Warning(Event::ParseStyle, "%s: %s", name, result.error().message);
- return {};
- }
- return *result;
-}
-
-optional<TransitionOptions> parseTransitionOptions(const char * name, const JSValue&);
-
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index b050e5482e..6431d5faa4 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -21,11 +21,12 @@ namespace style {
namespace conversion {
template <>
-Result<GeoJSON> convertGeoJSON(const JSValue& value) {
+optional<GeoJSON> convertGeoJSON(const JSValue& value, Error& error) {
try {
return mapbox::geojson::convert(value);
} catch (const std::exception& ex) {
- return Error{ ex.what() };
+ error = { ex.what() };
+ return {};
}
}
} // namespace conversion
@@ -136,10 +137,11 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) {
invalidateTiles();
- conversion::Result<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d);
+ conversion::Error error;
+ optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
if (!geoJSON) {
Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s",
- geoJSON.error().message.c_str());
+ error.message.c_str());
// Create an empty GeoJSON VT object to make sure we're not infinitely waiting for
// tiles to load.
_setGeoJSON(GeoJSON{ FeatureCollection{} });
diff --git a/src/mbgl/style/tile_source_impl.cpp b/src/mbgl/style/tile_source_impl.cpp
index daa6389a8e..9ea596d38b 100644
--- a/src/mbgl/style/tile_source_impl.cpp
+++ b/src/mbgl/style/tile_source_impl.cpp
@@ -24,9 +24,10 @@ Tileset TileSourceImpl::parseTileJSON(const std::string& json, const std::string
throw std::runtime_error(message.str());
}
- conversion::Result<Tileset> result = conversion::convert<Tileset, JSValue>(document);
+ conversion::Error error;
+ optional<Tileset> result = conversion::convert<Tileset, JSValue>(document, error);
if (!result) {
- throw std::runtime_error(result.error().message);
+ throw std::runtime_error(error.message);
}
// TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with.