summaryrefslogtreecommitdiff
path: root/src/mbgl/style/style_source.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/style_source.cpp')
-rw-r--r--src/mbgl/style/style_source.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/mbgl/style/style_source.cpp b/src/mbgl/style/style_source.cpp
new file mode 100644
index 0000000000..f46a6fb09b
--- /dev/null
+++ b/src/mbgl/style/style_source.cpp
@@ -0,0 +1,77 @@
+#include <mbgl/style/style_source.hpp>
+#include <mbgl/platform/platform.hpp>
+#include <mbgl/platform/log.hpp>
+
+#include <limits>
+
+namespace mbgl {
+
+void parse(const rapidjson::Value& value, std::vector<std::string>& target, const char *name) {
+ if (!value.HasMember(name))
+ return;
+
+ const rapidjson::Value& property = value[name];
+ if (!property.IsArray())
+ return;
+
+ for (rapidjson::SizeType i = 0; i < property.Size(); i++)
+ if (!property[i].IsString())
+ return;
+
+ for (rapidjson::SizeType i = 0; i < property.Size(); i++)
+ target.emplace_back(std::string(property[i].GetString(), property[i].GetStringLength()));
+}
+
+void parse(const rapidjson::Value& value, std::string& target, const char* name) {
+ if (!value.HasMember(name))
+ return;
+
+ const rapidjson::Value& property = value[name];
+ if (!property.IsString())
+ return;
+
+ target = { property.GetString(), property.GetStringLength() };
+}
+
+void parse(const rapidjson::Value& value, uint16_t& target, const char* name) {
+ if (!value.HasMember(name))
+ return;
+
+ const rapidjson::Value& property = value[name];
+ if (!property.IsUint())
+ return;
+
+ unsigned int uint = property.GetUint();
+ if (uint > std::numeric_limits<uint16_t>::max())
+ return;
+
+ target = uint;
+}
+
+template <size_t N>
+void parse(const rapidjson::Value& value, std::array<float, N>& target, const char* name) {
+ if (!value.HasMember(name))
+ return;
+
+ const rapidjson::Value& property = value[name];
+ if (!property.IsArray() || property.Size() != N)
+ return;
+
+ for (rapidjson::SizeType i = 0; i < property.Size(); i++)
+ if (!property[i].IsNumber())
+ return;
+
+ for (rapidjson::SizeType i = 0; i < property.Size(); i++)
+ target[i] = property[i].GetDouble();
+}
+
+void SourceInfo::parseTileJSONProperties(const rapidjson::Value& value) {
+ parse(value, tiles, "tiles");
+ parse(value, min_zoom, "minzoom");
+ parse(value, max_zoom, "maxzoom");
+ parse(value, attribution, "attribution");
+ parse(value, center, "center");
+ parse(value, bounds, "bounds");
+}
+
+}