Commit 5cbaae9c authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Ref #10813 clang-format Framework.

parent a8266497
......@@ -11,17 +11,15 @@
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"
namespace Mantid
{
namespace API
{
/// Structure uniquely describing an algorithm with its name, category and version.
struct Algorithm_descriptor
{
std::string name;///< name
std::string category;///< category
int version;///< version
namespace Mantid {
namespace API {
/// Structure uniquely describing an algorithm with its name, category and
/// version.
struct Algorithm_descriptor {
std::string name; ///< name
std::string category; ///< category
int version; ///< version
};
//----------------------------------------------------------------------
......@@ -34,11 +32,12 @@ class Algorithm;
instances of Algorithms. It inherits most of its implementation from
the Dynamic Factory base class.
It is implemented as a singleton class.
@author Russell Taylor, Tessella Support Services plc
@date 21/09/2007
Copyright &copy; 2007-2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2007-2011 ISIS Rutherford Appleton Laboratory, NScD Oak
Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
......@@ -55,21 +54,21 @@ class Algorithm;
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_API_DLL AlgorithmFactoryImpl : public Kernel::DynamicFactory<Algorithm>
{
class MANTID_API_DLL AlgorithmFactoryImpl
: public Kernel::DynamicFactory<Algorithm> {
public:
// Unhide the base class version (to satisfy the intel compiler)
using Kernel::DynamicFactory<Algorithm>::create;
///Creates an instance of an algorithm
boost::shared_ptr<Algorithm> create(const std::string& ,const int& ) const;
/// algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally
template <class C>
std::pair<std::string,int> subscribe()
{
Kernel::Instantiator<C, Algorithm>* newI = new Kernel::Instantiator<C, Algorithm>;
/// Creates an instance of an algorithm
boost::shared_ptr<Algorithm> create(const std::string &, const int &) const;
/// algorithm factory specific function to subscribe algorithms, calls the
/// dynamic factory subscribe function internally
template <class C> std::pair<std::string, int> subscribe() {
Kernel::Instantiator<C, Algorithm> *newI =
new Kernel::Instantiator<C, Algorithm>;
return this->subscribe(newI);
}
......@@ -77,91 +76,90 @@ public:
* Subscribes an algorithm using a custom instantiator. This
* object takes ownership of the instantiator
* @param instantiator - A pointer to a custom instantiator
* @param replaceExisting - Defines what happens if an algorithm of the same name/version already exists, see SubscribeAction
* @param replaceExisting - Defines what happens if an algorithm of the same
* name/version already exists, see SubscribeAction
* @returns The classname that was registered
*/
template<class T>
std::pair<std::string,int> subscribe(Kernel::AbstractInstantiator<T> *instantiator, const SubscribeAction replaceExisting = ErrorIfExists)
{
boost::shared_ptr<IAlgorithm> tempAlg = instantiator-> createInstance();
template <class T>
std::pair<std::string, int>
subscribe(Kernel::AbstractInstantiator<T> *instantiator,
const SubscribeAction replaceExisting = ErrorIfExists) {
boost::shared_ptr<IAlgorithm> tempAlg = instantiator->createInstance();
const int version = extractAlgVersion(tempAlg);
const std::string className = extractAlgName(tempAlg);
typename VersionMap::const_iterator it = m_vmap.find(className);
if (!className.empty())
{
const std::string key = createName(className,version);
if( it == m_vmap.end() )
{
if (!className.empty()) {
const std::string key = createName(className, version);
if (it == m_vmap.end()) {
m_vmap[className] = version;
}
else
{
if(version == it->second && replaceExisting == ErrorIfExists)
{
} else {
if (version == it->second && replaceExisting == ErrorIfExists) {
std::ostringstream os;
os << "Cannot register algorithm " << className << " twice with the same version\n";
os << "Cannot register algorithm " << className
<< " twice with the same version\n";
delete instantiator;
throw std::runtime_error(os.str());
}
if(version > it->second)
{
m_vmap[className]=version;
if (version > it->second) {
m_vmap[className] = version;
}
}
Kernel::DynamicFactory<Algorithm>::subscribe(key, instantiator, replaceExisting);
}
else
{
Kernel::DynamicFactory<Algorithm>::subscribe(key, instantiator,
replaceExisting);
} else {
delete instantiator;
throw std::invalid_argument("Cannot register empty algorithm name");
}
return std::make_pair(className,version);
return std::make_pair(className, version);
}
/// Unsubscribe the given algorithm
void unsubscribe(const std::string & algorithmName, const int version);
void unsubscribe(const std::string &algorithmName, const int version);
/// Does an algorithm of the given name and version exist
bool exists(const std::string & algorithmName, const int version = -1);
bool exists(const std::string &algorithmName, const int version = -1);
/// Get the algorithm names and version - mangled use decodeName to separate
const std::vector<std::string> getKeys() const;
const std::vector<std::string> getKeys(bool includeHidden) const;
/// Returns the highest version of the algorithm currently registered
int highestVersion(const std::string & algorithmName) const;
///Get the algorithm categories
const std::set<std::string> getCategories(bool includeHidden=false) const;
int highestVersion(const std::string &algorithmName) const;
/// Get the algorithm categories
const std::set<std::string> getCategories(bool includeHidden = false) const;
///Get the algorithm categories
const std::map<std::string,bool> getCategoriesWithState() const;
/// Get the algorithm categories
const std::map<std::string, bool> getCategoriesWithState() const;
/// Returns algorithm descriptors.
std::vector<Algorithm_descriptor> getDescriptors(bool includeHidden=false) const;
std::vector<Algorithm_descriptor>
getDescriptors(bool includeHidden = false) const;
///unmangles the names used as keys into the name and version
std::pair<std::string,int> decodeName(const std::string& mangledName)const;
/// unmangles the names used as keys into the name and version
std::pair<std::string, int> decodeName(const std::string &mangledName) const;
private:
private:
friend struct Mantid::Kernel::CreateUsingNew<AlgorithmFactoryImpl>;
/// Extract the name of an algorithm
const std::string extractAlgName(const boost::shared_ptr<IAlgorithm> alg) const;
const std::string
extractAlgName(const boost::shared_ptr<IAlgorithm> alg) const;
/// Extract the version of an algorithm
int extractAlgVersion(const boost::shared_ptr<IAlgorithm> alg) const;
///Create an algorithm object with the specified name
boost::shared_ptr<Algorithm> createAlgorithm(const std::string & name, const int version) const;
/// Create an algorithm object with the specified name
boost::shared_ptr<Algorithm> createAlgorithm(const std::string &name,
const int version) const;
/// Private Constructor for singleton class
AlgorithmFactoryImpl();
AlgorithmFactoryImpl();
/// Private copy constructor - NO COPY ALLOWED
AlgorithmFactoryImpl(const AlgorithmFactoryImpl&);
AlgorithmFactoryImpl(const AlgorithmFactoryImpl &);
/// Private assignment operator - NO ASSIGNMENT ALLOWED
AlgorithmFactoryImpl& operator = (const AlgorithmFactoryImpl&);
///Private Destructor
AlgorithmFactoryImpl &operator=(const AlgorithmFactoryImpl &);
/// Private Destructor
virtual ~AlgorithmFactoryImpl();
/// creates an algorithm name convolved from an name and version
std::string createName(const std::string&, const int&)const;
std::string createName(const std::string &, const int &) const;
/// fills a set with the hidden categories
void fillHiddenCategories(std::set<std::string> *categorySet) const;
......@@ -170,19 +168,23 @@ public:
/// The map holding the registered class names and their highest versions
VersionMap m_vmap;
};
///Forward declaration of a specialisation of SingletonHolder for AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
/// Forward declaration of a specialisation of SingletonHolder for
/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
#ifdef _WIN32
// this breaks new namespace declaraion rules; need to find a better fix
template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>;
template class MANTID_API_DLL
Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>;
#endif /* _WIN32 */
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl> AlgorithmFactory;
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>
AlgorithmFactory;
/// Convenient typedef for an UpdateNotification
typedef Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification AlgorithmFactoryUpdateNotification;
typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification> & AlgorithmFactoryUpdateNotification_ptr;
typedef Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification
AlgorithmFactoryUpdateNotification;
typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<
Algorithm>::UpdateNotification> &AlgorithmFactoryUpdateNotification_ptr;
} // namespace API
} // namespace Mantid
......
#ifndef MANTID_API_ALGORITHMHASPROPERTY_H_
#define MANTID_API_ALGORITHMHASPROPERTY_H_
//------------------------------------------------------------------------------
//Includes
// Includes
//------------------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/TypedValidator.h"
namespace Mantid
{
namespace API
{
//------------------------------------------------------------------------------
// Forward declaration
//------------------------------------------------------------------------------
class IAlgorithm;
/**
A validator to check whether a given algorithm has a named property.
The algorithm's property must be valid for the validator to pass.
@author Martyn Gigg, Tessella plc
@date 30/03/2011
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL AlgorithmHasProperty :
public Kernel::TypedValidator<boost::shared_ptr<IAlgorithm> >
{
public:
/// Constructor
AlgorithmHasProperty(const std::string & propName);
/// Destructor
~AlgorithmHasProperty();
/**
* Get a string representation of the type
* @returns A string containing the validator type
*/
inline std::string getType() const { return "AlgorithmHasProperty"; }
/// Make a copy of the present type of validator
inline Kernel::IValidator_sptr clone() const
{
return boost::make_shared<AlgorithmHasProperty>(*this);
}
protected:
/**
* Checks the value based on the validator's rules
* @param value :: The input algorithm to check
* @returns An error message to display to users or an empty string on no error
*/
virtual std::string checkValidity(const boost::shared_ptr<IAlgorithm> & value) const;
private:
/// Default constructor
AlgorithmHasProperty();
/// Store the property name
std::string m_propName;
};
} // namespace Mantid
namespace Mantid {
namespace API {
//------------------------------------------------------------------------------
// Forward declaration
//------------------------------------------------------------------------------
class IAlgorithm;
/**
A validator to check whether a given algorithm has a named property.
The algorithm's property must be valid for the validator to pass.
@author Martyn Gigg, Tessella plc
@date 30/03/2011
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL AlgorithmHasProperty
: public Kernel::TypedValidator<boost::shared_ptr<IAlgorithm>> {
public:
/// Constructor
AlgorithmHasProperty(const std::string &propName);
/// Destructor
~AlgorithmHasProperty();
/**
* Get a string representation of the type
* @returns A string containing the validator type
*/
inline std::string getType() const { return "AlgorithmHasProperty"; }
/// Make a copy of the present type of validator
inline Kernel::IValidator_sptr clone() const {
return boost::make_shared<AlgorithmHasProperty>(*this);
}
protected:
/**
* Checks the value based on the validator's rules
* @param value :: The input algorithm to check
* @returns An error message to display to users or an empty string on no
* error
*/
virtual std::string
checkValidity(const boost::shared_ptr<IAlgorithm> &value) const;
private:
/// Default constructor
AlgorithmHasProperty();
/// Store the property name
std::string m_propName;
};
} // namespace Mantid
} // namespace API
#endif /* MANTID_API_ALGORITHMHASPROPERTY_H_ */
#endif /* MANTID_API_ALGORITHMHASPROPERTY_H_ */
......@@ -15,29 +15,31 @@
#include <vector>
#include <set>
namespace Mantid
{
namespace API
{
class IAlgorithm;
class Algorithm;
class AlgorithmHistory;
namespace Mantid {
namespace API {
class IAlgorithm;
class Algorithm;
class AlgorithmHistory;
//typedefs for algorithm history pointers
typedef boost::shared_ptr<AlgorithmHistory> AlgorithmHistory_sptr;
typedef boost::shared_ptr<const AlgorithmHistory> AlgorithmHistory_const_sptr;
// typedefs for algorithm history pointers
typedef boost::shared_ptr<AlgorithmHistory> AlgorithmHistory_sptr;
typedef boost::shared_ptr<const AlgorithmHistory> AlgorithmHistory_const_sptr;
typedef std::set<AlgorithmHistory_sptr,
boost::function<bool(const AlgorithmHistory_const_sptr, const AlgorithmHistory_const_sptr)> > AlgorithmHistories;
typedef std::set<AlgorithmHistory_sptr,
boost::function<bool(const AlgorithmHistory_const_sptr,
const AlgorithmHistory_const_sptr)>>
AlgorithmHistories;
/** @class AlgorithmHistory AlgorithmHistory.h API/MAntidAPI/AlgorithmHistory.h
This class stores information about the Command History used by algorithms on a workspace.
This class stores information about the Command History used by algorithms
on a workspace.
@author Dickon Champion, ISIS, RAL
@date 21/01/2008
Copyright &copy; 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
......@@ -58,66 +60,68 @@ namespace API
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL AlgorithmHistory {
class MANTID_API_DLL AlgorithmHistory
{
public:
/// History container
/// The date-and-time will be stored as the Mantid::Kernel::DateAndTime type
explicit AlgorithmHistory(const Algorithm* const alg,
const Kernel::DateAndTime& start = Kernel::DateAndTime::defaultTime(),
const double& duration = -1.0,std::size_t uexeccount = 0);
explicit AlgorithmHistory(
const Algorithm *const alg,
const Kernel::DateAndTime &start = Kernel::DateAndTime::defaultTime(),
const double &duration = -1.0, std::size_t uexeccount = 0);
virtual ~AlgorithmHistory();
AlgorithmHistory& operator=(const AlgorithmHistory&);
AlgorithmHistory(const AlgorithmHistory&);
AlgorithmHistory(const std::string& name, int vers, const Kernel::DateAndTime& start = Kernel::DateAndTime::defaultTime(),
const double& duration = -1.0, std::size_t uexeccount = 0);
void addExecutionInfo(const Kernel::DateAndTime& start, const double& duration);
void addProperty(const std::string& name,const std::string& value,bool isdefault,
const unsigned int& direction = 99);
AlgorithmHistory &operator=(const AlgorithmHistory &);
AlgorithmHistory(const AlgorithmHistory &);
AlgorithmHistory(
const std::string &name, int vers,
const Kernel::DateAndTime &start = Kernel::DateAndTime::defaultTime(),
const double &duration = -1.0, std::size_t uexeccount = 0);
void addExecutionInfo(const Kernel::DateAndTime &start,
const double &duration);
void addProperty(const std::string &name, const std::string &value,
bool isdefault, const unsigned int &direction = 99);
/// add a child algorithm history record to this history object
void addChildHistory(AlgorithmHistory_sptr childHist);
// get functions
/// get name of algorithm in history const
const std::string& name() const {return m_name;}
const std::string &name() const { return m_name; }
/// get version number of algorithm in history const
const int& version() const {return m_version;}
const int &version() const { return m_version; }
/// get execution duration
double executionDuration() const { return m_executionDuration;}
/// get execution date
Mantid::Kernel::DateAndTime executionDate() const {return m_executionDate;}
///get the execution count
const std::size_t& execCount() const {return m_execCount;}
double executionDuration() const { return m_executionDuration; }
/// get execution date
Mantid::Kernel::DateAndTime executionDate() const { return m_executionDate; }
/// get the execution count
const std::size_t &execCount() const { return m_execCount; }
/// get parameter list of algorithm in history const
const Mantid::Kernel::PropertyHistories& getProperties() const {return m_properties;}
const Mantid::Kernel::PropertyHistories &getProperties() const {
return m_properties;
}
/// get the child histories of this history object
const AlgorithmHistories& getChildHistories() const { return m_childHistories; }
const AlgorithmHistories &getChildHistories() const {
return m_childHistories;
}
/// Retrieve a child algorithm history by index
AlgorithmHistory_sptr getChildAlgorithmHistory(const size_t index) const;
/// Add operator[] access
/// Add operator[] access
AlgorithmHistory_sptr operator[](const size_t index) const;
/// Retrieve the number of child algorithms
size_t childHistorySize() const;
/// print contents of object
void printSelf(std::ostream&,const int indent = 0) const;
void printSelf(std::ostream &, const int indent = 0) const;
/// Less than operator
inline bool operator<(const AlgorithmHistory &other) const
{
return (execCount() < other.execCount()) ;
inline bool operator<(const AlgorithmHistory &other) const {
return (execCount() < other.execCount());
}
/// Equality operator
inline bool operator==(const AlgorithmHistory &other) const
{
return (execCount() == other.execCount() &&
name() == other.name());
inline bool operator==(const AlgorithmHistory &other) const {
return (execCount() == other.execCount() && name() == other.name());
}
///Less than operator for pointers
inline bool compareHistory(const boost::shared_ptr<AlgorithmHistory> lhs,
const boost::shared_ptr<AlgorithmHistory> rhs)
{
/// Less than operator for pointers
inline bool compareHistory(const boost::shared_ptr<AlgorithmHistory> lhs,
const boost::shared_ptr<AlgorithmHistory> rhs) {
return *lhs < *rhs;
}
/// Create a concrete algorithm based on a history record
......@@ -125,21 +129,23 @@ public:
/// Create an child algorithm from a history record at a given index
boost::shared_ptr<IAlgorithm> getChildAlgorithm(const size_t index) const;
/// Write this history object to a nexus file
void saveNexus(::NeXus::File* file, int& algCount) const;
// Set the execution count
void saveNexus(::NeXus::File *file, int &algCount) const;
// Set the execution count
void setExecCount(std::size_t execCount) { m_execCount = execCount; }
/// Set data on history after it is created
void fillAlgorithmHistory(const Algorithm* const alg,
const Kernel::DateAndTime& start = Kernel::DateAndTime::defaultTime(),
const double& duration = -1.0,std::size_t uexeccount = 0);
// Allow Algorithm::execute to change the exec count & duration after the algorithm was executed
void fillAlgorithmHistory(
const Algorithm *const alg,
const Kernel::DateAndTime &start = Kernel::DateAndTime::defaultTime(),
const double &duration = -1.0, std::size_t uexeccount = 0);
// Allow Algorithm::execute to change the exec count & duration after the
// algorithm was executed
friend class Algorithm;
private:
//private constructor
// private constructor
AlgorithmHistory();
// Set properties of algorithm
void setProperties(const Algorithm* const alg);