python: use value_convertor to handle mapnik::parameter value_holder variant

This commit is contained in:
Dane Springmeyer 2011-12-02 13:37:26 -08:00
parent 14327b913d
commit 982d8fb321
2 changed files with 29 additions and 12 deletions

View File

@ -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>();
}

View File

@ -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);
}
};
}
}