+add pickle support for raster_symbolizer - see #345
This commit is contained in:
parent
a45a434f65
commit
ff36980723
1 changed files with 40 additions and 1 deletions
|
@ -24,13 +24,52 @@
|
|||
#include <boost/python.hpp>
|
||||
#include <mapnik/raster_symbolizer.hpp>
|
||||
|
||||
using mapnik::raster_symbolizer;
|
||||
|
||||
struct raster_symbolizer_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
/*
|
||||
static boost::python::tuple
|
||||
getinitargs(const raster_symbolizer& r)
|
||||
{
|
||||
return boost::python::make_tuple();
|
||||
}
|
||||
*/
|
||||
|
||||
static boost::python::tuple
|
||||
getstate(const raster_symbolizer& r)
|
||||
{
|
||||
return boost::python::make_tuple(r.get_mode(),r.get_scaling(),r.get_opacity());
|
||||
}
|
||||
|
||||
static void
|
||||
setstate (raster_symbolizer& r, boost::python::tuple state)
|
||||
{
|
||||
using namespace boost::python;
|
||||
if (len(state) != 3)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
("expected 3-item tuple in call to __setstate__; got %s"
|
||||
% state).ptr()
|
||||
);
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
r.set_mode(extract<std::string>(state[0]));
|
||||
r.set_scaling(extract<std::string>(state[1]));
|
||||
r.set_opacity(extract<float>(state[2]));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void export_raster_symbolizer()
|
||||
{
|
||||
using namespace boost::python;
|
||||
using mapnik::raster_symbolizer;
|
||||
|
||||
class_<raster_symbolizer>("RasterSymbolizer",
|
||||
init<>("Default ctor"))
|
||||
|
||||
.def_pickle(raster_symbolizer_pickle_suite())
|
||||
|
||||
.add_property("mode",
|
||||
make_function(&raster_symbolizer::get_mode,return_value_policy<copy_const_reference>()),
|
||||
|
|
Loading…
Add table
Reference in a new issue