------------------------------------------------------------------------------------------------ Reads the given file and returns its contents if successful.
| 585 | // ------------------------------------------------------------------------------------------------ |
| 586 | // Reads the given file and returns its contents if successful. |
| 587 | const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) { |
| 588 | ai_assert(nullptr != pimpl); |
| 589 | |
| 590 | ASSIMP_BEGIN_EXCEPTION_REGION(); |
| 591 | const std::string pFile(_pFile); |
| 592 | |
| 593 | // ---------------------------------------------------------------------- |
| 594 | // Put a large try block around everything to catch all std::exception's |
| 595 | // that might be thrown by STL containers or by new(). |
| 596 | // ImportErrorException's are throw by ourselves and caught elsewhere. |
| 597 | //----------------------------------------------------------------------- |
| 598 | |
| 599 | WriteLogOpening(pFile); |
| 600 | |
| 601 | #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS |
| 602 | try |
| 603 | #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS |
| 604 | { |
| 605 | // Check whether this Importer instance has already loaded |
| 606 | // a scene. In this case we need to delete the old one |
| 607 | if (pimpl->mScene) { |
| 608 | |
| 609 | ASSIMP_LOG_DEBUG("(Deleting previous scene)"); |
| 610 | FreeScene(); |
| 611 | } |
| 612 | |
| 613 | // First check if the file is accessible at all |
| 614 | if( !pimpl->mIOHandler->Exists( pFile)) { |
| 615 | |
| 616 | pimpl->mErrorString = "Unable to open file \"" + pFile + "\"."; |
| 617 | ASSIMP_LOG_ERROR(pimpl->mErrorString); |
| 618 | return nullptr; |
| 619 | } |
| 620 | |
| 621 | std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME, 0) ? new Profiler() : nullptr); |
| 622 | if (profiler) { |
| 623 | profiler->BeginRegion("total"); |
| 624 | } |
| 625 | |
| 626 | // Find an worker class which can handle the file extension. |
| 627 | // Multiple importers may be able to handle the same extension (.xml!); gather them all. |
| 628 | SetPropertyInteger("importerIndex", -1); |
| 629 | struct ImporterAndIndex { |
| 630 | BaseImporter * importer; |
| 631 | unsigned int index; |
| 632 | }; |
| 633 | std::vector<ImporterAndIndex> possibleImporters; |
| 634 | for (unsigned int a = 0; a < pimpl->mImporter.size(); a++) { |
| 635 | |
| 636 | // Every importer has a list of supported extensions. |
| 637 | std::set<std::string> extensions; |
| 638 | pimpl->mImporter[a]->GetExtensionList(extensions); |
| 639 | |
| 640 | if (BaseImporter::HasExtension(pFile, extensions)) { |
| 641 | ImporterAndIndex candidate = { pimpl->mImporter[a], a }; |
| 642 | possibleImporters.push_back(candidate); |
| 643 | } |
| 644 | } |
no test coverage detected