From a18d6dda5de5247b14611a3bd901fdf65e13beeb Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 19 Jun 2016 20:05:05 -0700 Subject: [core] Rewrite style parsing logic for reuse in node bindings --- src/mbgl/style/property_parsing.cpp | 128 ------------------------------------ 1 file changed, 128 deletions(-) (limited to 'src/mbgl/style/property_parsing.cpp') diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 263516f201..16ce0f4adc 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -1,136 +1,8 @@ #include -#include - namespace mbgl { namespace style { -template <> -optional parseConstant(const char* name, const JSValue& value) { - if (!value.IsBool()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be a boolean", name); - return {}; - } - - return value.GetBool(); -} - -template <> -optional parseConstant(const char* name, const JSValue& value) { - if (!value.IsNumber()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be a number, or a number function", name); - return {}; - } - - return value.GetDouble(); -} - -template <> -optional parseConstant(const char* name, const JSValue& value) { - if (!value.IsString()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); - return {}; - } - - return std::string { value.GetString(), value.GetStringLength() }; -} - -template <> -optional parseConstant(const char* name, const JSValue& value) { - if (!value.IsString()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name); - return {}; - } - - optional result = Color::parse({ value.GetString(), value.GetStringLength() }); - if (!result) { - Log::Warning(Event::ParseStyle, "value of '%s' must be a valid color", name); - return {}; - } - - return result; -} - -template <> -optional> parseConstant(const char* name, const JSValue& value) { - if (value.IsArray() && value.Size() == 2 && - value[rapidjson::SizeType(0)].IsNumber() && - value[rapidjson::SizeType(1)].IsNumber()) { - - float first = value[rapidjson::SizeType(0)].GetDouble(); - float second = value[rapidjson::SizeType(1)].GetDouble(); - return { {{ first, second }} }; - } else { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of two numbers", name); - return {}; - } -} - -template <> -optional> parseConstant(const char* name, const JSValue& value) { - if (value.IsArray() && value.Size() == 4 && - value[rapidjson::SizeType(0)].IsNumber() && - value[rapidjson::SizeType(1)].IsNumber() && - value[rapidjson::SizeType(2)].IsNumber() && - value[rapidjson::SizeType(3)].IsNumber()) { - - float first = value[rapidjson::SizeType(0)].GetDouble(); - float second = value[rapidjson::SizeType(1)].GetDouble(); - float third = value[rapidjson::SizeType(2)].GetDouble(); - float fourth = value[rapidjson::SizeType(3)].GetDouble(); - return { {{ first, second, third, fourth }} }; - } else { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of four numbers", name); - return {}; - } -} - -template <> -optional> parseConstant(const char* name, const JSValue& value) { - if (!value.IsArray()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name); - return {}; - } - - std::vector result; - - for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSValue& part = value[i]; - - if (!part.IsNumber()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", name); - return {}; - } - - result.push_back(part.GetDouble()); - } - - return result; -} - -template <> -optional> parseConstant(const char* name, const JSValue& value) { - if (!value.IsArray()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); - return {}; - } - - std::vector result; - - for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - const JSValue& part = value[i]; - - if (!part.IsString()) { - Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name); - return {}; - } - - result.push_back({ part.GetString(), part.GetStringLength() }); - } - - return result; -} - optional parseTransitionOptions(const char *, const JSValue& value) { if (!value.IsObject()) { return {}; -- cgit v1.2.1