mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
python: use value_convertor to handle mapnik::parameter value_holder variant
This commit is contained in:
parent
14327b913d
commit
982d8fb321
@ -83,24 +83,13 @@ void export_label_collision_detector();
|
||||
#include <mapnik/value_error.hpp>
|
||||
#include <mapnik/save_map.hpp>
|
||||
#include "python_grid_utils.hpp"
|
||||
#include "mapnik_value_converter.hpp"
|
||||
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
#include <pycairo.h>
|
||||
static Pycairo_CAPI_t *Pycairo_CAPI;
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct mapnik_value_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v.base());
|
||||
}
|
||||
};
|
||||
}}
|
||||
|
||||
void render(const mapnik::Map& map,
|
||||
mapnik::image_32& image,
|
||||
double scale_factor = 1.0,
|
||||
@ -651,5 +640,6 @@ BOOST_PYTHON_MODULE(_mapnik)
|
||||
|
||||
register_ptr_to_python<mapnik::expression_ptr>();
|
||||
register_ptr_to_python<mapnik::path_expression_ptr>();
|
||||
to_python_converter<mapnik::value_holder,mapnik_param_to_python>();
|
||||
to_python_converter<mapnik::value,mapnik_value_to_python>();
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include <boost/implicit_cast.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
struct value_converter : public boost::static_visitor<PyObject*>
|
||||
{
|
||||
PyObject * operator() (int val) const
|
||||
@ -48,6 +49,13 @@ namespace boost { namespace python {
|
||||
return ::PyBool_FromLong(val);
|
||||
}
|
||||
|
||||
PyObject * operator() (std::string const& s) const
|
||||
{
|
||||
PyObject *obj = Py_None;
|
||||
obj = ::PyUnicode_DecodeUTF8(s.c_str(),implicit_cast<ssize_t>(s.length()),0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
PyObject * operator() (UnicodeString const& s) const
|
||||
{
|
||||
std::string buffer;
|
||||
@ -63,6 +71,25 @@ namespace boost { namespace python {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct mapnik_value_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v.base());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct mapnik_param_to_python
|
||||
{
|
||||
static PyObject* convert(mapnik::value_holder const& v)
|
||||
{
|
||||
return boost::apply_visitor(value_converter(),v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user