python: make feature attribute access more pythonic
This commit is contained in:
parent
7abee1fd47
commit
00707d02ff
1 changed files with 17 additions and 3 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue