[core] Split up and clean up conversion.hpp
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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&);
|
||||
|
||||
Reference in New Issue
Block a user