#pragma once #include #include #include #include #include #include namespace mbgl { namespace style { namespace conversion { class Value; using ValueMap = std::unordered_map; using ValueVector = std::vector; class Value : public mbgl::variant, mapbox::util::recursive_wrapper> { using variant::variant; }; inline bool isUndefined(const Value&) { //Variant is always intialized return false; } inline bool isArray(const Value& value) { return value.is>(); } inline std::size_t arrayLength(const Value& value) { return value.get>().get().size(); } inline Value arrayMember(const Value& value, std::size_t i) { return value.get>().get()[i]; } inline bool isObject(const Value& value) { return value.is>(); } inline optional objectMember(const Value& value, const char* key) { auto map = value.get(); auto iter = map.find(key); if (iter != map.end()) { return iter->second; } else { return {}; } } using EachMemberFn = std::function(const std::string&, const Value&)>; optional eachMember(const Value& value, EachMemberFn&& fn) { auto map = value.get(); auto iter = map.begin(); while (iter != map.end()) { optional result = fn(iter->first, iter->second); if (result) { return result; } ++iter; } return {}; } inline optional toBool(const Value& value) { if (value.is()) { return value.get(); } else { return {}; } } inline optional toNumber(const Value& value) { if (value.is()) { return value.get(); } else { return {}; } return {}; } inline optional toString(const Value& value) { if (value.is()) { return value.get(); } else { return {}; } } inline optional toValue(const Value& value) { if (value.is()) { return { value.get() }; } else if (value.is()) { return { value.get() }; } else if (value.is()) { return { value.get() }; } else { return {}; } } } // namespace conversion } // namespace style } // namespace mbgl