binding for pop method
| 374 | |
| 375 | /// binding for pop method |
| 376 | static data_type |
| 377 | pop( CompoundData &x, PyObject *i, PyObject *v ) |
| 378 | { |
| 379 | key_type key = convertKey( x, i ); |
| 380 | const CompoundDataMap &xData = x.readable(); |
| 381 | CompoundDataMap::const_iterator value = xData.find( key ); |
| 382 | if ( value == xData.end() ) |
| 383 | { |
| 384 | if ( v == Py_None ) |
| 385 | { |
| 386 | PyErr_SetString( PyExc_KeyError, key ); |
| 387 | throw_error_already_set(); |
| 388 | } |
| 389 | extract<data_type> elem( v ); |
| 390 | if ( elem.check() ) |
| 391 | { |
| 392 | return elem(); |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | PyErr_SetString( PyExc_TypeError, "Invalid parameter" ); |
| 397 | throw_error_already_set(); |
| 398 | } |
| 399 | return data_type(); |
| 400 | } |
| 401 | // save the returning value. |
| 402 | data_type ret( value->second ); |
| 403 | // delete it from the map |
| 404 | CompoundDataMap &writableX = x.writable(); |
| 405 | CompoundDataMap::iterator writableValue = writableX.find( key ); |
| 406 | writableX.erase( writableValue ); |
| 407 | return ret; |
| 408 | } |
| 409 | |
| 410 | /// binding for popitem method |
| 411 | static boost::python::tuple |