cleanup
This commit is contained in:
parent
179740a331
commit
5f1984767a
1 changed files with 20 additions and 153 deletions
|
@ -22,7 +22,10 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
|
|
||||||
#include <boost/python/suite/indexing/indexing_suite.hpp>
|
#include <boost/python/suite/indexing/indexing_suite.hpp>
|
||||||
|
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
|
||||||
|
|
||||||
#include <boost/python/iterator.hpp>
|
#include <boost/python/iterator.hpp>
|
||||||
#include <boost/python/call_method.hpp>
|
#include <boost/python/call_method.hpp>
|
||||||
#include <boost/python/tuple.hpp>
|
#include <boost/python/tuple.hpp>
|
||||||
|
@ -65,148 +68,10 @@ void __setitem__(Feature & feature, std::string const& name, mapnik::value const
|
||||||
|
|
||||||
namespace boost { namespace python {
|
namespace boost { namespace python {
|
||||||
|
|
||||||
// Forward declaration
|
// TODO mapnik.Context : implement vector_indexing_suite - we don't want to expose internal key->index mapping
|
||||||
template <class Container, bool NoProxy, class DerivedPolicies>
|
// TODO mapnik.Feature : implement map_indexing_suite
|
||||||
class map_indexing_suite2;
|
|
||||||
|
|
||||||
namespace detail
|
}}
|
||||||
{
|
|
||||||
template <class Container, bool NoProxy>
|
|
||||||
class final_map_derived_policies
|
|
||||||
: public map_indexing_suite2<Container,
|
|
||||||
NoProxy, final_map_derived_policies<Container, NoProxy> > {};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Container,bool NoProxy = false,
|
|
||||||
class DerivedPolicies = detail::final_map_derived_policies<Container, NoProxy> >
|
|
||||||
class map_indexing_suite2
|
|
||||||
: public indexing_suite<
|
|
||||||
Container
|
|
||||||
, DerivedPolicies
|
|
||||||
, NoProxy
|
|
||||||
, true
|
|
||||||
, typename Container::value_type::second_type
|
|
||||||
, typename Container::key_type
|
|
||||||
, typename Container::key_type
|
|
||||||
>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef typename Container::value_type value_type;
|
|
||||||
typedef typename Container::value_type::second_type data_type;
|
|
||||||
typedef typename Container::key_type key_type;
|
|
||||||
typedef typename Container::key_type index_type;
|
|
||||||
typedef typename Container::size_type size_type;
|
|
||||||
typedef typename Container::difference_type difference_type;
|
|
||||||
|
|
||||||
template <class Class>
|
|
||||||
static void
|
|
||||||
extension_def(Class& cl)
|
|
||||||
{
|
|
||||||
cl
|
|
||||||
.def("get", &get)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
static data_type&
|
|
||||||
get_item(Container& container, index_type i_)
|
|
||||||
{
|
|
||||||
typename Container::iterator i = container.props().find(i_);
|
|
||||||
if (i == container.end())
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_KeyError, i_.c_str());
|
|
||||||
throw_error_already_set();
|
|
||||||
}
|
|
||||||
// will be auto-converted to proper python type by `mapnik_value_to_python`
|
|
||||||
return i->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
static data_type
|
|
||||||
get(Container& container, index_type i_)
|
|
||||||
{
|
|
||||||
typename Container::iterator i = container.props().find(i_);
|
|
||||||
if (i != container.end())
|
|
||||||
{
|
|
||||||
// will be auto-converted to proper python type by `mapnik_value_to_python`
|
|
||||||
return i->second;
|
|
||||||
}
|
|
||||||
return mapnik::value_null();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_item(Container& container, index_type i, data_type const& v)
|
|
||||||
{
|
|
||||||
container[i] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
delete_item(Container& container, index_type i)
|
|
||||||
{
|
|
||||||
container.props().erase(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t
|
|
||||||
size(Container& container)
|
|
||||||
{
|
|
||||||
return container.props().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
contains(Container& container, key_type const& key)
|
|
||||||
{
|
|
||||||
return container.props().find(key) != container.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
compare_index(Container& container, index_type a, index_type b)
|
|
||||||
{
|
|
||||||
return container.props().key_comp()(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static index_type
|
|
||||||
convert_index(Container& /*container*/, PyObject* i_)
|
|
||||||
{
|
|
||||||
extract<key_type const&> i(i_);
|
|
||||||
if (i.check())
|
|
||||||
{
|
|
||||||
return i();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
extract<key_type> i(i_);
|
|
||||||
if (i.check())
|
|
||||||
return i();
|
|
||||||
}
|
|
||||||
|
|
||||||
PyErr_SetString(PyExc_TypeError, "Invalid index type");
|
|
||||||
throw_error_already_set();
|
|
||||||
return index_type();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
struct std_pair_to_tuple
|
|
||||||
{
|
|
||||||
static PyObject* convert(std::pair<T1, T2> const& p)
|
|
||||||
{
|
|
||||||
return boost::python::incref(
|
|
||||||
boost::python::make_tuple(p.first, p.second).ptr());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
struct std_pair_to_python_converter
|
|
||||||
{
|
|
||||||
std_pair_to_python_converter()
|
|
||||||
{
|
|
||||||
boost::python::to_python_converter<
|
|
||||||
std::pair<T1, T2>,
|
|
||||||
std_pair_to_tuple<T1, T2> >();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}}
|
|
||||||
|
|
||||||
struct UnicodeString_from_python_str
|
struct UnicodeString_from_python_str
|
||||||
{
|
{
|
||||||
|
@ -267,31 +132,33 @@ void export_feature()
|
||||||
using namespace boost::python;
|
using namespace boost::python;
|
||||||
using mapnik::Feature;
|
using mapnik::Feature;
|
||||||
|
|
||||||
|
// Python to mapnik::value convrters
|
||||||
implicitly_convertible<int,mapnik::value>();
|
implicitly_convertible<int,mapnik::value>();
|
||||||
implicitly_convertible<double,mapnik::value>();
|
implicitly_convertible<double,mapnik::value>();
|
||||||
implicitly_convertible<UnicodeString,mapnik::value>();
|
implicitly_convertible<UnicodeString,mapnik::value>();
|
||||||
implicitly_convertible<bool,mapnik::value>();
|
implicitly_convertible<bool,mapnik::value>();
|
||||||
|
|
||||||
std_pair_to_python_converter<std::string const,mapnik::value>();
|
//std_pair_to_python_converter<std::string const,mapnik::value>();
|
||||||
UnicodeString_from_python_str();
|
UnicodeString_from_python_str();
|
||||||
|
|
||||||
class_<context,context_ptr,boost::noncopyable>
|
class_<context,context_ptr,boost::noncopyable>
|
||||||
("Context",init<>("Default ctor."))
|
("Context",init<>("Default ctor."))
|
||||||
.def("push", &context::push)
|
.def("push", &context::push)
|
||||||
|
// TODO .def("__iter__", .....)
|
||||||
;
|
;
|
||||||
|
|
||||||
class_<Feature,boost::shared_ptr<Feature>,
|
class_<Feature,boost::shared_ptr<Feature>,
|
||||||
boost::noncopyable>("Feature",init<context_ptr,int>("Default ctor."))
|
boost::noncopyable>("Feature",init<context_ptr,int>("Default ctor."))
|
||||||
.def("id",&Feature::id)
|
.def("id",&Feature::id)
|
||||||
.def("__str__",&Feature::to_string)
|
.def("__str__",&Feature::to_string)
|
||||||
.def("add_geometries_from_wkb", &feature_add_geometries_from_wkb)
|
.def("add_geometries_from_wkb", &feature_add_geometries_from_wkb)
|
||||||
.def("add_geometries_from_wkt", &feature_add_geometries_from_wkt)
|
.def("add_geometries_from_wkt", &feature_add_geometries_from_wkt)
|
||||||
.def("add_geometry", &Feature::add_geometry)
|
.def("add_geometry", &Feature::add_geometry)
|
||||||
.def("num_geometries",&Feature::num_geometries)
|
.def("num_geometries",&Feature::num_geometries)
|
||||||
.def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>()))
|
.def("get_geometry", make_function(get_geom1,return_value_policy<reference_existing_object>()))
|
||||||
.def("geometries",make_function(&Feature::paths,return_value_policy<reference_existing_object>()))
|
.def("geometries",make_function(&Feature::paths,return_value_policy<reference_existing_object>()))
|
||||||
.def("envelope", &Feature::envelope)
|
.def("envelope", &Feature::envelope)
|
||||||
.def("__setitem__",&__setitem__)
|
.def("__setitem__",&__setitem__)
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
// .def(map_indexing_suite2<Feature, true >())
|
// .def(map_indexing_suite2<Feature, true >())
|
||||||
|
|
Loading…
Reference in a new issue