From 6825541057d404ea89c4c24401ece8eccffca835 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 20 May 2009 00:21:29 +0000 Subject: [PATCH] fix pickling for styles since they have state and no initial args --- bindings/python/mapnik_style.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/bindings/python/mapnik_style.cpp b/bindings/python/mapnik_style.cpp index 3caa864b5..b95bfb30f 100644 --- a/bindings/python/mapnik_style.cpp +++ b/bindings/python/mapnik_style.cpp @@ -28,23 +28,45 @@ using mapnik::feature_type_style; using mapnik::rules; +using mapnik::rule_type; struct style_pickle_suite : boost::python::pickle_suite { static boost::python::tuple - getinitargs(const feature_type_style& s) + getstate(const feature_type_style& s) { - boost::python::list r; + boost::python::list rule_list; rules::const_iterator it = s.get_rules().begin(); rules::const_iterator end = s.get_rules().end(); for (; it != end; ++it) { - r.append( *it ); + rule_list.append( *it ); } - return boost::python::make_tuple(r); + return boost::python::make_tuple(rule_list); } + + static void + setstate (feature_type_style& s, boost::python::tuple state) + { + using namespace boost::python; + if (len(state) != 1) + { + PyErr_SetObject(PyExc_ValueError, + ("expected 1-item tuple in call to __setstate__; got %s" + % state).ptr() + ); + throw_error_already_set(); + } + + boost::python::list rules = extract(state[0]); + for (int i=0; i(rules[i])); + } + } + }; void export_style()