#pragma once #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace style { namespace conversion { template void stringify(Writer& writer, NullValue) { writer.Null(); } template void stringify(Writer& writer, bool v) { writer.Bool(v); } template void stringify(Writer& writer, uint64_t v) { writer.Uint64(v); } template void stringify(Writer& writer, int64_t v) { writer.Int64(v); } template void stringify(Writer& writer, double v) { writer.Double(v); } template void stringify(Writer& writer, const std::string& v) { writer.String(v); } template ::value>> void stringify(Writer& writer, const T& v) { writer.String(Enum::toString(v)); } template void stringify(Writer& writer, const Color& v) { writer.String(v.stringify()); } template void stringify(Writer& writer, const std::array& v) { writer.StartArray(); writer.Double(v[0]); writer.Double(v[1]); writer.EndArray(); } template void stringify(Writer& writer, const std::array& v) { writer.StartArray(); writer.Double(v[0]); writer.Double(v[1]); writer.Double(v[2]); writer.Double(v[3]); writer.EndArray(); } template void stringify(Writer&, const Value&); template void stringify(Writer& writer, const std::vector& v) { writer.StartArray(); for (const auto& e : v) { stringify(writer, e); } writer.EndArray(); } template void stringify(Writer& writer, const std::unordered_map& m) { writer.StartObject(); for (const auto& p : m) { writer.Key(p.first.data(), static_cast(p.first.size())); stringify(writer, p.second); } writer.EndObject(); } template void stringify(Writer& writer, const Value& v) { Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); }); } template void stringify(Writer& writer, FeatureType type) { switch (type) { case FeatureType::Unknown: writer.String("Unknown"); break; case FeatureType::Point: writer.String("Point"); break; case FeatureType::LineString: writer.String("LineString"); break; case FeatureType::Polygon: writer.String("Polygon"); break; } } template void stringify(Writer& writer, const FeatureIdentifier& id) { FeatureIdentifier::visit(id, [&] (const auto& id_) { stringify(writer, id_); }); } template void stringify(Writer& writer, const Filter& filter) { if (!filter.expression) writer.Null(); else stringify(writer, (*filter.expression)->serialize()); } template void stringify(Writer& writer, const Undefined&) { assert(false); // Should be omitted entirely instead. writer.Null(); } template void stringify(Writer& writer, const CameraFunction& fn) { stringify(writer, fn.getExpression().serialize()); } template void stringify(Writer& writer, const SourceFunction& fn) { stringify(writer, fn.getExpression().serialize()); } template void stringify(Writer& writer, const CompositeFunction& fn) { stringify(writer, fn.getExpression().serialize()); } template void stringify(Writer& writer, const PropertyValue& v) { v.evaluate([&] (const auto& v_) { stringify(writer, v_); }); } template void stringify(Writer& writer, const PropertyValue& value) { if (!value.isUndefined()) { writer.Key(Property::key); stringify(writer, value); } } template void stringify(Writer& writer, const DataDrivenPropertyValue& v) { v.evaluate([&] (const auto& v_) { stringify(writer, v_); }); } template void stringify(Writer& writer, const DataDrivenPropertyValue& value) { if (!value.isUndefined()) { writer.Key(Property::key); stringify(writer, value); } } } // namespace conversion } // namespace style } // namespace mbgl