Skip to content

Commit 7351ca7

Browse files
committed
move mapnik_param_to_python into mapnik_value_converter.hpp
1 parent cbf47bd commit 7351ca7

2 files changed

Lines changed: 46 additions & 46 deletions

File tree

src/mapnik_datasource.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <mapnik/feature_layer_desc.hpp>
2929
#include <mapnik/memory_datasource.hpp>
3030
#include "mapnik_value_converter.hpp"
31-
#include "python_optional.hpp"
3231
#include "create_datasource.hpp"
3332
// stl
3433
#include <vector>
@@ -49,14 +48,6 @@ namespace py = pybind11;
4948
namespace
5049
{
5150

52-
struct mapnik_param_to_python
53-
{
54-
static PyObject* convert(mapnik::value_holder const& v)
55-
{
56-
return mapnik::util::apply_visitor(value_converter(),v);
57-
}
58-
};
59-
6051
py::dict describe(std::shared_ptr<mapnik::datasource> const& ds)
6152
{
6253
py::dict description;

src/mapnik_value_converter.hpp

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,58 +25,67 @@
2525

2626
// mapnik
2727
#include <mapnik/value.hpp>
28+
#include <mapnik/params.hpp>
2829
#include <mapnik/unicode.hpp>
2930
//pybind11
3031
#include <pybind11/pybind11.h>
31-
//stl
32-
//#include <iostream>
3332

3433
namespace {
3534

36-
struct value_converter
35+
struct value_converter
36+
{
37+
PyObject * operator() (mapnik::value_integer val) const
3738
{
38-
PyObject * operator() (mapnik::value_integer val) const
39-
{
40-
return ::PyLong_FromLongLong(val);
41-
}
39+
return ::PyLong_FromLongLong(val);
40+
}
4241

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+
}
4746

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+
}
5251

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+
}
5756

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+
}
6463

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+
};
7069

70+
} // namespace
7171

72-
struct mapnik_value_to_python
72+
struct mapnik_value_to_python
73+
{
74+
static PyObject* convert(mapnik::value const& v)
7375
{
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+
8089

8190
namespace PYBIND11_NAMESPACE { namespace detail {
8291

0 commit comments

Comments
 (0)