Пример #1
0
DeepImageWriterPtr DeepImageWriter::create( const std::string &fileName )
{
	std::string ext = boost::filesystem::extension( boost::filesystem::path( fileName ) );

	ExtensionsToFnsMap *m = extensionsToFns();
	ExtensionsToFnsMap::const_iterator it = m->find( ext );

	if ( it == m->end() )
	{
		throw Exception( std::string( "Unrecognized output file format '") + ext + "'!" );
	}

	for ( it=m->begin(); it != m->end(); it++ )
	{
		if ( it->first == ext )
		{
			if ( it->second.canWrite( fileName ) )
			{
				return it->second.creator( fileName );
			}
		}
	}

	throw Exception( std::string( "Unable to find DeepImageWriter able to write to file of type '") + ext + "'!" );
}
Пример #2
0
DeepImageWriterPtr DeepImageWriter::create( const std::string &fileName )
{
	/// \todo We can stop using this deprecated form when we no longer need to be compatible
	/// with boost 1.43. At that point we can use path.extension().string() and compile with
	/// BOOST_FILESYSTEM_NO_DEPRECATED.
	std::string ext = boost::filesystem::extension( boost::filesystem::path( fileName ) );

	ExtensionsToFnsMap *m = extensionsToFns();
	ExtensionsToFnsMap::const_iterator it = m->find( ext );

	if ( it == m->end() )
	{
		throw Exception( std::string( "Unrecognized output file format '") + ext + "'!" );
	}

	for ( it=m->begin(); it != m->end(); it++ )
	{
		if ( it->first == ext )
		{
			if ( it->second.canWrite( fileName ) )
			{
				return it->second.creator( fileName );
			}
		}
	}

	throw Exception( std::string( "Unable to find DeepImageWriter able to write to file of type '") + ext + "'!" );
}
Пример #3
0
void DeepImageWriter::supportedExtensions( std::vector<std::string> &extensions )
{
	extensions.clear();
	ExtensionsToFnsMap *m = extensionsToFns();
	for ( ExtensionsToFnsMap::const_iterator it=m->begin(); it != m->end(); it++ )
	{
		extensions.push_back( it->first.substr( 1 ) );
	}
}
Пример #4
0
void DeepImageWriter::supportedExtensions( TypeId typeId, std::vector<std::string> &extensions )
{
	extensions.clear();
	ExtensionsToFnsMap *m = extensionsToFns();

	const std::set< TypeId > &derivedTypes = RunTimeTyped::derivedTypeIds( typeId );

	for ( ExtensionsToFnsMap::const_iterator it=m->begin(); it != m->end(); it++ )
	{
		if ( it->second.typeId == typeId || std::find( derivedTypes.begin(), derivedTypes.end(), it->second.typeId ) != derivedTypes.end() )
		{
			extensions.push_back( it->first.substr( 1 ) );
		}
	}
}
Пример #5
0
void Reader::supportedExtensions( std::vector<std::string> &extensions )
{
	extensions.clear();
	ExtensionsToFnsMap *m = extensionsToFns();
	assert( m );

	std::set<std::string> uniqueExtensions;

	for( ExtensionsToFnsMap::const_iterator it=m->begin(); it!=m->end(); it++ )
	{
		uniqueExtensions.insert( it->first.substr( 1 ) );
	}

	extensions.resize( uniqueExtensions.size() );
	std::copy( uniqueExtensions.begin(), uniqueExtensions.end(), extensions.begin() );
}
Пример #6
0
void DeepImageWriter::registerDeepImageWriter( const std::string &extensions, CanWriteFn canWrite, CreatorFn creator, TypeId typeId )
{
	assert( canWrite );
	assert( creator );
	assert( typeId != InvalidTypeId );

	ExtensionsToFnsMap *m = extensionsToFns();
	std::vector<std::string> splitExt;
	boost::split( splitExt, extensions, boost::is_any_of( " " ) );
	DeepImageWriterFns w;
	w.creator = creator;
	w.canWrite = canWrite;
	w.typeId = typeId;
	for ( std::vector<std::string>::const_iterator it=splitExt.begin(); it != splitExt.end(); it++ )
	{
		m->insert( ExtensionsToFnsMap::value_type( "." + *it, w ) );
	}
}
Пример #7
0
void Reader::registerReader( const std::string &extensions, CanReadFn canRead, CreatorFn creator, TypeId typeId )
{
	assert( canRead );
	assert( creator );
	assert( typeId != InvalidTypeId );

	ExtensionsToFnsMap *m = extensionsToFns();
	assert( m );
	vector<string> splitExt;
	split( splitExt, extensions, is_any_of( " " ) );
	ReaderFns r;
	r.creator = creator;
	r.canRead = canRead;
	r.typeId = typeId;
	for( vector<string>::const_iterator it=splitExt.begin(); it!=splitExt.end(); it++ )
	{
		m->insert( ExtensionsToFnsMap::value_type( "." + *it, r ) );
	}
}
Пример #8
0
void Reader::supportedExtensions( TypeId typeId, std::vector<std::string> &extensions )
{
	extensions.clear();
	ExtensionsToFnsMap *m = extensionsToFns();
	assert( m );

	std::set<std::string> uniqueExtensions;

	const std::set< TypeId > &derivedTypes = RunTimeTyped::derivedTypeIds( typeId );

	for( ExtensionsToFnsMap::const_iterator it=m->begin(); it!=m->end(); it++ )
	{
		if ( it->second.typeId == typeId || std::find( derivedTypes.begin(), derivedTypes.end(), it->second.typeId ) != derivedTypes.end() )
		{
			uniqueExtensions.insert( it->first.substr( 1 ) );
		}
	}

	extensions.resize( uniqueExtensions.size() );
	std::copy( uniqueExtensions.begin(), uniqueExtensions.end(), extensions.begin() );
}
Пример #9
0
ReaderPtr Reader::create( const std::string &fileName )
{
	bool knownExtension = false;
	ExtensionsToFnsMap *m = extensionsToFns();
	assert( m );
	string ext = extension(boost::filesystem::path(fileName));
	if( ext!="" )
	{
		ExtensionsToFnsMap::const_iterator it = m->find( ext );

		if( it!=m->end() )
		{
			knownExtension = true;

			ExtensionsToFnsMap::const_iterator lastElement = m->upper_bound( ext );

			for ( ; it != lastElement; ++it )
			{
				if( it->second.canRead( fileName ) )
				{
					return it->second.creator( fileName );
				}
			}
		}
	}

	// failed to find a reader based on extension. try all canRead functions
	// as a last ditch attempt.
	for( ExtensionsToFnsMap::const_iterator it=m->begin(); it!=m->end(); it++ )
	{
		if( it->second.canRead( fileName ) )
		{
			return( it->second.creator( fileName ) );
		}
	}
	if ( knownExtension )
	{
		throw Exception( string( "Unable to load file '" ) + fileName + "'!" );
	}
	else
	{
		throw Exception( string( "Unrecognized input file format '") + ext + "'!" );
	}
}