generalize stylesheet parse function

This commit is contained in:
Konstantin Käfer
2014-05-26 12:30:27 +02:00
parent a7c3b8b6f5
commit e506d6bcdd
6 changed files with 62 additions and 102 deletions

View File

@@ -91,6 +91,10 @@ struct GenericClass {
boost::optional<TranslateAnchor> translateAnchor;
boost::optional<FunctionProperty> opacity;
boost::optional<PropertyTransition> opacity_transition;
boost::optional<bool> prerender;
boost::optional<float> prerenderBuffer;
boost::optional<uint16_t> prerenderSize;
boost::optional<bool> prerenderBlur;
};
struct GenericProperties {
@@ -98,6 +102,10 @@ struct GenericProperties {
std::array<float, 2> translate = {{ 0, 0 }};
TranslateAnchor translateAnchor = TranslateAnchor::Map;
float opacity = 1.0;
bool prerender = false;
float prerenderBuffer = 1.0f / 32.0f;
uint16_t prerenderSize = 256;
bool prerenderBlur = false;
};
struct IconClass : public GenericClass {
@@ -145,8 +153,6 @@ struct FillClass : public GenericClass {
boost::optional<Color> stroke_color;
boost::optional<PropertyTransition> stroke_color_transition;
boost::optional<std::string> image;
boost::optional<FunctionProperty> prerendered;
boost::optional<FunctionProperty> blur;
};
struct FillProperties : public GenericProperties {
@@ -154,9 +160,6 @@ struct FillProperties : public GenericProperties {
bool antialias = true;
Color fill_color = {{ 0, 0, 0, 1 }};
Color stroke_color = {{ 0, 0, 0, 1 }};
bool prerendered = false;
float prerenderBuffer = 1.0f / 32.0f;
uint16_t prerenderSize = 256;
float blur = 0.0f;
std::string image;
};

View File

@@ -30,6 +30,7 @@ private:
const std::map<std::string, BucketDescription> &buckets,
const std::map<std::string, std::string> &layerBuckets);
void parseGenericClass(GenericClass &klass, JSVal value);
FillClass parseFillClass(JSVal value);
LineClass parseLineClass(JSVal value);
IconClass parseIconClass(JSVal value);

View File

@@ -85,6 +85,18 @@ struct relaxed_equal {
Value const &lhs;
};
}
template <typename T>
T toNumber(const Value &value) {
if (value.is<std::string>()) return util::string_to_number<T>()(value.get<std::string>());
else if (value.is<bool>()) return value.get<bool>();
else if (value.is<int64_t>()) return value.get<int64_t>();
else if (value.is<uint64_t>()) return value.get<uint64_t>();
else if (value.is<double>()) return value.get<double>();
else return 0;
}
}
#endif