| 1324 | } |
| 1325 | |
| 1326 | void* luabind::detail::class_rep::convert_to( |
| 1327 | LUABIND_TYPE_INFO target_type |
| 1328 | , const object_rep* obj |
| 1329 | , void* target_memory) const |
| 1330 | { |
| 1331 | // TODO: since this is a member function, we don't have to use the accesor functions for |
| 1332 | // the types and the extractor |
| 1333 | |
| 1334 | assert(obj == 0 || obj->crep() == this); |
| 1335 | |
| 1336 | int steps = 0; |
| 1337 | int offset = 0; |
| 1338 | if (!(LUABIND_TYPE_INFO_EQUAL(holder_type(), target_type)) |
| 1339 | && !(LUABIND_TYPE_INFO_EQUAL(const_holder_type(), target_type))) |
| 1340 | { |
| 1341 | steps = implicit_cast(this, target_type, offset); |
| 1342 | } |
| 1343 | |
| 1344 | // should never be called with a type that can't be cast |
| 1345 | assert((steps >= 0) && "internal error, please report"); |
| 1346 | |
| 1347 | if (LUABIND_TYPE_INFO_EQUAL(target_type, holder_type())) |
| 1348 | { |
| 1349 | if (obj == 0) |
| 1350 | { |
| 1351 | // we are trying to convert nil to a holder type |
| 1352 | m_default_construct_holder(target_memory); |
| 1353 | return target_memory; |
| 1354 | } |
| 1355 | // if the type we are trying to convert to is the holder_type |
| 1356 | // it means that his crep has a holder_type (since it would have |
| 1357 | // been invalid otherwise, and T cannot be invalid). It also means |
| 1358 | // that we need no conversion, since the holder_type is what the |
| 1359 | // object points to. |
| 1360 | return obj->ptr(); |
| 1361 | } |
| 1362 | |
| 1363 | if (LUABIND_TYPE_INFO_EQUAL(target_type, const_holder_type())) |
| 1364 | { |
| 1365 | if (obj == 0) |
| 1366 | { |
| 1367 | // we are trying to convert nil to a const holder type |
| 1368 | m_default_construct_const_holder(target_memory); |
| 1369 | return target_memory; |
| 1370 | } |
| 1371 | |
| 1372 | if (obj->flags() & object_rep::constant) |
| 1373 | { |
| 1374 | // we are holding a constant |
| 1375 | return obj->ptr(); |
| 1376 | } |
| 1377 | else |
| 1378 | { |
| 1379 | // we are holding a non-constant, we need to convert it |
| 1380 | // to a const_holder. |
| 1381 | m_const_converter(obj->ptr(), target_memory); |
| 1382 | return target_memory; |
| 1383 | } |
no test coverage detected