summaryrefslogtreecommitdiff
path: root/src/style
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-07-17 12:44:45 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-07-17 12:44:45 -0400
commit4cb9972278c2121a87161e3b02b2071acc1ca8e1 (patch)
treeb0f017fda1740503c1bd7d5e3a28e586648d2e77 /src/style
parent056f9e88d5214ae5752ec946666c756e2bf3d72b (diff)
parentfa4133a094a084527633038d2de1982ed4898a08 (diff)
downloadqtlocation-mapboxgl-4cb9972278c2121a87161e3b02b2071acc1ca8e1.tar.gz
Merge branch 'master' into fuzz-pipe
Conflicts: bin/package.json src/style/style_parser.cpp test/fixtures/fixture_log.cpp test/test.gyp
Diffstat (limited to 'src/style')
-rw-r--r--src/style/applied_class_properties.cpp4
-rw-r--r--src/style/class_dictionary.cpp4
-rw-r--r--src/style/class_properties.cpp4
-rw-r--r--src/style/filter_comparison.cpp143
-rw-r--r--src/style/filter_expression.cpp236
-rw-r--r--src/style/function_properties.cpp6
-rw-r--r--src/style/property_fallback.cpp4
-rw-r--r--src/style/style.cpp16
-rw-r--r--src/style/style_bucket.cpp4
-rw-r--r--src/style/style_layer.cpp10
-rw-r--r--src/style/style_layer_group.cpp4
-rw-r--r--src/style/style_parser.cpp23
-rw-r--r--src/style/style_properties.cpp4
-rw-r--r--src/style/value.cpp6
14 files changed, 196 insertions, 272 deletions
diff --git a/src/style/applied_class_properties.cpp b/src/style/applied_class_properties.cpp
index dfe419ebde..ca9c09436c 100644
--- a/src/style/applied_class_properties.cpp
+++ b/src/style/applied_class_properties.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/applied_class_properties.hpp>
+#include <mbgl/style/applied_class_properties.hpp>
-namespace llmr {
+namespace mbgl {
AppliedClassProperty::AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value)
: name(class_id),
diff --git a/src/style/class_dictionary.cpp b/src/style/class_dictionary.cpp
index a641295c6f..6e1eb5a879 100644
--- a/src/style/class_dictionary.cpp
+++ b/src/style/class_dictionary.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/class_dictionary.hpp>
+#include <mbgl/style/class_dictionary.hpp>
-namespace llmr {
+namespace mbgl {
ClassID ClassDictionary::Lookup(const std::string &class_name) {
auto it = store.find(class_name);
diff --git a/src/style/class_properties.cpp b/src/style/class_properties.cpp
index e326f56561..e7bf855bfc 100644
--- a/src/style/class_properties.cpp
+++ b/src/style/class_properties.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/class_properties.hpp>
+#include <mbgl/style/class_properties.hpp>
-namespace llmr {
+namespace mbgl {
const PropertyTransition &ClassProperties::getTransition(PropertyKey key, const PropertyTransition &defaultTransition) const {
auto it = transitions.find(key);
diff --git a/src/style/filter_comparison.cpp b/src/style/filter_comparison.cpp
new file mode 100644
index 0000000000..b3f3a9ef08
--- /dev/null
+++ b/src/style/filter_comparison.cpp
@@ -0,0 +1,143 @@
+#include <mbgl/map/vector_tile.hpp>
+#include <mbgl/style/filter_comparison_private.hpp>
+
+#include <mbgl/style/value_comparison.hpp>
+
+#include <ostream>
+
+namespace mbgl {
+
+
+inline bool includes(const Value &property_value, const std::vector<Value> &filter_values) {
+ for (const Value &filter_value : filter_values) {
+ if (util::relaxed_equal(property_value, filter_value)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+template <typename Comparer>
+inline bool compare(const Value &property_value, const std::vector<Value> &filter_values, const Comparer &comparer) {
+ for (const Value &filter_value : filter_values) {
+ if (!comparer(property_value, filter_value)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+template <typename Comparer>
+inline bool all(const std::vector<Value> &property_values, const std::vector<Value> &filter_values, const Comparer &comparer) {
+ for (const Value &property_value : property_values) {
+ if (!compare(property_value, filter_values, comparer)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+inline bool set_equal(const std::vector<Value> &property_values, const std::vector<Value> &filter_values) {
+ for (const Value &property_value : property_values) {
+ if (!includes(property_value, filter_values)) {
+ return false;
+ }
+ }
+ if (property_values.size() == filter_values.size()) {
+ // Optimization: When the count is the same, the set is guaranteed to be identical.
+ return true;
+ }
+ // Otherwise, check again for identical reverse-mapped values.
+ for (const Value &filter_value : filter_values) {
+ if (!includes(filter_value, property_values)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+bool FilterComparison::Instance::compare(const std::vector<Value> &property_values) const {
+ switch (op) {
+ case Operator::Equal:
+ return set_equal(property_values, values);
+ case Operator::NotEqual:
+ return !set_equal(property_values, values);
+ case Operator::In:
+ for (const Value &property_value : property_values) {
+ if (includes(property_value, values)) {
+ return true;
+ }
+ }
+ return false;
+ case Operator::NotIn:
+ for (const Value &property_value : property_values) {
+ if (!includes(property_value, values)) {
+ return true;
+ }
+ }
+ return false;
+ case Operator::Greater:
+ return all(property_values, values, util::relaxed_greater);
+ case Operator::GreaterEqual:
+ return all(property_values, values, util::relaxed_greater_equal);
+ case Operator::Less:
+ return all(property_values, values, util::relaxed_less);
+ case Operator::LessEqual:
+ return all(property_values, values, util::relaxed_less_equal);
+ default:
+ return false;
+ }
+}
+
+
+const std::string &FilterComparison::getField() const {
+ return field;
+}
+
+std::ostream& operator <<(std::ostream &s, const FilterComparison &comparison) {
+ s << "comparison" << std::endl;
+ for (const FilterComparison::Instance &instance : comparison.instances) {
+ s << " - " << comparison.field << " " << instance << std::endl;
+ }
+ return s;
+}
+
+
+std::ostream& operator <<(std::ostream &s, const FilterComparison::Instance &instance) {
+ switch (instance.op) {
+ case FilterComparison::Operator::Equal: s << "=="; break;
+ case FilterComparison::Operator::NotEqual: s << "!="; break;
+ case FilterComparison::Operator::Greater: s << ">"; break;
+ case FilterComparison::Operator::GreaterEqual: s << ">="; break;
+ case FilterComparison::Operator::Less: s << "<"; break;
+ case FilterComparison::Operator::LessEqual: s << "<="; break;
+ case FilterComparison::Operator::In: s << "in"; break;
+ case FilterComparison::Operator::NotIn: s << "!in"; break;
+ }
+
+ s << " [ ";
+ for (const Value &value : instance.values) {
+ s << toString(value) << " ";
+ }
+ s << "]";
+ return s;
+}
+
+
+FilterComparison::Operator parseFilterComparisonOperator(const std::string &op) {
+ if (op == "==") return FilterComparison::Operator::Equal;
+ if (op == "!=") return FilterComparison::Operator::NotEqual;
+ if (op == ">") return FilterComparison::Operator::Greater;
+ if (op == ">=") return FilterComparison::Operator::GreaterEqual;
+ if (op == "<") return FilterComparison::Operator::Less;
+ if (op == "<=") return FilterComparison::Operator::LessEqual;
+ if (op == "in") return FilterComparison::Operator::In;
+ if (op == "!in") return FilterComparison::Operator::NotIn;
+ return FilterComparison::Operator::Equal;
+}
+
+template bool FilterComparison::compare(const VectorTileTagExtractor &extractor) const;
+
+}
diff --git a/src/style/filter_expression.cpp b/src/style/filter_expression.cpp
index 58483accac..ff4073b129 100644
--- a/src/style/filter_expression.cpp
+++ b/src/style/filter_expression.cpp
@@ -1,166 +1,11 @@
-#include <llmr/style/filter_expression.hpp>
-#include <llmr/map/vector_tile.hpp>
+#include <mbgl/style/filter_expression_private.hpp>
+#include <mbgl/map/vector_tile.hpp>
-namespace llmr {
+#include <mbgl/style/value_comparison.hpp>
+#include <ostream>
-template <typename Comparer>
-inline bool FilterComparison::Instance::includes(const Value &property_value, const Comparer &comparer) const {
- for (const Value &filter_value : values) {
- if (comparer(property_value, filter_value)) {
- return true;
- }
- }
- return false;
-}
-
-template <typename Comparer>
-inline bool FilterComparison::Instance::compare(const Value &property_value, const Comparer &comparer) const {
- for (const Value &filter_value : values) {
- if (!comparer(property_value, filter_value)) {
- return false;
- }
- }
- return true;
-}
-
-template <typename Comparer>
-inline bool FilterComparison::Instance::all(const std::forward_list<Value> &property_values, const Comparer &comparer) const {
- for (const Value &property_value : property_values) {
- if (!compare(property_value, comparer)) {
- return false;
- }
- }
- return true;
-}
-
-
-
-bool FilterComparison::Instance::compare(const Value &property_value) const {
- switch (op) {
- case Operator::Equal:
- case Operator::In:
- return includes(property_value, util::relaxed_equal);
- case Operator::NotEqual:
- case Operator::NotIn:
- return !includes(property_value, util::relaxed_equal);
- case Operator::Greater:
- return compare(property_value, util::relaxed_greater);
- case Operator::GreaterEqual:
- return compare(property_value, util::relaxed_greater_equal);
- case Operator::Less:
- return compare(property_value, util::relaxed_less);
- case Operator::LessEqual:
- return compare(property_value, util::relaxed_less_equal);
- default:
- return false;
- }
-}
-
-bool FilterComparison::Instance::compare(const std::forward_list<Value> &property_values) const {
- switch (op) {
- case Operator::Equal:
- for (const Value &property_value : property_values) {
- if (!includes(property_value, util::relaxed_equal)) {
- return false;
- }
- }
- return true;
- case Operator::NotEqual:
- for (const Value &property_value : property_values) {
- if (includes(property_value, util::relaxed_equal)) {
- return false;
- }
- }
- return true;
- case Operator::In:
- for (const Value &property_value : property_values) {
- if (includes(property_value, util::relaxed_equal)) {
- return true;
- }
- }
- return false;
- case Operator::NotIn:
- for (const Value &property_value : property_values) {
- if (!includes(property_value, util::relaxed_equal)) {
- return true;
- }
- }
- return false;
- case Operator::Greater:
- return all(property_values, util::relaxed_greater);
- case Operator::GreaterEqual:
- return all(property_values, util::relaxed_greater_equal);
- case Operator::Less:
- return all(property_values, util::relaxed_less);
- case Operator::LessEqual:
- return all(property_values, util::relaxed_less_equal);
- default:
- return false;
- }
-}
-
-
-const std::string &FilterComparison::getField() const {
- return field;
-}
-
-inline bool FilterComparison::compare(const VectorTileTagExtractor &extractor) const {
- const std::forward_list<Value> values = extractor.getValues(field);
-
- // All instances are ANDed together.
- for (const Instance &instance : instances) {
- if (!instance.compare(values)) {
- return false;
- }
- }
- return true;
-}
-
-
-
-std::ostream& operator <<(std::ostream &s, const FilterComparison &comparison) {
- s << "comparison" << std::endl;
- for (const FilterComparison::Instance &instance : comparison.instances) {
- s << " - " << comparison.field << " " << instance << std::endl;
- }
- return s;
-}
-
-
-std::ostream& operator <<(std::ostream &s, const FilterComparison::Instance &instance) {
- switch (instance.op) {
- case FilterComparison::Operator::Equal: s << "=="; break;
- case FilterComparison::Operator::NotEqual: s << "!="; break;
- case FilterComparison::Operator::Greater: s << ">"; break;
- case FilterComparison::Operator::GreaterEqual: s << ">="; break;
- case FilterComparison::Operator::Less: s << "<"; break;
- case FilterComparison::Operator::LessEqual: s << "<="; break;
- case FilterComparison::Operator::In: s << "in"; break;
- case FilterComparison::Operator::NotIn: s << "!in"; break;
- }
-
- s << " [ ";
- for (const Value &value : instance.values) {
- s << toString(value) << " ";
- }
- s << "]";
- return s;
-}
-
-
-FilterComparison::Operator parseFilterComparisonOperator(const std::string &op) {
- if (op == "==") return FilterComparison::Operator::Equal;
- if (op == "!=") return FilterComparison::Operator::NotEqual;
- if (op == ">") return FilterComparison::Operator::Greater;
- if (op == ">=") return FilterComparison::Operator::GreaterEqual;
- if (op == "<") return FilterComparison::Operator::Less;
- if (op == "<=") return FilterComparison::Operator::LessEqual;
- if (op == "in") return FilterComparison::Operator::In;
- if (op == "!in") return FilterComparison::Operator::NotIn;
- return FilterComparison::Operator::Equal;
-}
-
+namespace mbgl {
std::ostream& operator <<(std::ostream &s, FilterExpression::Operator op) {
switch (op) {
@@ -183,81 +28,16 @@ std::ostream& operator <<(std::ostream &s, FilterExpression::GeometryType type)
return s;
}
-
-
-bool FilterExpression::compare(const VectorTileTagExtractor &extractor) const {
- if (type != GeometryType::Any && extractor.getType() != type && extractor.getType() != GeometryType::Any) {
- return false;
- }
-
- switch (op) {
- case Operator::And:
- for (const FilterComparison &comparison : comparisons) {
- if (!comparison.compare(extractor)) {
- return false;
- }
- }
- for (const FilterExpression &expression: expressions) {
- if (!expression.compare(extractor)) {
- return false;
- }
- }
- return true;
- case Operator::Or:
- for (const FilterComparison &comparison : comparisons) {
- if (comparison.compare(extractor)) {
- return true;
- }
- }
- for (const FilterExpression &expression: expressions) {
- if (expression.compare(extractor)) {
- return true;
- }
- }
- return false;
- case Operator::Xor: {
- int count = 0;
- for (const FilterComparison &comparison : comparisons) {
- count += comparison.compare(extractor);
- if (count > 1) {
- return false;
- }
- }
- for (const FilterExpression &expression: expressions) {
- count += expression.compare(extractor);
- if (count > 1) {
- return false;
- }
- }
- return count == 1;
- }
- case Operator::Nor:
- for (const FilterComparison &comparison : comparisons) {
- if (comparison.compare(extractor)) {
- return false;
- }
- }
- for (const FilterExpression &expression: expressions) {
- if (expression.compare(extractor)) {
- return false;
- }
- }
- return true;
- default:
- return true;
- }
-}
-
bool FilterExpression::empty() const {
return type == GeometryType::Any && comparisons.empty() && expressions.empty();
}
void FilterExpression::add(const FilterComparison &comparison) {
- comparisons.emplace_front(comparison);
+ comparisons.emplace_back(comparison);
}
void FilterExpression::add(const FilterExpression &expression) {
- expressions.emplace_front(expression);
+ expressions.emplace_back(expression);
}
void FilterExpression::setGeometryType(GeometryType g) {
@@ -281,4 +61,6 @@ std::ostream& operator <<(std::ostream &s, const FilterExpression &expression) {
return s;
}
+template bool FilterExpression::compare(const VectorTileTagExtractor &extractor) const;
+
}
diff --git a/src/style/function_properties.cpp b/src/style/function_properties.cpp
index 9ed04b1b51..2b378fb6b9 100644
--- a/src/style/function_properties.cpp
+++ b/src/style/function_properties.cpp
@@ -1,9 +1,9 @@
-#include <llmr/style/function_properties.hpp>
-#include <llmr/style/types.hpp>
+#include <mbgl/style/function_properties.hpp>
+#include <mbgl/style/types.hpp>
#include <cmath>
-namespace llmr {
+namespace mbgl {
template <>
diff --git a/src/style/property_fallback.cpp b/src/style/property_fallback.cpp
index 38eae89c51..949dc1a5cb 100644
--- a/src/style/property_fallback.cpp
+++ b/src/style/property_fallback.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/property_fallback.hpp>
+#include <mbgl/style/property_fallback.hpp>
-namespace llmr {
+namespace mbgl {
const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = {
{ PropertyKey::FillAntialias, true },
diff --git a/src/style/style.cpp b/src/style/style.cpp
index c5204720ab..f867616970 100644
--- a/src/style/style.cpp
+++ b/src/style/style.cpp
@@ -1,16 +1,16 @@
-#include <llmr/style/style.hpp>
-#include <llmr/style/style_layer_group.hpp>
-#include <llmr/style/style_parser.hpp>
-#include <llmr/style/style_bucket.hpp>
-#include <llmr/util/constants.hpp>
-#include <llmr/util/time.hpp>
-#include <llmr/util/error.hpp>
+#include <mbgl/style/style.hpp>
+#include <mbgl/style/style_layer_group.hpp>
+#include <mbgl/style/style_parser.hpp>
+#include <mbgl/style/style_bucket.hpp>
+#include <mbgl/util/constants.hpp>
+#include <mbgl/util/time.hpp>
+#include <mbgl/util/error.hpp>
#include <csscolorparser/csscolorparser.hpp>
#include <rapidjson/document.h>
-namespace llmr {
+namespace mbgl {
Style::Style() {
}
diff --git a/src/style/style_bucket.cpp b/src/style/style_bucket.cpp
index 664d5a9488..afd4bc09f7 100644
--- a/src/style/style_bucket.cpp
+++ b/src/style/style_bucket.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/style_bucket.hpp>
+#include <mbgl/style/style_bucket.hpp>
-namespace llmr {
+namespace mbgl {
StyleBucket::StyleBucket(StyleLayerType type) {
switch (type) {
diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp
index c2a8065c18..69c5a8c8ca 100644
--- a/src/style/style_layer.cpp
+++ b/src/style/style_layer.cpp
@@ -1,9 +1,9 @@
-#include <llmr/style/style_layer.hpp>
-#include <llmr/style/style_bucket.hpp>
-#include <llmr/style/style_layer_group.hpp>
-#include <llmr/style/property_fallback.hpp>
+#include <mbgl/style/style_layer.hpp>
+#include <mbgl/style/style_bucket.hpp>
+#include <mbgl/style/style_layer_group.hpp>
+#include <mbgl/style/property_fallback.hpp>
-namespace llmr {
+namespace mbgl {
StyleLayer::StyleLayer(const std::string &id, std::map<ClassID, ClassProperties> &&styles,
std::unique_ptr<const RasterizeProperties> &&rasterize)
diff --git a/src/style/style_layer_group.cpp b/src/style/style_layer_group.cpp
index 86fe6fa241..c7e4360d21 100644
--- a/src/style/style_layer_group.cpp
+++ b/src/style/style_layer_group.cpp
@@ -1,7 +1,7 @@
-#include <llmr/style/style_layer_group.hpp>
+#include <mbgl/style/style_layer_group.hpp>
-namespace llmr {
+namespace mbgl {
void StyleLayerGroup::setClasses(const std::vector<std::string> &class_names, timestamp now,
const PropertyTransition &defaultTransition) {
diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp
index 93e309d685..c4faf81f5a 100644
--- a/src/style/style_parser.cpp
+++ b/src/style/style_parser.cpp
@@ -1,11 +1,11 @@
-#include <llmr/style/style_parser.hpp>
-#include <llmr/style/style_layer_group.hpp>
-#include <llmr/util/constants.hpp>
-#include <llmr/util/std.hpp>
-#include <llmr/platform/log.hpp>
+#include <mbgl/style/style_parser.hpp>
+#include <mbgl/style/style_layer_group.hpp>
+#include <mbgl/util/constants.hpp>
+#include <mbgl/util/std.hpp>
+#include <mbgl/platform/log.hpp>
#include <csscolorparser/csscolorparser.hpp>
-namespace llmr {
+namespace mbgl {
using JSVal = const rapidjson::Value&;
@@ -792,7 +792,7 @@ FilterExpression StyleParser::parseFilter(JSVal value, FilterExpression::Operato
} else if (filterValue.IsArray()) {
comparison.add(FilterComparison::Operator::In, parseValues(filterValue));
} else {
- comparison.add(FilterComparison::Operator::Equal, std::forward_list<Value>({ parseValue(filterValue) }));
+ comparison.add(FilterComparison::Operator::Equal, std::vector<Value>({ parseValue(filterValue) }));
}
expression.add(comparison);
}
@@ -830,15 +830,14 @@ Value StyleParser::parseValue(JSVal value) {
}
}
-std::forward_list<Value> StyleParser::parseValues(JSVal value) {
- std::forward_list<Value> values;
+std::vector<Value> StyleParser::parseValues(JSVal value) {
+ std::vector<Value> values;
if (value.IsArray()) {
- auto it = values.before_begin();
for (rapidjson::SizeType i = 0; i < value.Size(); i++) {
- it = values.emplace_after(it, parseValue(replaceConstant(value[i])));
+ values.emplace_back(parseValue(replaceConstant(value[i])));
}
} else {
- values.emplace_front(parseValue(value));
+ values.emplace_back(parseValue(value));
}
return values;
}
diff --git a/src/style/style_properties.cpp b/src/style/style_properties.cpp
index f2b5af651e..3d6bc41b81 100644
--- a/src/style/style_properties.cpp
+++ b/src/style/style_properties.cpp
@@ -1,6 +1,6 @@
-#include <llmr/style/style_properties.hpp>
+#include <mbgl/style/style_properties.hpp>
-namespace llmr {
+namespace mbgl {
template<> const FillProperties &defaultStyleProperties() { static const FillProperties p; return p; }
template<> const LineProperties &defaultStyleProperties() { static const LineProperties p; return p; }
diff --git a/src/style/value.cpp b/src/style/value.cpp
index f41acb3a06..5cd32376ab 100644
--- a/src/style/value.cpp
+++ b/src/style/value.cpp
@@ -1,4 +1,4 @@
-#include <llmr/style/value.hpp>
+#include <mbgl/style/value.hpp>
#pragma GCC diagnostic push
#ifndef __clang__
@@ -7,7 +7,7 @@
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic pop
-llmr::Value llmr::parseValue(pbf data) {
+mbgl::Value mbgl::parseValue(pbf data) {
while (data.next())
{
switch (data.tag)
@@ -34,7 +34,7 @@ llmr::Value llmr::parseValue(pbf data) {
return false;
}
-std::string llmr::toString(const llmr::Value& value) {
+std::string mbgl::toString(const mbgl::Value& value) {
if (value.is<std::string>()) return value.get<std::string>();
else if (value.is<bool>()) return value.get<bool>() ? "true" : "false";
else if (value.is<int64_t>()) return std::to_string(value.get<int64_t>());