summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-22 12:31:49 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-24 09:39:15 -0700
commit089c4e413fbe80711ebd874520d3b8fdcb997112 (patch)
treea8088b0ed6cbd36b5cadf247a6e0fc524b6c3a3d /src
parentcb6a519f7c1e59b584b84039ebf4803c1d7eee71 (diff)
downloadqtlocation-mapboxgl-089c4e413fbe80711ebd874520d3b8fdcb997112.tar.gz
[core] Split up and clean up conversion.hpp
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion.cpp25
-rw-r--r--src/mbgl/style/parser.cpp9
-rw-r--r--src/mbgl/style/property_parsing.hpp10
3 files changed, 10 insertions, 34 deletions
diff --git a/src/mbgl/style/conversion.cpp b/src/mbgl/style/conversion.cpp
deleted file mode 100644
index e863e285c4..0000000000
--- a/src/mbgl/style/conversion.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <mbgl/style/conversion.hpp>
-
-namespace mbgl {
-namespace style {
-namespace conversion {
-
-Result<Value> normalizeFilterValue(const std::string& key, const optional<Value>& value) {
- if (!value) {
- return Error { "filter expression value must be a boolean, number, or string" };
- } else if (key != "$type") {
- return *value;
- } else if (*value == std::string("Point")) {
- return Value(uint64_t(FeatureType::Point));
- } else if (*value == std::string("LineString")) {
- return Value(uint64_t(FeatureType::LineString));
- } else if (*value == std::string("Polygon")) {
- return Value(uint64_t(FeatureType::Polygon));
- } else {
- return Error { "value for $type filter must be Point, LineString, or Polygon" };
- }
-}
-
-} // namespace conversion
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index eddda5d3f2..bbe2fd7862 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -11,6 +11,7 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/filter.hpp>
#include <mbgl/platform/log.hpp>
@@ -277,11 +278,11 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique
}
if (value.HasMember("filter")) {
- conversion::Result<Filter> filter = conversion::convertFilter(value["filter"]);
- if (filter.is<Filter>()) {
- impl->filter = filter.get<Filter>();
+ conversion::Result<Filter> filter = conversion::convert<Filter>(value["filter"]);
+ if (filter) {
+ impl->filter = *filter;
} else {
- Log::Warning(Event::ParseStyle, filter.get<conversion::Error>().message);
+ Log::Warning(Event::ParseStyle, filter.error().message);
}
}
diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp
index 0c750ca298..8c2bd2c0f4 100644
--- a/src/mbgl/style/property_parsing.hpp
+++ b/src/mbgl/style/property_parsing.hpp
@@ -3,7 +3,7 @@
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
-#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/platform/log.hpp>
@@ -12,12 +12,12 @@ namespace style {
template <typename T>
PropertyValue<T> parseProperty(const char* name, const JSValue& value) {
- conversion::Result<PropertyValue<T>> result = conversion::convertPropertyValue<T>(value);
- if (result.template is<conversion::Error>()) {
- Log::Warning(Event::ParseStyle, "%s: %s", name, result.template get<conversion::Error>().message);
+ 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.template get<PropertyValue<T>>();
+ return *result;
}
optional<TransitionOptions> parseTransitionOptions(const char * name, const JSValue&);