|
25 | 25 |
|
26 | 26 | // mapnik |
27 | 27 | #include <mapnik/value.hpp> |
| 28 | +#include <mapnik/params.hpp> |
28 | 29 | #include <mapnik/unicode.hpp> |
29 | 30 | //pybind11 |
30 | 31 | #include <pybind11/pybind11.h> |
31 | | -//stl |
32 | | -//#include <iostream> |
33 | 32 |
|
34 | 33 | namespace { |
35 | 34 |
|
36 | | - struct value_converter |
| 35 | +struct value_converter |
| 36 | +{ |
| 37 | + PyObject * operator() (mapnik::value_integer val) const |
37 | 38 | { |
38 | | - PyObject * operator() (mapnik::value_integer val) const |
39 | | - { |
40 | | - return ::PyLong_FromLongLong(val); |
41 | | - } |
| 39 | + return ::PyLong_FromLongLong(val); |
| 40 | + } |
42 | 41 |
|
43 | | - PyObject * operator() (mapnik::value_double val) const |
44 | | - { |
45 | | - return ::PyFloat_FromDouble(val); |
46 | | - } |
| 42 | + PyObject * operator() (mapnik::value_double val) const |
| 43 | + { |
| 44 | + return ::PyFloat_FromDouble(val); |
| 45 | + } |
47 | 46 |
|
48 | | - PyObject * operator() (mapnik::value_bool val) const |
49 | | - { |
50 | | - return ::PyBool_FromLong(val); |
51 | | - } |
| 47 | + PyObject * operator() (mapnik::value_bool val) const |
| 48 | + { |
| 49 | + return ::PyBool_FromLong(val); |
| 50 | + } |
52 | 51 |
|
53 | | - PyObject * operator() (std::string const& s) const |
54 | | - { |
55 | | - return ::PyUnicode_DecodeUTF8(s.c_str(), static_cast<ssize_t>(s.length()),0); |
56 | | - } |
| 52 | + PyObject * operator() (std::string const& s) const |
| 53 | + { |
| 54 | + return ::PyUnicode_DecodeUTF8(s.c_str(), static_cast<ssize_t>(s.length()),0); |
| 55 | + } |
57 | 56 |
|
58 | | - PyObject * operator() (mapnik::value_unicode_string const& s) const |
59 | | - { |
60 | | - const char* data = reinterpret_cast<const char*>(s.getBuffer()); |
61 | | - Py_ssize_t size = static_cast<Py_ssize_t>(s.length() * sizeof(s[0])); |
62 | | - return ::PyUnicode_DecodeUTF16(data, size, nullptr, nullptr); |
63 | | - } |
| 57 | + PyObject * operator() (mapnik::value_unicode_string const& s) const |
| 58 | + { |
| 59 | + const char* data = reinterpret_cast<const char*>(s.getBuffer()); |
| 60 | + Py_ssize_t size = static_cast<Py_ssize_t>(s.length() * sizeof(s[0])); |
| 61 | + return ::PyUnicode_DecodeUTF16(data, size, nullptr, nullptr); |
| 62 | + } |
64 | 63 |
|
65 | | - PyObject * operator() (mapnik::value_null const& /*s*/) const |
66 | | - { |
67 | | - Py_RETURN_NONE; |
68 | | - } |
69 | | - }; |
| 64 | + PyObject * operator() (mapnik::value_null const& /*s*/) const |
| 65 | + { |
| 66 | + Py_RETURN_NONE; |
| 67 | + } |
| 68 | +}; |
70 | 69 |
|
| 70 | +} // namespace |
71 | 71 |
|
72 | | - struct mapnik_value_to_python |
| 72 | +struct mapnik_value_to_python |
| 73 | +{ |
| 74 | + static PyObject* convert(mapnik::value const& v) |
73 | 75 | { |
74 | | - static PyObject* convert(mapnik::value const& v) |
75 | | - { |
76 | | - return mapnik::util::apply_visitor(value_converter(),v); |
77 | | - } |
78 | | - }; |
79 | | -} |
| 76 | + return mapnik::util::apply_visitor(value_converter(),v); |
| 77 | + } |
| 78 | +}; |
| 79 | + |
| 80 | +struct mapnik_param_to_python |
| 81 | +{ |
| 82 | + static PyObject* convert(mapnik::value_holder const& v) |
| 83 | + { |
| 84 | + return mapnik::util::apply_visitor(value_converter(),v); |
| 85 | + } |
| 86 | +}; |
| 87 | + |
| 88 | + |
80 | 89 |
|
81 | 90 | namespace PYBIND11_NAMESPACE { namespace detail { |
82 | 91 |
|
|
0 commit comments