mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-02-24 19:55:59 +00:00
encapsulate factory/preset alloc in one method.
throw typed exception in allocate()
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
#include "NativePresetFactory/NativePresetFactory.hpp"
|
||||
#endif
|
||||
|
||||
#include "Common.hpp"
|
||||
#include <sstream>
|
||||
PresetFactoryManager::PresetFactoryManager() : _gx(0), _gy(0), initialized(false) {}
|
||||
|
||||
@ -75,6 +76,22 @@ void PresetFactoryManager::registerFactory(const std::string & extensions, Prese
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::auto_ptr<Preset> PresetFactoryManager::allocate(const std::string & url, const std::string & name)
|
||||
{
|
||||
try {
|
||||
const std::string extension = parseExtension (url);
|
||||
|
||||
return factory(extension).allocate(url, name);
|
||||
} catch (const std::exception & e) {
|
||||
throw PresetFactoryException(e.what());
|
||||
} catch (...) {
|
||||
throw PresetFactoryException("uncaught preset factory exception");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PresetFactory & PresetFactoryManager::factory(const std::string & extension) {
|
||||
|
||||
if (!_factoryMap.count(extension)) {
|
||||
|
||||
@ -48,6 +48,7 @@ class PresetFactoryManager {
|
||||
/// \param extension the file name extension to verify
|
||||
/// \returns true if a factory exists, false otherwise
|
||||
bool extensionHandled(const std::string & extension) const;
|
||||
std::auto_ptr<Preset> allocate(const std::string & url, const std::string & name);
|
||||
|
||||
private:
|
||||
int _gx, _gy;
|
||||
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user