summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-08 17:18:06 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-13 17:22:05 -0700
commit039b05ebb462762c43ce4fc750fd98ae0c9e0093 (patch)
treeb424a42325ad306593d85ea438bee0d22d67ea30
parentee78b1b797bc8d46f7475612ae84f0ee548a0ed6 (diff)
downloadqtlocation-mapboxgl-039b05ebb462762c43ce4fc750fd98ae0c9e0093.tar.gz
[core] Extract code templates to individual .ejs files
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs76
-rw-r--r--scripts/generate-style-code.js279
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs92
-rw-r--r--src/mbgl/style/layers/layer_properties.cpp.ejs50
-rw-r--r--src/mbgl/style/layers/layer_properties.hpp.ejs50
5 files changed, 272 insertions, 275 deletions
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
new file mode 100644
index 0000000000..fdf7620892
--- /dev/null
+++ b/include/mbgl/style/layers/layer.hpp.ejs
@@ -0,0 +1,76 @@
+<%
+ const type = locals.type;
+ const layoutProperties = locals.layoutProperties;
+ const paintProperties = locals.paintProperties;
+-%>
+// This file is generated. Do not edit.
+
+#pragma once
+
+#include <mbgl/style/layer.hpp>
+#include <mbgl/style/filter.hpp>
+#include <mbgl/style/property_value.hpp>
+
+#include <mbgl/util/color.hpp>
+
+<% if (type === 'line' || type === 'symbol') { -%>
+#include <vector>
+
+<% } -%>
+namespace mbgl {
+namespace style {
+
+class <%- camelize(type) %>Layer : public Layer {
+public:
+ <%- camelize(type) %>Layer(const std::string& layerID);
+ ~<%- camelize(type) %>Layer() final;
+
+<% if (type === 'raster') { -%>
+ // Source
+
+ void setSource(const std::string& sourceID);
+ const std::string& getSourceID() const;
+
+<% } else if (type !== 'background') { -%>
+ // Source
+
+ void setSource(const std::string& sourceID, const std::string& sourceLayer);
+ const std::string& getSourceID() const;
+ const std::string& getSourceLayer() const;
+
+ void setFilter(const Filter&);
+ const Filter& getFilter() const;
+
+<% } -%>
+<% if (layoutProperties.length) { -%>
+ // Layout properties
+
+<% for (const property of layoutProperties) { -%>
+ PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const;
+ void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>);
+
+<% } -%>
+<% } -%>
+ // Paint properties
+
+<% for (const property of paintProperties) { -%>
+ PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const;
+ void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>);
+
+<% } -%>
+ // Private implementation
+
+ class Impl;
+ Impl* const impl;
+
+ <%- camelize(type) %>Layer(const Impl&);
+ <%- camelize(type) %>Layer(const <%- camelize(type) %>Layer&) = delete;
+};
+
+template <>
+inline bool Layer::is<<%- camelize(type) %>Layer>() const {
+ return type == Type::<%- camelize(type) %>;
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index 1796cda212..21654117b8 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -76,281 +76,10 @@ global.defaultValue = function (property) {
}
}
-const layerHpp = ejs.compile(`<%
- const type = locals.type;
- const layoutProperties = locals.layoutProperties;
- const paintProperties = locals.paintProperties;
--%>
-// This file is generated. Do not edit.
-
-#pragma once
-
-#include <mbgl/style/layer.hpp>
-#include <mbgl/style/filter.hpp>
-#include <mbgl/style/property_value.hpp>
-
-#include <mbgl/util/color.hpp>
-
-<% if (type === 'line' || type === 'symbol') { -%>
-#include <vector>
-
-<% } -%>
-namespace mbgl {
-namespace style {
-
-class <%- camelize(type) %>Layer : public Layer {
-public:
- <%- camelize(type) %>Layer(const std::string& layerID);
- ~<%- camelize(type) %>Layer() final;
-
-<% if (type === 'raster') { -%>
- // Source
-
- void setSource(const std::string& sourceID);
- const std::string& getSourceID() const;
-
-<% } else if (type !== 'background') { -%>
- // Source
-
- void setSource(const std::string& sourceID, const std::string& sourceLayer);
- const std::string& getSourceID() const;
- const std::string& getSourceLayer() const;
-
- void setFilter(const Filter&);
- const Filter& getFilter() const;
-
-<% } -%>
-<% if (layoutProperties.length) { -%>
- // Layout properties
-
-<% for (const property of layoutProperties) { -%>
- PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const;
- void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>);
-
-<% } -%>
-<% } -%>
- // Paint properties
-
-<% for (const property of paintProperties) { -%>
- PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const;
- void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>);
-
-<% } -%>
- // Private implementation
-
- class Impl;
- Impl* const impl;
-
- <%- camelize(type) %>Layer(const Impl&);
- <%- camelize(type) %>Layer(const <%- camelize(type) %>Layer&) = delete;
-};
-
-template <>
-inline bool Layer::is<<%- camelize(type) %>Layer>() const {
- return type == Type::<%- camelize(type) %>;
-}
-
-} // namespace style
-} // namespace mbgl
-`, {strict: true});
-
-const layerCpp = ejs.compile(`<%
- const type = locals.type;
- const layoutProperties = locals.layoutProperties;
- const paintProperties = locals.paintProperties;
--%>
-// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`.
-
-#include <mbgl/style/layers/<%- type %>_layer.hpp>
-#include <mbgl/style/layers/<%- type %>_layer_impl.hpp>
-
-namespace mbgl {
-namespace style {
-
-<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID)
- : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>())
- , impl(static_cast<Impl*>(baseImpl.get())) {
- impl->id = layerID;
-}
-
-<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other)
- : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>(other))
- , impl(static_cast<Impl*>(baseImpl.get())) {
-}
-
-<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;
-
-std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const {
- return std::make_unique<<%- camelize(type) %>Layer>(*this);
-}
-
-<% if (type === 'raster') { -%>
-// Source
-
-void <%- camelize(type) %>Layer::setSource(const std::string& sourceID) {
- impl->source = sourceID;
-}
-
-const std::string& <%- camelize(type) %>Layer::getSourceID() const {
- return impl->source;
-}
-<% } else if (type !== 'background') { -%>
-// Source
-
-void <%- camelize(type) %>Layer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
- impl->source = sourceID;
- impl->sourceLayer = sourceLayer;
-}
-
-const std::string& <%- camelize(type) %>Layer::getSourceID() const {
- return impl->source;
-}
-
-const std::string& <%- camelize(type) %>Layer::getSourceLayer() const {
- return impl->sourceLayer;
-}
-
-// Filter
-
-void <%- camelize(type) %>Layer::setFilter(const Filter& filter) {
- impl->filter = filter;
-}
-
-const Filter& <%- camelize(type) %>Layer::getFilter() const {
- return impl->filter;
-}
-<% } -%>
-
-// Layout properties
-
-<% for (const property of layoutProperties) { -%>
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
- return impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.get();
-}
-
-void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) {
- impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value);
-}
-<% } -%>
-
-// Paint properties
-<% for (const property of paintProperties) { %>
-PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
- return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get();
-}
-
-void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) {
- impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value);
-}
-<% } -%>
-
-} // namespace style
-} // namespace mbgl
-`, {strict: true});
-
-const propertiesHpp = ejs.compile(`<%
- const type = locals.type;
- const layoutProperties = locals.layoutProperties;
- const paintProperties = locals.paintProperties;
--%>
-// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`.
-
-#pragma once
-
-#include <mbgl/style/layout_property.hpp>
-#include <mbgl/style/paint_property.hpp>
-#include <mbgl/util/rapidjson.hpp>
-
-namespace mbgl {
-namespace style {
-
-class CascadeParameters;
-class CalculationParameters;
-
-<% if (layoutProperties.length) { -%>
-class <%- camelize(type) %>LayoutProperties {
-public:
- void parse(const JSValue&);
- void recalculate(const CalculationParameters&);
-
-<% for (const property of layoutProperties) { -%>
- LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
-<% } -%>
-};
-
-<% } -%>
-class <%- camelize(type) %>PaintProperties {
-public:
- void parse(const JSValue&);
- void cascade(const CascadeParameters&);
- bool recalculate(const CalculationParameters&);
-
-<% for (const property of paintProperties) { -%>
-<% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%>
- PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
-<% } else if (property.name === 'fill-outline-color') { -%>
- PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} };
-<% } else { -%>
- PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
-<% } -%>
-<% } -%>
-};
-
-} // namespace style
-} // namespace mbgl
-`, {strict: true});
-
-const propertiesCpp = ejs.compile(`<%
- const type = locals.type;
- const layoutProperties = locals.layoutProperties;
- const paintProperties = locals.paintProperties;
--%>
-// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`.
-
-#include <mbgl/style/layers/<%- type %>_layer_properties.hpp>
-
-namespace mbgl {
-namespace style {
-
-<% if (layoutProperties.length) { -%>
-void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) {
-<% for (const property of layoutProperties) { -%>
- <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value);
-<% } -%>
-}
-
-void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParameters& parameters) {
-<% for (const property of layoutProperties) { -%>
- <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters);
-<% } -%>
-}
-
-<% } -%>
-void <%- camelize(type) %>PaintProperties::parse(const JSValue& value) {
-<% for (const property of paintProperties) { -%>
- <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value);
-<% } -%>
-}
-
-void <%- camelize(type) %>PaintProperties::cascade(const CascadeParameters& parameters) {
-<% for (const property of paintProperties) { -%>
- <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters);
-<% } -%>
-}
-
-bool <%- camelize(type) %>PaintProperties::recalculate(const CalculationParameters& parameters) {
- bool hasTransitions = false;
-
-<% for (const property of paintProperties) { -%>
- hasTransitions |= <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters);
-<% } -%>
-
- return hasTransitions;
-}
-
-} // namespace style
-} // namespace mbgl
-`, {strict: true});
+const layerHpp = ejs.compile(fs.readFileSync('include/mbgl/style/layers/layer.hpp.ejs', 'utf8'), {strict: true});
+const layerCpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer.cpp.ejs', 'utf8'), {strict: true});
+const propertiesHpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer_properties.hpp.ejs', 'utf8'), {strict: true});
+const propertiesCpp = ejs.compile(fs.readFileSync('src/mbgl/style/layers/layer_properties.cpp.ejs', 'utf8'), {strict: true});
for (const type of spec.layer.type.values) {
const layoutProperties = Object.keys(spec[`layout_${type}`]).reduce((memo, name) => {
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
new file mode 100644
index 0000000000..633d673804
--- /dev/null
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -0,0 +1,92 @@
+<%
+ const type = locals.type;
+ const layoutProperties = locals.layoutProperties;
+ const paintProperties = locals.paintProperties;
+-%>
+// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
+
+#include <mbgl/style/layers/<%- type %>_layer.hpp>
+#include <mbgl/style/layers/<%- type %>_layer_impl.hpp>
+
+namespace mbgl {
+namespace style {
+
+<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID)
+ : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>())
+ , impl(static_cast<Impl*>(baseImpl.get())) {
+ impl->id = layerID;
+}
+
+<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other)
+ : Layer(Type::<%- camelize(type) %>, std::make_unique<Impl>(other))
+ , impl(static_cast<Impl*>(baseImpl.get())) {
+}
+
+<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default;
+
+std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const {
+ return std::make_unique<<%- camelize(type) %>Layer>(*this);
+}
+
+<% if (type === 'raster') { -%>
+// Source
+
+void <%- camelize(type) %>Layer::setSource(const std::string& sourceID) {
+ impl->source = sourceID;
+}
+
+const std::string& <%- camelize(type) %>Layer::getSourceID() const {
+ return impl->source;
+}
+<% } else if (type !== 'background') { -%>
+// Source
+
+void <%- camelize(type) %>Layer::setSource(const std::string& sourceID, const std::string& sourceLayer) {
+ impl->source = sourceID;
+ impl->sourceLayer = sourceLayer;
+}
+
+const std::string& <%- camelize(type) %>Layer::getSourceID() const {
+ return impl->source;
+}
+
+const std::string& <%- camelize(type) %>Layer::getSourceLayer() const {
+ return impl->sourceLayer;
+}
+
+// Filter
+
+void <%- camelize(type) %>Layer::setFilter(const Filter& filter) {
+ impl->filter = filter;
+}
+
+const Filter& <%- camelize(type) %>Layer::getFilter() const {
+ return impl->filter;
+}
+<% } -%>
+
+// Layout properties
+
+<% for (const property of layoutProperties) { -%>
+PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
+ return impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.get();
+}
+
+void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) {
+ impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value);
+}
+<% } -%>
+
+// Paint properties
+<% for (const property of paintProperties) { %>
+PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
+ return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get();
+}
+
+void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) {
+ impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value);
+}
+<% } -%>
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/layers/layer_properties.cpp.ejs b/src/mbgl/style/layers/layer_properties.cpp.ejs
new file mode 100644
index 0000000000..8fef8d29c4
--- /dev/null
+++ b/src/mbgl/style/layers/layer_properties.cpp.ejs
@@ -0,0 +1,50 @@
+<%
+ const type = locals.type;
+ const layoutProperties = locals.layoutProperties;
+ const paintProperties = locals.paintProperties;
+-%>
+// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
+
+#include <mbgl/style/layers/<%- type %>_layer_properties.hpp>
+
+namespace mbgl {
+namespace style {
+
+<% if (layoutProperties.length) { -%>
+void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) {
+<% for (const property of layoutProperties) { -%>
+ <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value);
+<% } -%>
+}
+
+void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParameters& parameters) {
+<% for (const property of layoutProperties) { -%>
+ <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters);
+<% } -%>
+}
+
+<% } -%>
+void <%- camelize(type) %>PaintProperties::parse(const JSValue& value) {
+<% for (const property of paintProperties) { -%>
+ <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value);
+<% } -%>
+}
+
+void <%- camelize(type) %>PaintProperties::cascade(const CascadeParameters& parameters) {
+<% for (const property of paintProperties) { -%>
+ <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters);
+<% } -%>
+}
+
+bool <%- camelize(type) %>PaintProperties::recalculate(const CalculationParameters& parameters) {
+ bool hasTransitions = false;
+
+<% for (const property of paintProperties) { -%>
+ hasTransitions |= <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters);
+<% } -%>
+
+ return hasTransitions;
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs
new file mode 100644
index 0000000000..55e07ad61b
--- /dev/null
+++ b/src/mbgl/style/layers/layer_properties.hpp.ejs
@@ -0,0 +1,50 @@
+<%
+ const type = locals.type;
+ const layoutProperties = locals.layoutProperties;
+ const paintProperties = locals.paintProperties;
+-%>
+// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
+
+#pragma once
+
+#include <mbgl/style/layout_property.hpp>
+#include <mbgl/style/paint_property.hpp>
+#include <mbgl/util/rapidjson.hpp>
+
+namespace mbgl {
+namespace style {
+
+class CascadeParameters;
+class CalculationParameters;
+
+<% if (layoutProperties.length) { -%>
+class <%- camelize(type) %>LayoutProperties {
+public:
+ void parse(const JSValue&);
+ void recalculate(const CalculationParameters&);
+
+<% for (const property of layoutProperties) { -%>
+ LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
+<% } -%>
+};
+
+<% } -%>
+class <%- camelize(type) %>PaintProperties {
+public:
+ void parse(const JSValue&);
+ void cascade(const CascadeParameters&);
+ bool recalculate(const CalculationParameters&);
+
+<% for (const property of paintProperties) { -%>
+<% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%>
+ PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
+<% } else if (property.name === 'fill-outline-color') { -%>
+ PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} };
+<% } else { -%>
+ PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> };
+<% } -%>
+<% } -%>
+};
+
+} // namespace style
+} // namespace mbgl