python: make feature attribute access more pythonic

This commit is contained in:
Dane Springmeyer 2011-12-02 15:08:56 -08:00
parent 7abee1fd47
commit 00707d02ff

View file

@ -94,9 +94,11 @@ namespace boost { namespace python {
template <class Class>
static void
extension_def(Class& /*cl*/)
extension_def(Class& cl)
{
cl
.def("get", &get)
;
}
static data_type&
@ -105,13 +107,25 @@ namespace boost { namespace python {
typename Container::iterator i = container.props().find(i_);
if (i == container.end())
{
PyErr_SetString(PyExc_KeyError, "Invalid key");
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)
{