diff options
Diffstat (limited to 'platform/android/src/style/conversion')
15 files changed, 124 insertions, 586 deletions
diff --git a/platform/android/src/style/conversion/filter.cpp b/platform/android/src/style/conversion/filter.cpp new file mode 100644 index 0000000000..4eac0cf82b --- /dev/null +++ b/platform/android/src/style/conversion/filter.cpp @@ -0,0 +1,26 @@ +#include "filter.hpp" +#include "../android_conversion.hpp" + +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/filter.hpp> + +namespace mbgl { +namespace android { +namespace conversion { + +optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { + mbgl::optional<mbgl::style::Filter> filter; + if (jfilter) { + mbgl::style::conversion::Error error; + auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(Value(env, jfilter), error); + if (!converted) { + mbgl::Log::Error(mbgl::Event::JNI, "Error converting filter: " + error.message); + } + filter = std::move(*converted); + } + return filter; +} + +} // namespace conversion +} // namespace android +} // namespace mbgl
\ No newline at end of file diff --git a/platform/android/src/style/conversion/filter.hpp b/platform/android/src/style/conversion/filter.hpp index c154e88e7c..df482de8f3 100644 --- a/platform/android/src/style/conversion/filter.hpp +++ b/platform/android/src/style/conversion/filter.hpp @@ -1,30 +1,15 @@ #pragma once -#include "../android_conversion.hpp" -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/filter.hpp> +#include <mbgl/style/filter.hpp> +#include <mbgl/util/optional.hpp> #include <jni/jni.hpp> -#include <tuple> -#include <map> - namespace mbgl { namespace android { namespace conversion { -inline optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { - mbgl::optional<mbgl::style::Filter> filter; - if (jfilter) { - mbgl::style::conversion::Error error; - auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(Value(env, jfilter), error); - if (!converted) { - mbgl::Log::Error(mbgl::Event::JNI, "Error converting filter: " + error.message); - } - filter = std::move(*converted); - } - return filter; -} +optional<mbgl::style::Filter> toFilter(jni::JNIEnv&, jni::Array<jni::Object<>>); } // namespace conversion } // namespace android diff --git a/platform/android/src/style/conversion/latlngquad.hpp b/platform/android/src/style/conversion/latlngquad.hpp deleted file mode 100644 index 9d1a83e164..0000000000 --- a/platform/android/src/style/conversion/latlngquad.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mapbox/geojson.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/geojson.hpp> -#include <jni/jni.hpp> - -namespace mbgl { -namespace style { -namespace conversion { - -template <> -optional<std::array<LatLng, 4>> Converter<std::array<LatLng, 4>>::operator()(const mbgl::android::Value& value, Error& error) const { - if (value.isNull() || !value.isArray()) { - error = { "value cannot be converted to LatLng array" }; - return {}; - } - - return convert<GeoJSON>(value.toString(), error); -} - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/platform/android/src/style/conversion/position.cpp b/platform/android/src/style/conversion/position.cpp new file mode 100644 index 0000000000..9b3925914e --- /dev/null +++ b/platform/android/src/style/conversion/position.cpp @@ -0,0 +1,24 @@ +#include "position.hpp" + +namespace mbgl { +namespace android { +namespace conversion { + +Result<jni::Object<Position>> Converter<jni::Object<Position>, mbgl::style::Position>::operator()(jni::JNIEnv &env, const mbgl::style::Position &value) const { + std::array<float, 3> cartPosition = value.getSpherical(); + return Position::fromPosition(env, cartPosition[0], cartPosition[1], cartPosition[2]); +} + +Result<mbgl::style::Position> Converter<mbgl::style::Position, jni::Object<Position>>::operator()(jni::JNIEnv &env, const jni::Object<Position> &value) const { + float radialCoordinate = Position::getRadialCoordinate(env, value); + float azimuthalAngle = Position::getAzimuthalAngle(env, value); + float polarAngle = Position::getPolarAngle(env, value); + std::array<float, 3> cartPosition {{radialCoordinate, azimuthalAngle, polarAngle}}; + mbgl::style::Position position{}; + position.set(cartPosition); + return position; +} + +} +} +} diff --git a/platform/android/src/style/conversion/position.hpp b/platform/android/src/style/conversion/position.hpp index f32a892c0c..2ef4bf4395 100644 --- a/platform/android/src/style/conversion/position.hpp +++ b/platform/android/src/style/conversion/position.hpp @@ -1,37 +1,25 @@ #pragma once #include "../../conversion/conversion.hpp" +#include "../position.hpp" -#include <jni/jni.hpp> #include <mbgl/style/position.hpp> -#include "../../jni/local_object.hpp" -#include "../position.hpp" +#include <jni/jni.hpp> namespace mbgl { namespace android { namespace conversion { -template<> +template <> struct Converter<jni::Object<Position>, mbgl::style::Position> { - Result<jni::Object<Position>> operator()(jni::JNIEnv &env, const mbgl::style::Position &value) const { - std::array<float, 3> cartPosition = value.getSpherical(); - return Position::fromPosition(env, cartPosition[0], cartPosition[1], cartPosition[2]); - } + Result<jni::Object<Position>> operator()(jni::JNIEnv &env, const mbgl::style::Position &value) const; }; -template<> +template <> struct Converter<mbgl::style::Position, jni::Object<Position>> { - Result<mbgl::style::Position> operator()(jni::JNIEnv &env, const jni::Object<Position> &value) const { - float radialCoordinate = Position::getRadialCoordinate(env, value); - float azimuthalAngle = Position::getAzimuthalAngle(env, value); - float polarAngle = Position::getPolarAngle(env, value); - std::array<float, 3> cartPosition {{radialCoordinate, azimuthalAngle, polarAngle}}; - mbgl::style::Position position{}; - position.set(cartPosition); - return position; - } + Result<mbgl::style::Position> operator()(jni::JNIEnv &env, const jni::Object<Position> &value) const; }; } } -}
\ No newline at end of file +} diff --git a/platform/android/src/style/conversion/property_expression.hpp b/platform/android/src/style/conversion/property_expression.hpp index ae9d4ea41c..08429960cb 100644 --- a/platform/android/src/style/conversion/property_expression.hpp +++ b/platform/android/src/style/conversion/property_expression.hpp @@ -1,16 +1,11 @@ #pragma once -#include <mbgl/style/property_value.hpp> #include "../../conversion/conversion.hpp" -#include "../../conversion/constant.hpp" -#include "types.hpp" -#include "../../java/lang.hpp" - -#include <jni/jni.hpp> #include "../../gson/json_element.hpp" -#include <tuple> -#include <map> +#include <mbgl/style/property_expression.hpp> + +#include <jni/jni.hpp> namespace mbgl { namespace android { @@ -18,11 +13,8 @@ namespace conversion { template <class T> struct Converter<jni::Object<android::gson::JsonElement>, mbgl::style::PropertyExpression<T>> { - Result<jni::Object<android::gson::JsonElement>> operator()(jni::JNIEnv& env, const mbgl::style::PropertyExpression<T>& value) const { - // Convert expressions - mbgl::Value expressionValue = value.getExpression().serialize(); - return gson::JsonElement::New(env, expressionValue); + return gson::JsonElement::New(env, value.getExpression().serialize()); } }; diff --git a/platform/android/src/style/conversion/property_value.hpp b/platform/android/src/style/conversion/property_value.hpp index 256647cddf..8150285c85 100644 --- a/platform/android/src/style/conversion/property_value.hpp +++ b/platform/android/src/style/conversion/property_value.hpp @@ -2,10 +2,10 @@ #include <mbgl/style/color_ramp_property_value.hpp> #include <mbgl/style/property_value.hpp> + #include "../../conversion/conversion.hpp" #include "../../conversion/constant.hpp" #include "property_expression.hpp" -#include "types.hpp" namespace mbgl { namespace android { @@ -17,25 +17,22 @@ namespace conversion { template <typename T> class PropertyValueEvaluator { public: - PropertyValueEvaluator(jni::JNIEnv& _env) : env(_env) {} jni::jobject* operator()(const mbgl::style::Undefined) const { return nullptr; } - jni::jobject* operator()(const T &value) const { - Result<jni::jobject*> result = convert<jni::jobject*>(env, value); - return *result; + jni::jobject* operator()(const T& value) const { + return *convert<jni::jobject*>(env, value); } - jni::jobject* operator()(const mbgl::style::PropertyExpression<T> &value) const { - return *convert<jni::Object<android::gson::JsonElement>, mbgl::style::PropertyExpression<T>>(env, value); + jni::jobject* operator()(const mbgl::style::PropertyExpression<T>& value) const { + return *convert<jni::Object<android::gson::JsonElement>>(env, value); } private: jni::JNIEnv& env; - }; /** @@ -43,7 +40,6 @@ private: */ template <class T> struct Converter<jni::jobject*, mbgl::style::PropertyValue<T>> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::PropertyValue<T>& value) const { PropertyValueEvaluator<T> evaluator(env); return value.evaluate(evaluator); @@ -55,8 +51,7 @@ struct Converter<jni::jobject*, mbgl::style::PropertyValue<T>> { */ template <> struct Converter<jni::jobject*, mbgl::style::ColorRampPropertyValue> { - - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::ColorRampPropertyValue value) const { + Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::ColorRampPropertyValue& value) const { PropertyValueEvaluator<mbgl::style::ColorRampPropertyValue> evaluator(env); return *convert<jni::jobject*>(env, value.evaluate(evaluator)); } diff --git a/platform/android/src/style/conversion/transition_options.cpp b/platform/android/src/style/conversion/transition_options.cpp new file mode 100644 index 0000000000..313333ad17 --- /dev/null +++ b/platform/android/src/style/conversion/transition_options.cpp @@ -0,0 +1,16 @@ +#include "transition_options.hpp" + +namespace mbgl { +namespace android { +namespace conversion { + +Result<jni::Object<TransitionOptions>> Converter<jni::Object<TransitionOptions>, mbgl::style::TransitionOptions>::operator()(jni::JNIEnv& env, const mbgl::style::TransitionOptions& value) const { + return TransitionOptions::fromTransitionOptions(env, + std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())).count(), + std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())).count() + ); +} + +} +} +} diff --git a/platform/android/src/style/conversion/transition_options.hpp b/platform/android/src/style/conversion/transition_options.hpp index ae65a32194..6630456d37 100644 --- a/platform/android/src/style/conversion/transition_options.hpp +++ b/platform/android/src/style/conversion/transition_options.hpp @@ -1,11 +1,11 @@ #pragma once #include "../../conversion/conversion.hpp" +#include "../transition_options.hpp" -#include <jni/jni.hpp> #include <mbgl/style/transition_options.hpp> -#include "../../jni/local_object.hpp" -#include "../transition_options.hpp" + +#include <jni/jni.hpp> namespace mbgl { namespace android { @@ -13,18 +13,9 @@ namespace conversion { template<> struct Converter<jni::Object<TransitionOptions>, mbgl::style::TransitionOptions> { - Result<jni::Object<TransitionOptions>> operator()(jni::JNIEnv &env, const mbgl::style::TransitionOptions &value) const { - - // Convert duration - jlong duration = std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())).count(); - // Convert delay - jlong delay = std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())).count(); - - // Create transition options - return TransitionOptions::fromTransitionOptions(env, duration, delay); - } + Result<jni::Object<TransitionOptions>> operator()(jni::JNIEnv&, const mbgl::style::TransitionOptions&) const; }; } } -}
\ No newline at end of file +} diff --git a/platform/android/src/style/conversion/types.hpp b/platform/android/src/style/conversion/types.hpp deleted file mode 100644 index e87782fad0..0000000000 --- a/platform/android/src/style/conversion/types.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. -#pragma once - -#include "types_string_values.hpp" -#include "../../conversion/conversion.hpp" -#include "../../conversion/constant.hpp" - -#include <mbgl/style/types.hpp> -#include <mbgl/util/optional.hpp> -#include <jni/jni.hpp> - -#include <string> - -namespace mbgl { -namespace android { -namespace conversion { - -template <> -struct Converter<jni::jobject*, mbgl::style::VisibilityType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::VisibilityType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::LineCapType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::LineCapType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::LineJoinType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::LineJoinType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::SymbolPlacementType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::SymbolPlacementType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::AlignmentType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::AlignmentType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::IconTextFitType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::IconTextFitType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::SymbolAnchorType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::SymbolAnchorType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::TextJustifyType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::TextJustifyType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::TextTransformType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::TextTransformType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::TranslateAnchorType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::TranslateAnchorType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::CirclePitchScaleType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CirclePitchScaleType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::RasterResamplingType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::RasterResamplingType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::HillshadeIlluminationAnchorType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::HillshadeIlluminationAnchorType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -template <> -struct Converter<jni::jobject*, mbgl::style::LightAnchorType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::LightAnchorType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - - -} // namespace conversion -} // namespace android -} // namespace mbgl diff --git a/platform/android/src/style/conversion/types.hpp.ejs b/platform/android/src/style/conversion/types.hpp.ejs deleted file mode 100644 index 3cd4764015..0000000000 --- a/platform/android/src/style/conversion/types.hpp.ejs +++ /dev/null @@ -1,40 +0,0 @@ -<% - const properties = locals.properties; --%> -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. -#pragma once - -#include "types_string_values.hpp" -#include "../../conversion/conversion.hpp" -#include "../../conversion/constant.hpp" - -#include <mbgl/style/types.hpp> -#include <mbgl/util/optional.hpp> -#include <jni/jni.hpp> - -#include <string> - -namespace mbgl { -namespace android { -namespace conversion { - -template <> -struct Converter<jni::jobject*, mbgl::style::VisibilityType> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::VisibilityType& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -<% for (const property of properties) { -%> -template <> -struct Converter<jni::jobject*, mbgl::style::<%- propertyNativeType(property) %>> { - Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::<%- propertyNativeType(property) %>& value) const { - return convert<jni::jobject*, std::string>(env, toString(value)); - } -}; - -<% } -%> - -} // namespace conversion -} // namespace android -} // namespace mbgl diff --git a/platform/android/src/style/conversion/types_string_values.hpp b/platform/android/src/style/conversion/types_string_values.hpp deleted file mode 100644 index 9f6696d181..0000000000 --- a/platform/android/src/style/conversion/types_string_values.hpp +++ /dev/null @@ -1,257 +0,0 @@ -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. -#pragma once - -#include <mbgl/style/types.hpp> - -#include <string> -#include <stdexcept> - -namespace mbgl { -namespace android { -namespace conversion { - - // visibility - inline std::string toString(mbgl::style::VisibilityType value) { - switch (value) { - case mbgl::style::VisibilityType::Visible: - return "visible"; - break; - case mbgl::style::VisibilityType::None: - return "none"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // line-cap - inline std::string toString(mbgl::style::LineCapType value) { - switch (value) { - case mbgl::style::LineCapType::Butt: - return "butt"; - break; - case mbgl::style::LineCapType::Round: - return "round"; - break; - case mbgl::style::LineCapType::Square: - return "square"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // line-join - inline std::string toString(mbgl::style::LineJoinType value) { - switch (value) { - case mbgl::style::LineJoinType::Bevel: - return "bevel"; - break; - case mbgl::style::LineJoinType::Round: - return "round"; - break; - case mbgl::style::LineJoinType::Miter: - return "miter"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // symbol-placement - inline std::string toString(mbgl::style::SymbolPlacementType value) { - switch (value) { - case mbgl::style::SymbolPlacementType::Point: - return "point"; - break; - case mbgl::style::SymbolPlacementType::Line: - return "line"; - break; - case mbgl::style::SymbolPlacementType::LineCenter: - return "line-center"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // icon-rotation-alignment - inline std::string toString(mbgl::style::AlignmentType value) { - switch (value) { - case mbgl::style::AlignmentType::Map: - return "map"; - break; - case mbgl::style::AlignmentType::Viewport: - return "viewport"; - break; - case mbgl::style::AlignmentType::Auto: - return "auto"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // icon-text-fit - inline std::string toString(mbgl::style::IconTextFitType value) { - switch (value) { - case mbgl::style::IconTextFitType::None: - return "none"; - break; - case mbgl::style::IconTextFitType::Width: - return "width"; - break; - case mbgl::style::IconTextFitType::Height: - return "height"; - break; - case mbgl::style::IconTextFitType::Both: - return "both"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // icon-anchor - inline std::string toString(mbgl::style::SymbolAnchorType value) { - switch (value) { - case mbgl::style::SymbolAnchorType::Center: - return "center"; - break; - case mbgl::style::SymbolAnchorType::Left: - return "left"; - break; - case mbgl::style::SymbolAnchorType::Right: - return "right"; - break; - case mbgl::style::SymbolAnchorType::Top: - return "top"; - break; - case mbgl::style::SymbolAnchorType::Bottom: - return "bottom"; - break; - case mbgl::style::SymbolAnchorType::TopLeft: - return "top-left"; - break; - case mbgl::style::SymbolAnchorType::TopRight: - return "top-right"; - break; - case mbgl::style::SymbolAnchorType::BottomLeft: - return "bottom-left"; - break; - case mbgl::style::SymbolAnchorType::BottomRight: - return "bottom-right"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // text-justify - inline std::string toString(mbgl::style::TextJustifyType value) { - switch (value) { - case mbgl::style::TextJustifyType::Left: - return "left"; - break; - case mbgl::style::TextJustifyType::Center: - return "center"; - break; - case mbgl::style::TextJustifyType::Right: - return "right"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // text-transform - inline std::string toString(mbgl::style::TextTransformType value) { - switch (value) { - case mbgl::style::TextTransformType::None: - return "none"; - break; - case mbgl::style::TextTransformType::Uppercase: - return "uppercase"; - break; - case mbgl::style::TextTransformType::Lowercase: - return "lowercase"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // fill-translate-anchor - inline std::string toString(mbgl::style::TranslateAnchorType value) { - switch (value) { - case mbgl::style::TranslateAnchorType::Map: - return "map"; - break; - case mbgl::style::TranslateAnchorType::Viewport: - return "viewport"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // circle-pitch-scale - inline std::string toString(mbgl::style::CirclePitchScaleType value) { - switch (value) { - case mbgl::style::CirclePitchScaleType::Map: - return "map"; - break; - case mbgl::style::CirclePitchScaleType::Viewport: - return "viewport"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // raster-resampling - inline std::string toString(mbgl::style::RasterResamplingType value) { - switch (value) { - case mbgl::style::RasterResamplingType::Linear: - return "linear"; - break; - case mbgl::style::RasterResamplingType::Nearest: - return "nearest"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // hillshade-illumination-anchor - inline std::string toString(mbgl::style::HillshadeIlluminationAnchorType value) { - switch (value) { - case mbgl::style::HillshadeIlluminationAnchorType::Map: - return "map"; - break; - case mbgl::style::HillshadeIlluminationAnchorType::Viewport: - return "viewport"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - // anchor - inline std::string toString(mbgl::style::LightAnchorType value) { - switch (value) { - case mbgl::style::LightAnchorType::Map: - return "map"; - break; - case mbgl::style::LightAnchorType::Viewport: - return "viewport"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - - -} // namespace conversion -} // namespace android -} // namespace mbgl diff --git a/platform/android/src/style/conversion/types_string_values.hpp.ejs b/platform/android/src/style/conversion/types_string_values.hpp.ejs deleted file mode 100644 index bf52919741..0000000000 --- a/platform/android/src/style/conversion/types_string_values.hpp.ejs +++ /dev/null @@ -1,48 +0,0 @@ -<% - const properties = locals.properties; --%> -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. -#pragma once - -#include <mbgl/style/types.hpp> - -#include <string> -#include <stdexcept> - -namespace mbgl { -namespace android { -namespace conversion { - - // visibility - inline std::string toString(mbgl::style::VisibilityType value) { - switch (value) { - case mbgl::style::VisibilityType::Visible: - return "visible"; - break; - case mbgl::style::VisibilityType::None: - return "none"; - break; - default: - throw std::runtime_error("Not implemented"); - } - } - -<% for (const property of properties) { -%> - // <%- property.name %> - inline std::string toString(mbgl::style::<%- propertyNativeType(property) %> value) { - switch (value) { -<% for (const value in property.values) { -%> - case mbgl::style::<%- propertyNativeType(property) %>::<%- camelize(value) %>: - return "<%- value %>"; - break; -<% } -%> - default: - throw std::runtime_error("Not implemented"); - } - } - -<% } -%> - -} // namespace conversion -} // namespace android -} // namespace mbgl diff --git a/platform/android/src/style/conversion/url_or_tileset.cpp b/platform/android/src/style/conversion/url_or_tileset.cpp new file mode 100644 index 0000000000..2ec5856751 --- /dev/null +++ b/platform/android/src/style/conversion/url_or_tileset.cpp @@ -0,0 +1,30 @@ +#include "url_or_tileset.hpp" +#include "../android_conversion.hpp" + +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/tileset.hpp> + +namespace mbgl { +namespace android { + +// This conversion is expected not to fail because it's used only in contexts where +// the value was originally a String or TileSet object on the Java side. If it fails +// to convert, it's a bug in our serialization or Java-side static typing. +variant<std::string, Tileset> convertURLOrTileset(mbgl::android::Value&& value) { + using namespace mbgl::style::conversion; + + const Convertible convertible(std::move(value)); + if (isObject(convertible)) { + Error error; + optional<Tileset> tileset = convert<Tileset>(convertible, error); + if (!tileset) { + throw std::logic_error(error.message); + } + return { *tileset }; + } else { + return { *toString(convertible) }; + } +} + +} +} diff --git a/platform/android/src/style/conversion/url_or_tileset.hpp b/platform/android/src/style/conversion/url_or_tileset.hpp index 92c1182a63..f42a9b9a2a 100644 --- a/platform/android/src/style/conversion/url_or_tileset.hpp +++ b/platform/android/src/style/conversion/url_or_tileset.hpp @@ -1,37 +1,16 @@ #pragma once -#include <mbgl/util/optional.hpp> #include <mbgl/util/variant.hpp> - #include <mbgl/util/tileset.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/tileset.hpp> - -#include <jni/jni.hpp> #include <string> +#include "../value.hpp" + namespace mbgl { namespace android { -// This conversion is expected not to fail because it's used only in contexts where -// the value was originally a String or TileSet object on the Java side. If it fails -// to convert, it's a bug in our serialization or Java-side static typing. -inline variant<std::string, Tileset> convertURLOrTileset(mbgl::android::Value&& value) { - using namespace mbgl::style::conversion; - - const Convertible convertible(std::move(value)); - if (isObject(convertible)) { - Error error; - optional<Tileset> tileset = convert<Tileset>(convertible, error); - if (!tileset) { - throw std::logic_error(error.message); - } - return { *tileset }; - } else { - return { *toString(convertible) }; - } -} +variant<std::string, Tileset> convertURLOrTileset(mbgl::android::Value&& value); } } |