| 80 | } |
| 81 | |
| 82 | ReaderPtr Reader::create( const std::string &fileName ) |
| 83 | { |
| 84 | bool knownExtension = false; |
| 85 | ExtensionsToFnsMap *m = extensionsToFns(); |
| 86 | assert( m ); |
| 87 | string ext = boost::filesystem::path( fileName ).extension().string(); |
| 88 | if( ext!="" ) |
| 89 | { |
| 90 | ExtensionsToFnsMap::const_iterator it = m->find( ext ); |
| 91 | |
| 92 | if( it!=m->end() ) |
| 93 | { |
| 94 | knownExtension = true; |
| 95 | |
| 96 | ExtensionsToFnsMap::const_iterator lastElement = m->upper_bound( ext ); |
| 97 | |
| 98 | for ( ; it != lastElement; ++it ) |
| 99 | { |
| 100 | if( it->second.canRead( fileName ) ) |
| 101 | { |
| 102 | return it->second.creator( fileName ); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // failed to find a reader based on extension. try all canRead functions |
| 109 | // as a last ditch attempt. |
| 110 | for( ExtensionsToFnsMap::const_iterator it=m->begin(); it!=m->end(); it++ ) |
| 111 | { |
| 112 | if( it->second.canRead( fileName ) ) |
| 113 | { |
| 114 | return( it->second.creator( fileName ) ); |
| 115 | } |
| 116 | } |
| 117 | if ( knownExtension ) |
| 118 | { |
| 119 | throw Exception( string( "Unable to load file '" ) + fileName + "'!" ); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | throw Exception( string( "Unrecognized input file format '") + ext + "'!" ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void Reader::supportedExtensions( std::vector<std::string> &extensions ) |
| 128 | { |