Newer
Older
Dickon Champion
committed
#include "IAlgorithm.h"
#include "StatusCode.h"
#include "AlgorithmManager.h"
Dickon Champion
committed
namespace Mantid
Russell Taylor
committed
{
namespace Kernel
Dickon Champion
committed
{
Dickon Champion
committed
AlgorithmManager* AlgorithmManager::m_instance = 0;
/// Private Constructor for singleton class
AlgorithmManager::AlgorithmManager() : DynamicFactory<IAlgorithm>(),
no_of_alg(0)
Dickon Champion
committed
{
}
/** Private destructor
* Prevents client from calling 'delete' on the pointer handed
* out by Instance
*/
Dickon Champion
committed
AlgorithmManager::~AlgorithmManager()
{
/** Creates an instance of an algorithm, but does not own that instance
*
* @param algName The name of the algorithm required
* @return A pointer to the created algorithm
* @throw NotFoundError Thrown if algorithm requested is not registered
*/
IAlgorithm* AlgorithmManager::createUnmanaged(const std::string& algName) const
{
return DynamicFactory<IAlgorithm>::create(algName); // Throws on fail:
Dickon Champion
committed
}
/** Creates an instance of an algorithm
*
* @param algName The name of the algorithm required
* @return A pointer to the created algorithm
* @throw NotFoundError Thrown if algorithm requested is not registered
* @throw std::runtime_error Thrown if properties string is ill-formed
*/
Dickon Champion
committed
{
regAlg.push_back(DynamicFactory<IAlgorithm>::create(algName)); // Throws on fail:
if (status.isFailure())
{
throw std::runtime_error("AlgorithmManager:: Unable to initialise algorithm " + algName);
}
no_of_alg++;
return regAlg.back();
Dickon Champion
committed
}
/** A static method which retrieves the single instance of the Algorithm Manager
*
* @returns A pointer to the Algorithm Manager instance
*/
Dickon Champion
committed
AlgorithmManager* AlgorithmManager::Instance()
{
if (!m_instance) m_instance = new AlgorithmManager;
return m_instance;
Dickon Champion
committed
}
/// Finalizes and deletes all registered algorithms
Dickon Champion
committed
void AlgorithmManager::clear()
{
int errOut(0);
std::vector<IAlgorithm*>::iterator vc;
for(vc=regAlg.begin();vc!=regAlg.end();vc++)
{
// no test for zero since impossible
StatusCode status = (*vc)->finalize();
errOut+= status.isFailure();
delete (*vc);
Dickon Champion
committed
}
regAlg.clear();
no_of_alg=0;
if (errOut) throw std::runtime_error("AlgorithmManager:: Unable to finalise algorithm " );
return;
}
Russell Taylor
committed
} // namespace Kernel
} // namespace Mantid