diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-05-30 10:32:26 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2018-05-30 12:03:32 +0300 |
commit | 9436a95da1ec9036607c4c612c17dc5021c6cf81 (patch) | |
tree | 0b7a0c9e8dd94b8ff56ee9685d1bfde8ad226fd9 | |
parent | 2912d06cb2d96dcf6026fc16973e65bac4847385 (diff) |
[pykmlib] Added none protectionpykmlib-0.0.2
-rw-r--r-- | kml/pykmlib/bindings.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/kml/pykmlib/bindings.cpp b/kml/pykmlib/bindings.cpp index 43746966fd..4283f00257 100644 --- a/kml/pykmlib/bindings.cpp +++ b/kml/pykmlib/bindings.cpp @@ -93,6 +93,9 @@ struct LocalizableStringAdapter static void SetDict(LocalizableString & str, boost::python::dict & dict) { str.clear(); + if (dict.is_none()) + return; + auto const langs = python_list_to_std_vector<std::string>(dict.keys()); for (auto const & lang : langs) { @@ -156,6 +159,9 @@ struct PropertiesAdapter static void SetDict(Properties & props, boost::python::dict & dict) { props.clear(); + if (dict.is_none()) + return; + auto const keys = python_list_to_std_vector<std::string>(dict.keys()); for (auto const & k : keys) props[k] = extract<std::string>(dict[k]); @@ -188,6 +194,11 @@ struct VectorAdapter static void Set(std::vector<T> & v, boost::python::object const & iterable) { + if (iterable.is_none()) + { + v.clear(); + return; + } v = python_list_to_std_vector<T>(iterable); } @@ -243,8 +254,11 @@ boost::python::list VectorAdapter<m2::PointD>::Get(std::vector<m2::PointD> const template<> void VectorAdapter<m2::PointD>::Set(std::vector<m2::PointD> & v, boost::python::object const & iterable) { - auto const latLon = python_list_to_std_vector<ms::LatLon>(iterable); v.clear(); + if (iterable.is_none()) + return; + + auto const latLon = python_list_to_std_vector<ms::LatLon>(iterable); v.reserve(latLon.size()); for (size_t i = 0; i < latLon.size(); ++i) v.emplace_back(MercatorBounds::LonToX(latLon[i].lon), MercatorBounds::LatToY(latLon[i].lat)); @@ -519,8 +533,11 @@ boost::python::list GetLanguages(std::vector<int8_t> const & langs) void SetLanguages(std::vector<int8_t> & langs, boost::python::object const & iterable) { - auto const langStr = python_list_to_std_vector<std::string>(iterable); langs.clear(); + if (iterable.is_none()) + return; + + auto const langStr = python_list_to_std_vector<std::string>(iterable); langs.reserve(langStr.size()); for (auto const & lang : langStr) { |