[android] Simplify enum conversion

This commit is contained in:
John Firebaugh
2018-08-17 18:05:15 -07:00
parent 1584d8f70a
commit 9587f569f7
8 changed files with 9 additions and 484 deletions

View File

@@ -65,8 +65,6 @@ platform/android/src/style/conversion/property_expression.hpp
platform/android/src/style/conversion/property_value.hpp
platform/android/src/style/conversion/transition_options.cpp
platform/android/src/style/conversion/transition_options.hpp
platform/android/src/style/conversion/types.hpp
platform/android/src/style/conversion/types_string_values.hpp
platform/android/src/style/conversion/url_or_tileset.cpp
platform/android/src/style/conversion/url_or_tileset.hpp
platform/android/src/map/camera_position.cpp

View File

@@ -363,20 +363,3 @@ writeIfModified(
`platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java`,
enumPropertyJavaTemplate({properties: enumProperties})
);
// De-duplicate enum properties before processing jni property templates
const enumPropertiesDeDup = _(enumProperties).uniqBy(global.propertyNativeType).value();
// JNI Enum property conversion templates
const enumPropertyHppTypeStringValueTemplate = ejs.compile(fs.readFileSync('platform/android/src/style/conversion/types_string_values.hpp.ejs', 'utf8'), {strict: true});
writeIfModified(
`platform/android/src/style/conversion/types_string_values.hpp`,
enumPropertyHppTypeStringValueTemplate({properties: enumPropertiesDeDup})
);
// JNI property value types conversion templates
const enumPropertyHppTypeTemplate = ejs.compile(fs.readFileSync('platform/android/src/style/conversion/types.hpp.ejs', 'utf8'), {strict: true});
writeIfModified(
`platform/android/src/style/conversion/types.hpp`,
enumPropertyHppTypeTemplate({properties: enumPropertiesDeDup})
);

View File

@@ -3,6 +3,8 @@
#include "conversion.hpp"
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
#include <jni/jni.hpp>
#include <string>
@@ -74,6 +76,13 @@ struct Converter<jni::jobject*, std::vector<float>> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const std::vector<float>& value) const;
};
template <class T>
struct Converter<jni::jobject*, T, typename std::enable_if_t<std::is_enum<T>::value>> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const T& value) const {
return convert<jni::jobject*, std::string>(env, Enum<T>::toString(value));
}
};
// Java -> C++
template <>

View File

@@ -6,7 +6,6 @@
#include "../../conversion/conversion.hpp"
#include "../../conversion/constant.hpp"
#include "property_expression.hpp"
#include "types.hpp"
namespace mbgl {
namespace android {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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