summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Wojciechowski <lucas@mapbox.com>2018-04-23 14:48:57 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-05-09 16:08:50 -0700
commit5f69284f22e6639e1b86319944a5262892d1b599 (patch)
treedf5be92015c439f786b4b9eb5b54108694abe317
parent8dd21f0107180ce3837a7c2edf551e5be575e1dc (diff)
downloadqtlocation-mapboxgl-5f69284f22e6639e1b86319944a5262892d1b599.tar.gz
Add `createLiteral` convenience method
-rw-r--r--include/mbgl/style/expression/literal.hpp3
-rw-r--r--src/mbgl/style/expression/literal.cpp8
-rw-r--r--test/style/conversion/stringify.test.cpp7
3 files changed, 16 insertions, 2 deletions
diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp
index a00c468efc..d3b3a20cce 100644
--- a/include/mbgl/style/expression/literal.hpp
+++ b/include/mbgl/style/expression/literal.hpp
@@ -51,6 +51,9 @@ private:
Value value;
};
+std::unique_ptr<Literal> createLiteral(const char* value);
+std::unique_ptr<Literal> createLiteral(Value value);
+
} // namespace expression
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/expression/literal.cpp b/src/mbgl/style/expression/literal.cpp
index 8a63980dba..f68cfd5cf5 100644
--- a/src/mbgl/style/expression/literal.cpp
+++ b/src/mbgl/style/expression/literal.cpp
@@ -109,6 +109,14 @@ mbgl::Value Literal::serialize() const {
return *fromExpressionValue<mbgl::Value>(value);
}
}
+
+std::unique_ptr<Literal> createLiteral(const char* value) {
+ return createLiteral(std::string(value));
+}
+
+std::unique_ptr<Literal> createLiteral(Value value) {
+ return std::make_unique<Literal>(value);
+}
} // namespace expression
} // namespace style
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp
index 851301d515..c3faf1f838 100644
--- a/test/style/conversion/stringify.test.cpp
+++ b/test/style/conversion/stringify.test.cpp
@@ -1,5 +1,6 @@
#include <mbgl/test/util.hpp>
+#include <mbgl/style/expression/literal.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
@@ -75,10 +76,12 @@ TEST(Stringify, Value) {
}
TEST(Stringify, Filter) {
+ using namespace mbgl::style::expression;
+
ASSERT_EQ(stringify(Filter()), "null");
- expression::ParsingContext context;
- ASSERT_EQ(stringify(Filter(expression::createCompoundExpression("filter-==", std::make_unique<expression::Literal>(std::string("a")), std::make_unique<expression::Literal>(1.0), context))), "[\"filter-==\",\"a\",1.0]");
+ ParsingContext context;
+ ASSERT_EQ(stringify(Filter(createCompoundExpression("filter-==", createLiteral("a"), createLiteral(1.0), context))), "[\"filter-==\",\"a\",1.0]");
}
TEST(Stringify, CameraFunction) {