Newer
Older
Dickon Champion
committed
#include "MantidAPI/AlgorithmManager.h"
Dickon Champion
committed
Dickon Champion
committed
namespace Mantid
Russell Taylor
committed
{
namespace API
{
/// Private Constructor for singleton class
AlgorithmManagerImpl::AlgorithmManagerImpl(): g_log(Kernel::Logger::get("AlgorithmManager")), no_of_alg(0)
std::cerr << "Algorithm Manager created." << std::endl;
g_log.debug() << "Algorithm Manager created." << std::endl;
Dickon Champion
committed
/** Private destructor
* Prevents client from calling 'delete' on the pointer handed
* out by Instance
*/
Matt Clarke
committed
AlgorithmManagerImpl::~AlgorithmManagerImpl()
std::cerr << "Algorithm Manager destroyed." << std::endl;
// g_log.debug() << "Algorithm Manager destroyed." << std::endl;
Dickon Champion
committed
/** Creates an instance of an algorithm, but does not own that instance
*
* @param algName The name of the algorithm required
* @param version The version of the algorithm required, if not defined most recent version is used -> version =-1
* @return A pointer to the created algorithm
* @throw NotFoundError Thrown if algorithm requested is not registered
*/
Algorithm_sptr AlgorithmManagerImpl::createUnmanaged(const std::string& algName,const int& version) const
return AlgorithmFactory::Instance().create(algName,version); // Throws on fail:
/** Gets the names and categories of all the currently available algorithms
*
* \return A vector of pairs of algorithm names and categories
*/
for (unsigned int i=0; i < regAlg.size(); ++i)
{
std::pair<std::string,std::string> alg(regAlg[i]->name(),regAlg[i]->category());
retVector.push_back(alg);
}
return retVector;
/** Creates an instance of an algorithm
*
* @param algName The name of the algorithm required
* @param version The version of the algorithm required, if not defined most recent version is used -> version =-1
* @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
*/
Algorithm_sptr AlgorithmManagerImpl::create(const std::string& algName, const int& version)
regAlg.push_back(AlgorithmFactory::Instance().create(algName,version)); // Throws on fail:
regAlg.back()->initialize();
}
catch(std::runtime_error& ex)
{
g_log.error()<<"AlgorithmManager:: Unable to create algorithm "<< algName <<ex.what() << std::endl;
throw std::runtime_error("AlgorithmManager:: Unable to create algorithm " + algName);
}
no_of_alg++;
return regAlg.back();
}
/// deletes all registered algorithms
Matt Clarke
committed
void AlgorithmManagerImpl::clear()
regAlg.clear();
no_of_alg=0;
Dickon Champion
committed
Russell Taylor
committed
} // namespace Mantid