encapsulate factory/preset alloc in one method.

throw typed exception in allocate()
This commit is contained in:
carm
2012-11-11 23:11:21 -05:00
parent 176fad1b79
commit c4d44203de
3 changed files with 29 additions and 11 deletions

View File

@ -136,11 +136,7 @@ std::auto_ptr<Preset> PresetLoader::loadPreset ( unsigned int index ) const
// Check that index isn't insane
assert ( index >= 0 );
assert ( index < _entries.size() );
// Return a new autopointer to a preset
const std::string extension = parseExtension ( _entries[index] );
return _presetFactoryManager.factory(extension).allocate
return _presetFactoryManager.allocate
( _entries[index], _presetNames[index] );
}
@ -149,13 +145,17 @@ std::auto_ptr<Preset> PresetLoader::loadPreset ( unsigned int index ) const
std::auto_ptr<Preset> PresetLoader::loadPreset ( const std::string & url ) const
{
// Return a new autopointer to a preset
const std::string extension = parseExtension ( url );
/// @bug probably should not use url for preset name
return _presetFactoryManager.factory(extension).allocate
(url, url);
try {
/// @bug probably should not use url for preset name
return _presetFactoryManager.allocate
(url, url);
} catch (const std::exception & e) {
throw PresetFactoryException(e.what());
} catch (...) {
throw PresetFactoryException("preset factory exception of unknown cause");
}
return std::auto_ptr<Preset>();
}
void PresetLoader::handleDirectoryError()