From 38fcbe21d48186c4630a3b8a76d1b20e156faadd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 30 Oct 2016 11:06:59 -0700 Subject: [core] Convert style properties to a tuple-based approach This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md. The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily. Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state. --- src/mbgl/style/layers/layer_properties.hpp.ejs | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/mbgl/style/layers/layer_properties.hpp.ejs') diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 0c91ecba8c..f490a636f9 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -14,33 +14,35 @@ namespace mbgl { namespace style { -class CascadeParameters; -class CalculationParameters; - -<% if (layoutProperties.length) { -%> -class <%- camelize(type) %>LayoutProperties { -public: - void recalculate(const CalculationParameters&); - <% for (const property of layoutProperties) { -%> - LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; +struct <%- camelize(property.name) %> : LayoutProperty<<%- propertyType(property) %>> { + static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; } +}; + <% } -%> +<% for (const property of paintProperties) { -%> +struct <%- camelize(property.name) %> : <% +if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { +%>CrossFaded<% } -%>PaintProperty<<%- propertyType(property) %>> { + static <%- propertyType(property) %> defaultValue() { return <%- defaultValue(property) %>; } }; <% } -%> -class <%- camelize(type) %>PaintProperties { -public: - void cascade(const CascadeParameters&); - bool recalculate(const CalculationParameters&); +<% if (layoutProperties.length) { -%> +class <%- camelize(type) %>LayoutProperties : public LayoutProperties< +<% for (const property of layoutProperties.slice(0, -1)) { -%> + <%- camelize(property.name) %>, +<% } -%> + <%- camelize(layoutProperties.slice(-1)[0].name) %> +> {}; -<% for (const property of paintProperties) { -%> -<% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> - PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; -<% } else { -%> - PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } -%> +class <%- camelize(type) %>PaintProperties : public PaintProperties< +<% for (const property of paintProperties.slice(0, -1)) { -%> + <%- camelize(property.name) %>, <% } -%> -}; + <%- camelize(paintProperties.slice(-1)[0].name) %> +> {}; } // namespace style } // namespace mbgl -- cgit v1.2.1