| 167 | } |
| 168 | |
| 169 | class CompoundObjectFromPythonDict |
| 170 | { |
| 171 | public : |
| 172 | |
| 173 | CompoundObjectFromPythonDict() |
| 174 | { |
| 175 | converter::registry::push_back( |
| 176 | &convertible, |
| 177 | &construct, |
| 178 | type_id<CompoundObjectPtr> () |
| 179 | ); |
| 180 | } |
| 181 | |
| 182 | private : |
| 183 | |
| 184 | static void *convertible( PyObject *obj_ptr ) |
| 185 | { |
| 186 | if ( !PyDict_Check( obj_ptr ) ) |
| 187 | { |
| 188 | return nullptr; |
| 189 | } |
| 190 | return obj_ptr; |
| 191 | } |
| 192 | |
| 193 | static void construct( |
| 194 | PyObject *obj_ptr, |
| 195 | converter::rvalue_from_python_stage1_data *data ) |
| 196 | { |
| 197 | assert( obj_ptr ); |
| 198 | assert( PyDict_Check( obj_ptr ) ); |
| 199 | |
| 200 | handle<> h( borrowed(obj_ptr) ); |
| 201 | dict d( h ); |
| 202 | |
| 203 | void* storage = (( converter::rvalue_from_python_storage<CompoundObjectPtr>* ) data )->storage.bytes; |
| 204 | new( storage ) CompoundObjectPtr( compoundObjectFromDict( d ) ); |
| 205 | data->convertible = storage; |
| 206 | } |
| 207 | |
| 208 | static CompoundObjectPtr compoundObjectFromDict( const dict &v ) |
| 209 | { |
| 210 | CompoundObjectPtr x = new CompoundObject(); |
| 211 | list keys = v.keys(); |
| 212 | int len = boost::python::len(v); |
| 213 | object key,value; |
| 214 | for (int i = 0; i < len; i++) |
| 215 | { |
| 216 | key = keys[i]; |
| 217 | value = v[key]; |
| 218 | extract<InternedString> keyElem(key); |
| 219 | if (!keyElem.check()) |
| 220 | { |
| 221 | PyErr_SetString(PyExc_TypeError, "Incompatible key type. Only strings accepted."); |
| 222 | throw_error_already_set(); |
| 223 | } |
| 224 | |
| 225 | extract< Object& > valueElem(value); |
| 226 | if (valueElem.check()) |
no outgoing calls
no test coverage detected