Work around ugly boost python bug.
This commit is contained in:
parent
c28582a23c
commit
7088f972e5
2 changed files with 49 additions and 12 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <mapnik/expression_string.hpp>
|
||||
#include <mapnik/text_symbolizer.hpp>
|
||||
#include "mapnik_threads.hpp"
|
||||
#include "python_optional.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
||||
|
@ -390,26 +391,26 @@ void export_text_placement()
|
|||
register_ptr_to_python<boost::shared_ptr<formating::text_node> >();
|
||||
|
||||
|
||||
class_<FormatNodeWrap,
|
||||
class_with_optional<FormatNodeWrap,
|
||||
boost::shared_ptr<FormatNodeWrap>,
|
||||
bases<formating::node>,
|
||||
boost::noncopyable>
|
||||
("FormatingFormatNode")
|
||||
.def_readwrite_optional("text_size", &formating::format_node::text_size)
|
||||
.def_readwrite_optional("face_name", &formating::format_node::face_name)
|
||||
.def_readwrite_optional("character_spacing", &formating::format_node::character_spacing)
|
||||
.def_readwrite_optional("line_spacing", &formating::format_node::line_spacing)
|
||||
.def_readwrite_optional("text_opacity", &formating::format_node::text_opacity)
|
||||
.def_readwrite_optional("wrap_char", &formating::format_node::wrap_char)
|
||||
.def_readwrite_optional("wrap_before", &formating::format_node::wrap_before)
|
||||
.def_readwrite_optional("text_transform", &formating::format_node::text_transform)
|
||||
.def_readwrite_optional("fill", &formating::format_node::fill)
|
||||
.def_readwrite_optional("halo_fill", &formating::format_node::halo_fill)
|
||||
.def_readwrite_optional("halo_radius", &formating::format_node::halo_radius)
|
||||
.def("apply", &formating::format_node::apply, &FormatNodeWrap::default_apply)
|
||||
.add_property("child",
|
||||
&formating::format_node::get_child,
|
||||
&formating::format_node::set_child)
|
||||
.def_readwrite("face_name", &formating::format_node::face_name)
|
||||
.def_readwrite("text_size", &formating::format_node::text_size)
|
||||
.def_readwrite("character_spacing", &formating::format_node::character_spacing)
|
||||
.def_readwrite("line_spacing", &formating::format_node::line_spacing)
|
||||
.def_readwrite("text_opacity", &formating::format_node::text_opacity)
|
||||
.def_readwrite("wrap_char", &formating::format_node::wrap_char)
|
||||
.def_readwrite("wrap_before", &formating::format_node::wrap_before)
|
||||
.def_readwrite("text_transform", &formating::format_node::text_transform)
|
||||
.def_readwrite("fill", &formating::format_node::fill)
|
||||
.def_readwrite("halo_fill", &formating::format_node::halo_fill)
|
||||
.def_readwrite("halo_radius", &formating::format_node::halo_radius)
|
||||
;
|
||||
register_ptr_to_python<boost::shared_ptr<formating::format_node> >();
|
||||
}
|
||||
|
|
|
@ -100,3 +100,39 @@ struct python_optional : public boost::noncopyable
|
|||
}
|
||||
};
|
||||
|
||||
/** This class works around a bug in boost python.
|
||||
|
||||
See http://osdir.com/ml/python.c++/2003-11/msg00158.html
|
||||
*/
|
||||
template <typename T, typename X1, typename X2, typename X3>
|
||||
class class_with_optional : public boost::python::class_<T, X1, X2, X3>
|
||||
{
|
||||
public:
|
||||
typedef class_with_optional<T,X1,X2,X3> self;
|
||||
// Construct with the class name, with or without docstring, and default __init__() function
|
||||
class_with_optional(char const* name, char const* doc = 0) : boost::python::class_<T, X1, X2, X3>(name, doc) { }
|
||||
|
||||
// Construct with class name, no docstring, and an uncallable __init__ function
|
||||
class_with_optional(char const* name, boost::python::no_init_t y) : boost::python::class_<T, X1, X2, X3>(name, y) { }
|
||||
|
||||
// Construct with class name, docstring, and an uncallable __init__ function
|
||||
class_with_optional(char const* name, char const* doc, boost::python::no_init_t y) : boost::python::class_<T, X1, X2, X3>(name, doc, y) { }
|
||||
|
||||
// Construct with class name and init<> function
|
||||
template <class DerivedT> class_with_optional(char const* name, boost::python::init_base<DerivedT> const& i)
|
||||
: boost::python::class_<T, X1, X2, X3>(name, i) { }
|
||||
|
||||
// Construct with class name, docstring and init<> function
|
||||
template <class DerivedT>
|
||||
inline class_with_optional(char const* name, char const* doc, boost::python::init_base<DerivedT> const& i)
|
||||
: boost::python::class_<T, X1, X2, X3>(name, doc, i) { }
|
||||
|
||||
template <class D>
|
||||
self& def_readwrite_optional(char const* name, D const& d, char const* doc=0)
|
||||
{
|
||||
this->add_property(name,
|
||||
make_getter(d, boost::python::return_value_policy<boost::python::return_by_value>()),
|
||||
make_setter(d, boost::python::default_call_policies()));
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue