#include #include #include #include namespace node_mbgl { template struct ValueConverter {}; template <> struct ValueConverter { mbgl::optional> operator()(const v8::Local& value) const { if (!value->IsBoolean()) { Nan::ThrowTypeError("boolean required"); return {}; } return { value->BooleanValue() }; } }; template <> struct ValueConverter { mbgl::optional> operator()(const v8::Local& value) const { if (!value->IsNumber()) { Nan::ThrowTypeError("number required"); return {}; } return { float(value->NumberValue()) }; } }; template <> struct ValueConverter { mbgl::optional> operator()(const v8::Local& value) const { if (!value->IsString()) { Nan::ThrowTypeError("string required"); return {}; } return { std::string(*Nan::Utf8String(value)) }; } }; template struct ValueConverter::value>> { mbgl::optional> operator()(const v8::Local& value) const { if (!value->IsString()) { Nan::ThrowTypeError("string required"); return {}; } mbgl::optional result = mbgl::Enum::toEnum(*Nan::Utf8String(value)); if (!result) { Nan::ThrowTypeError("invalid enumeration value"); return {}; } return { *result }; } }; template <> struct ValueConverter { mbgl::optional> operator()(const v8::Local& value) const { if (!value->IsString()) { Nan::ThrowTypeError("string required"); return {}; } mbgl::optional result = mbgl::Color::parse(*Nan::Utf8String(value)); if (!result) { Nan::ThrowTypeError("invalid color"); return {}; } return { *result }; } }; template <> struct ValueConverter> { mbgl::optional>> operator()(const v8::Local& value) const { (void)value; return {}; } }; template <> struct ValueConverter> { mbgl::optional>> operator()(const v8::Local& value) const { (void)value; return {}; } }; template <> struct ValueConverter> { mbgl::optional>> operator()(const v8::Local& value) const { (void)value; return {}; } }; template <> struct ValueConverter> { mbgl::optional>> operator()(const v8::Local& value) const { (void)value; return {}; } }; using PropertySetter = std::function&)>; using PropertySetters = std::unordered_map; template PropertySetter makePropertySetter(void (L::*setter)(mbgl::style::PropertyValue)) { return [setter] (mbgl::style::Layer& layer, const v8::Local& value) { L* typedLayer = layer.as(); if (!typedLayer) { Nan::ThrowTypeError("layer doesn't support this property"); return false; } mbgl::optional> typedValue; if (value->IsNull() || value->IsUndefined()) { typedValue = mbgl::style::PropertyValue(); } else { typedValue = ValueConverter()(value); } if (!typedValue) { return false; } (typedLayer->*setter)(*typedValue); return true; }; } }