This GitLab instance is undergoing maintenance and is operating in read-only mode.

You are on a read-only GitLab instance.
Commit c20c02a8 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Refs #4949. Remove TYPE from IValidator interface.

Touches nearly everything unfortunately but is necessary.
parent 73868158
#ifndef MANTID_API_ALGORITHM_H_
#define MANTID_API_ALGORITHM_H_
/* Used to register classes into the factory. creates a global object in an
* anonymous namespace. The object itself does nothing, but the comma operator
* is used in the call to its constructor to effect a call to the factory's
* subscribe method.
*/
#define DECLARE_ALGORITHM(classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_alg_##classname( \
((Mantid::API::AlgorithmFactory::Instance().subscribe<classname>()) \
, 0)); \
}
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IAlgorithm.h"
#include "MantidKernel/PropertyManagerOwner.h"
#include "MantidKernel/Property.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/FileValidator.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/MandatoryValidator.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/EmptyValues.h"
#include "MantidAPI/WorkspaceGroup.h"
// -- These headers will (most-likely) be used by every inheriting algorithm
#include "MantidAPI/Progress.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/WorkspaceOpOverloads.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceOpOverloads.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/EmptyValues.h"
#include <boost/shared_ptr.hpp>
#include <Poco/ActiveMethod.h>
#include <Poco/NotificationCenter.h>
#include <Poco/Notification.h>
#include <Poco/NObserver.h>
#include <Poco/Void.h>
#include <string>
#include <vector>
#include <map>
......@@ -55,6 +37,7 @@ namespace API
// Forward Declaration
//----------------------------------------------------------------------
class AlgorithmProxy;
class AlgorithmHistory;
/**
Base class from which all concrete algorithm classes should be derived.
......@@ -327,6 +310,8 @@ protected:
virtual void setOtherProperties(IAlgorithm * alg, const std::string & propertyName, const std::string & propertyValue, int periodNum);
private:
/// VectorWorkspaces
typedef std::vector<boost::shared_ptr<Workspace> > WorkspaceVector;
/// Private Copy constructor: NO COPY ALLOWED
Algorithm(const Algorithm&);
......@@ -338,8 +323,8 @@ private:
void store();
void fillHistory(Mantid::Kernel::DateAndTime, double,std::size_t);
void findWorkspaceProperties(std::vector<Workspace_sptr>& inputWorkspaces,
std::vector<Workspace_sptr>& outputWorkspaces) const;
void findWorkspaceProperties(WorkspaceVector& inputWorkspaces,
WorkspaceVector& outputWorkspaces) const;
void logAlgorithmInfo() const;
......@@ -365,9 +350,9 @@ private:
/// Vector of all the workspaces that have been read-locked
std::vector<Workspace_sptr> m_readLockedWorkspaces;
WorkspaceVector m_readLockedWorkspaces;
/// Vector of all the workspaces that have been write-locked
std::vector<Workspace_sptr> m_writeLockedWorkspaces;
WorkspaceVector m_writeLockedWorkspaces;
/// All the WorkspaceProperties that are Input or InOut. Set in execute()
std::vector<IWorkspaceProperty *> m_inputWorkspaceProps;
......@@ -381,9 +366,9 @@ private:
void copyNonWorkspaceProperties(IAlgorithm * alg, int periodNum);
/// One vector of workspaces for each input workspace property
std::vector<std::vector<Workspace_sptr> > m_groups;
std::vector<WorkspaceVector> m_groups;
/// Pointer to the WorkspaceGroup (if any) for each input workspace property
std::vector<WorkspaceGroup_sptr> m_groupWorkspaces;
std::vector<boost::shared_ptr<WorkspaceGroup> > m_groupWorkspaces;
/// Flag set true if processGroups() should be called
bool m_processGroups;
/// If only one input is a group, this is its index. -1 if they are all groups
......@@ -401,5 +386,16 @@ typedef boost::shared_ptr<Algorithm> Algorithm_sptr;
} // namespace API
} // namespace Mantid
/* Used to register classes into the factory. creates a global object in an
* anonymous namespace. The object itself does nothing, but the comma operator
* is used in the call to its constructor to effect a call to the factory's
* subscribe method.
*/
#define DECLARE_ALGORITHM(classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_alg_##classname( \
((Mantid::API::AlgorithmFactory::Instance().subscribe<classname>()) \
, 0)); \
}
#endif /*MANTID_API_ALGORITHM_H_*/
......@@ -5,7 +5,7 @@
//Includes
//------------------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/IValidator.h"
#include "MantidKernel/TypedValidator.h"
#include <boost/shared_ptr.hpp>
namespace Mantid
......@@ -46,7 +46,7 @@ namespace Mantid
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL AlgorithmHasProperty :
public Kernel::IValidator<boost::shared_ptr<IAlgorithm> >
public Kernel::TypedValidator<boost::shared_ptr<IAlgorithm> >
{
public:
/// Constructor
......@@ -59,9 +59,9 @@ namespace Mantid
*/
inline std::string getType() const { return "AlgorithmHasProperty"; }
/// Make a copy of the present type of validator
inline Kernel::IValidator<boost::shared_ptr<IAlgorithm> >* clone() const
inline Kernel::IValidator_sptr clone() const
{
return new AlgorithmHasProperty(*this);
return boost::make_shared<AlgorithmHasProperty>(*this);
}
protected:
......
......@@ -7,10 +7,6 @@
namespace Mantid
{
namespace Kernel
{
class DataItem;
}
namespace API
{
//-------------------------------------------------------------------------
......@@ -62,7 +58,7 @@ namespace Mantid
/// Constructor
AlgorithmProperty(const std::string & propName,
Kernel::IValidator<HeldType> *validator = new Kernel::NullValidator<HeldType>(),
Kernel::IValidator_sptr validator = boost::make_shared<Kernel::NullValidator>(),
unsigned int direction = Kernel::Direction::Input);
/// Copy constructor
AlgorithmProperty(const AlgorithmProperty & rhs);
......@@ -87,8 +83,6 @@ namespace Mantid
virtual std::string getDefault() const;
/// Sets the value of the algorithm
virtual std::string setValue(const std::string& value);
/// Set a property value via a DataItem
virtual std::string setValue(const boost::shared_ptr<Kernel::DataItem> data);
private:
/// Default constructor
......
......@@ -67,8 +67,6 @@ public:
bool isOptional() const;
///Overridden setValue method
virtual std::string setValue(const std::string & propValue);
/// Set a value via a data pointer
virtual std::string setValue(const boost::shared_ptr<Kernel::DataItem>);
/// Returns the main file extension that's used
std::string getDefaultExt() const {return m_defaultExt;}
......
......@@ -78,16 +78,6 @@ namespace Mantid
/// Set the value of the property
virtual std::string setValue( const std::string& value );
/**
* Set a property value via a DataItem
* @param data :: A shared pointer to a data item
* @return "" if the assignment was successful or a user level description of the problem
*/
virtual std::string setValue(const boost::shared_ptr<Kernel::DataItem> data)
{
return Kernel::PropertyWithValue< boost::shared_ptr<IFitFunction> >::setValue(data);
}
/// Checks whether the entered function is valid.
std::string isValid() const;
......
......@@ -47,8 +47,6 @@ namespace API
/// Overridden setValue method
virtual std::string setValue(const std::string & propValue);
/// Set a property value via a DataItem
virtual std::string setValue(const boost::shared_ptr<Kernel::DataItem> data);
/// @return the vector of suggested extensions. For use in GUIs showing files.
std::set<std::string> getExts() const
......
......@@ -10,7 +10,6 @@
#include <boost/shared_ptr.hpp>
#include "MantidKernel/Logger.h"
#include "MantidKernel/Exception.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h"
#include <iostream>
......@@ -20,6 +19,16 @@ namespace Mantid
{
namespace API
{
// -------------------------------------------------------------------------
// Forward decaration
// -------------------------------------------------------------------------
class MatrixWorkspace;
/// Enumeration for a mandatory/optional property
enum PropertyMode { Mandatory, Optional };
/// Enumeration for locking behaviour
enum LockMode { Lock, NoLock };
/** A property class for workspaces. Inherits from PropertyWithValue, with the value being
a pointer to the workspace type given to the WorkspaceProperty constructor. This kind
of property also holds the name of the workspace (as used by the AnalysisDataService)
......@@ -68,9 +77,9 @@ namespace Mantid
* @throw std::out_of_range if the direction argument is not a member of the Direction enum (i.e. 0-2)
*/
explicit WorkspaceProperty( const std::string &name, const std::string &wsName, const unsigned int direction,
Kernel::IValidator<boost::shared_ptr<TYPE> > *validator = new Kernel::NullValidator<boost::shared_ptr<TYPE> > ) :
Kernel::IValidator_sptr validator = boost::make_shared<Kernel::NullValidator>() ) :
Kernel::PropertyWithValue <boost::shared_ptr<TYPE> >( name, boost::shared_ptr<TYPE>( ), validator, direction ),
m_workspaceName( wsName ), m_initialWSName( wsName ), m_optional(false), m_locking(true)
m_workspaceName( wsName ), m_initialWSName( wsName ), m_optional(PropertyMode::Mandatory), m_locking(LockMode::Lock)
{
}
......@@ -79,15 +88,15 @@ namespace Mantid
* @param name :: The name to assign to the property
* @param wsName :: The name of the workspace
* @param direction :: Whether this is a Direction::Input, Direction::Output or Direction::InOut (Input & Output) workspace
* @param optional :: A boolean indicating whether the property is mandatory or not. Only matters
* for input properties
* @param optional :: If true then the property is optional
* @param validator :: The (optional) validator to use for this property
* @throw std::out_of_range if the direction argument is not a member of the Direction enum (i.e. 0-2)
*/
explicit WorkspaceProperty(const std::string &name, const std::string &wsName, const unsigned int direction, bool optional,
Kernel::IValidator<boost::shared_ptr<TYPE> > *validator = new Kernel::NullValidator<boost::shared_ptr<TYPE> > ) :
explicit WorkspaceProperty( const std::string &name, const std::string &wsName, const unsigned int direction,
const PropertyMode optional,
Kernel::IValidator_sptr validator = boost::make_shared<Kernel::NullValidator>() ) :
Kernel::PropertyWithValue <boost::shared_ptr<TYPE> >( name, boost::shared_ptr<TYPE>( ), validator, direction ),
m_workspaceName( wsName ), m_initialWSName( wsName ), m_optional(optional), m_locking(true)
m_workspaceName( wsName ), m_initialWSName( wsName ), m_optional(optional), m_locking(LockMode::Lock)
{
}
......@@ -103,8 +112,9 @@ namespace Mantid
* @param validator :: The (optional) validator to use for this property
* @throw std::out_of_range if the direction argument is not a member of the Direction enum (i.e. 0-2)
*/
explicit WorkspaceProperty(const std::string &name, const std::string &wsName, const unsigned int direction, bool optional, bool locking,
Kernel::IValidator<boost::shared_ptr<TYPE> > *validator = new Kernel::NullValidator<boost::shared_ptr<TYPE> > ) :
explicit WorkspaceProperty(const std::string &name, const std::string &wsName, const unsigned int direction,
const PropertyMode optional, const LockMode locking,
Kernel::IValidator_sptr validator = boost::make_shared<Kernel::NullValidator>()) :
Kernel::PropertyWithValue <boost::shared_ptr<TYPE> >( name, boost::shared_ptr<TYPE>( ), validator, direction ),
m_workspaceName( wsName ), m_initialWSName( wsName ), m_optional(optional), m_locking(locking)
{
......@@ -190,24 +200,25 @@ namespace Mantid
}
/** Set a value from a data item
* @param value :: A shared pointer to a DataItem. If it is of the correct
* type it will set validated, if not the property's value will be cleared.
* @return
*/
virtual std::string setValue(const boost::shared_ptr<Kernel::DataItem> value)
* @param value :: A shared pointer to a DataItem. If it is of the correct
* type it will set validated, if not the property's value will be cleared.
* @return
*/
virtual std::string setDataItem(const boost::shared_ptr<Kernel::DataItem> value)
{
boost::shared_ptr<TYPE> typed = boost::dynamic_pointer_cast<TYPE>(value);
if(typed)
{
Kernel::PropertyWithValue< boost::shared_ptr<TYPE> >::m_value = typed;
}
else
{
this->clear();
}
return isValid();
boost::shared_ptr<TYPE> typed = boost::dynamic_pointer_cast<TYPE>(value);
if(typed)
{
Kernel::PropertyWithValue< boost::shared_ptr<TYPE> >::m_value = typed;
}
else
{
this->clear();
}
return isValid();
}
/** Checks whether the entered workspace is valid.
* To be valid, in addition to satisfying the conditions of any validators,
* an output property must not have an empty name and an input one must point to
......@@ -271,13 +282,13 @@ namespace Mantid
* @return true if the workspace can be blank */
bool isOptional() const
{
return m_optional;
return (m_optional == PropertyMode::Optional);
}
/** Does the workspace need to be locked before starting an algorithm?
* @return true (default) if the workspace will be locked */
bool isLocking() const
{
return m_locking;
return (m_locking == LockMode::Lock);
}
/** Returns the current contents of the AnalysisDataService for input workspaces.
......@@ -290,7 +301,7 @@ namespace Mantid
{
// If an input workspace, get the list of workspaces currently in the ADS
std::set<std::string> vals = AnalysisDataService::Instance().getObjectNames();
if (m_optional) // Insert an empty option
if (isOptional()) // Insert an empty option
{
vals.insert("");
}
......@@ -329,7 +340,7 @@ namespace Mantid
virtual bool store()
{
bool result = false;
if ( ! this->operator()() && m_optional ) return result;
if ( ! this->operator()() && isOptional() ) return result;
if ( this->direction() ) // Output or InOut
{
// Check that workspace exists
......@@ -418,7 +429,7 @@ namespace Mantid
}
else
{
if( m_optional ) error = ""; // Optional ones don't need a name
if( isOptional() ) error = ""; // Optional ones don't need a name
else error = "Enter a name for the Output workspace";
}
return error;
......@@ -434,7 +445,7 @@ namespace Mantid
if( m_workspaceName.empty() )
{
if( m_optional )
if( isOptional() )
{
error = "";
}
......
......@@ -4,11 +4,9 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IEventWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Workspace.h"
#include "MantidKernel/TypedValidator.h"
#include "MantidKernel/CompositeValidator.h"
#include "MantidKernel/IValidator.h"
#include <boost/shared_ptr.hpp>
#include <numeric>
#include <vector>
......@@ -45,12 +43,15 @@ namespace API
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport CompositeWorkspaceValidator : public Kernel::CompositeValidator<boost::shared_ptr<TYPE> >
//==============================================================================================
/**
* An interface for those validators that require the MatrixWorkspace interface
*/
class MatrixWorkspaceValidator : public Kernel::TypedValidator<MatrixWorkspace_sptr>
{
};
//===============================================================================================
/** A validator which checks that the unit of the workspace referred to
* by a WorkspaceProperty is the expected one.
......@@ -58,22 +59,20 @@ class DLLExport CompositeWorkspaceValidator : public Kernel::CompositeValidator<
* @author Russell Taylor, Tessella Support Services plc
* @date 16/09/2008
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport WorkspaceUnitValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport WorkspaceUnitValidator : public MatrixWorkspaceValidator
{
public:
/** Constructor
* @param unitID :: The name of the unit that the workspace must have. If left empty,
* the validator will simply check that the workspace is not unitless.
*/
explicit WorkspaceUnitValidator(const std::string& unitID = "") : m_unitID(unitID) {}
virtual ~WorkspaceUnitValidator() {}
explicit WorkspaceUnitValidator(const std::string& unitID = "")
: MatrixWorkspaceValidator(), m_unitID(unitID) {}
///Gets the type of the validator
std::string getType() const { return "workspaceunit"; }
Kernel::IValidator<boost::shared_ptr<TYPE> >* clone() const { return new WorkspaceUnitValidator(*this); }
/// Clone the current state
Kernel::IValidator_sptr clone() const { return boost::make_shared<WorkspaceUnitValidator>(*this); }
private:
/** Checks that the units of the workspace data are declared match any required units
......@@ -81,7 +80,7 @@ private:
* @param value :: The workspace to test
* @return A user level description of the error or "" for no error
*/
std::string checkValidity( const boost::shared_ptr<TYPE>& value ) const
std::string checkValidity( const MatrixWorkspace_sptr & value ) const
{
// This effectively checks for single-valued workspaces
if ( value->axes() == 0 ) return "A single valued workspace has no unit, which is required for this algorithm";
......@@ -115,30 +114,27 @@ private:
* @author Russell Taylor, Tessella Support Services plc
* @date 16/09/2008
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport HistogramValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport HistogramValidator : public MatrixWorkspaceValidator
{
public:
/** Constructor
* @param mustBeHistogram :: Flag indicating whether the check is that a workspace should
* contain histogram data (true, default) or shouldn't (false).
*/
explicit HistogramValidator(const bool& mustBeHistogram = true) :
m_mustBeHistogram(mustBeHistogram) {}
virtual ~HistogramValidator() {}
explicit HistogramValidator(const bool& mustBeHistogram = true)
: MatrixWorkspaceValidator(), m_mustBeHistogram(mustBeHistogram) {}
///Gets the type of the validator
std::string getType() const { return "histogram"; }
Kernel::IValidator<boost::shared_ptr<TYPE> >* clone() const { return new HistogramValidator(*this); }
/// Clone the current state
Kernel::IValidator_sptr clone() const { return boost::make_shared<HistogramValidator>(*this); }
private:
/** Checks if the workspace contains a histogram when it shouldn't and vice-versa
* @param value :: The workspace to test
* @return A user level description if a problem exists or ""
*/
std::string checkValidity( const boost::shared_ptr<TYPE>& value ) const
std::string checkValidity( const MatrixWorkspace_sptr& value ) const
{
if (m_mustBeHistogram)
{
......@@ -163,8 +159,7 @@ private:
* @author Russell Taylor, Tessella Support Services plc
* @date 16/09/2008
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport RawCountValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport RawCountValidator : public MatrixWorkspaceValidator
{
public:
/** Constructor
......@@ -174,19 +169,17 @@ public:
RawCountValidator(const bool& mustNotBeDistribution = true) :
m_mustNotBeDistribution(mustNotBeDistribution) {}
virtual ~RawCountValidator() {}
///Gets the type of the validator
std::string getType() const { return "rawcount"; }
Kernel::IValidator<boost::shared_ptr<TYPE> >* clone() const { return new RawCountValidator(*this); }
/// Clone the current state
Kernel::IValidator_sptr clone() const { return boost::make_shared<RawCountValidator>(*this); }
private:
/** Checks if the workspace must be a distribution but isn't and vice-versa
* @param value :: The workspace to test
* @return A user level description of any problem that exists or "" no problem
*/
std::string checkValidity( const boost::shared_ptr<TYPE>& value ) const
std::string checkValidity( const MatrixWorkspace_sptr & value ) const
{
if (m_mustNotBeDistribution)
{
......@@ -214,24 +207,20 @@ private:
* @author Russell Taylor, Tessella Support Services plc
* @date 18/09/2008
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport CommonBinsValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport CommonBinsValidator : public MatrixWorkspaceValidator
{
public:
CommonBinsValidator() {}
virtual ~CommonBinsValidator() {}
///Gets the type of the validator
std::string getType() const { return "commonbins"; }
Kernel::IValidator<boost::shared_ptr<TYPE> >* clone() const { return new CommonBinsValidator(*this); }
/// Clone the current state
Kernel::IValidator_sptr clone() const { return boost::make_shared<CommonBinsValidator>(*this); }
private:
/** Checks that the bin boundaries of each histogram in the workspace are the same
* @param value :: The workspace to test
* @return A message for users saying that bins are different, otherwise ""
*/
std::string checkValidity( const boost::shared_ptr<TYPE>& value ) const
std::string checkValidity( const MatrixWorkspace_sptr& value ) const
{
if ( !value ) return "Enter an existing workspace";
//there being only one or zero histograms is accepted as not being an error
......@@ -256,27 +245,25 @@ private:
* @author Michael Whitty, STFC
* @date 15/09/2010
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport SpectraAxisValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport SpectraAxisValidator : public MatrixWorkspaceValidator
{
public:
/** Class constructor with parameter.
* @param axisNumber :: set the axis number to validate
*/
SpectraAxisValidator(const int& axisNumber = 1) : m_axisNumber(axisNumber) {}
virtual ~SpectraAxisValidator() {}
///Gets the type of the validator
std::string getType() const { return "spectraaxis"; }
Kernel::IValidator<boost::shared_ptr<TYPE> >* clone() const { return new SpectraAxisValidator(*this); }
/// Clone the current validator
Kernel::IValidator_sptr clone() const { return boost::make_shared<SpectraAxisValidator>(*this); }
private:
/** Checks that the axis stated
* @param value :: The workspace to test
* @return A message for users with negative results, otherwise ""
*/
std::string checkValidity( const boost::shared_ptr<TYPE>& value ) const
std::string checkValidity( const MatrixWorkspace_sptr& value ) const
{
Mantid::API::Axis* axis = value->getAxis(m_axisNumber);
if ( axis->isSpectra() ) return "";
......@@ -290,27 +277,25 @@ private:
* @author Michael Whitty, STFC
* @date 15/09/2010
*/
template <typename TYPE = MatrixWorkspace>
class DLLExport NumericAxisValidator : public Kernel::IValidator<boost::shared_ptr<TYPE> >
class DLLExport NumericAxisValidator : public MatrixWorkspaceValidator
{
public:
/** Class constructor with parameter.
* @param axisNumber :: set the axis number to validate
*/
NumericAxisValidator(const int& axisNumber = 1) : m_axisNumber(axisNumber) {}
virtual ~NumericAxisValidator() {}
///Gets the type of the validator
std::string getType() const { return "numericaaxis"; }