10#include "MantidKernel/DllConfig.h"
13#include <boost/any.hpp>
31template <
class T>
struct IsPtrType :
public std::is_pointer<T> {};
34template <
class T>
struct IsPtrType<
std::shared_ptr<T>> :
public std::true_type {};
35template <>
struct IsPtrType<decltype(nullptr)> :
public std::true_type {};
58 template <
typename TYPE> std::string
isValid(
const TYPE &
value)
const {
return runCheck(
value, IsPtrType<TYPE>()); }
77 virtual std::vector<std::string>
allowedValues()
const {
return std::vector<std::string>(); }
94 throw std::invalid_argument(
"Validator does'n support value aliasing.");
105 virtual std::string
check(
const boost::any &)
const = 0;
113 template <
typename T> std::string
runCheck(
const T &
value,
const std::false_type &)
const {
114 const T *valuePtr = &
value;
115 return check(boost::any(valuePtr));
123 template <
typename T> std::string
runCheck(
const T &
value,
const std::true_type &)
const {
124 return runCheckWithDataItemPtr(
value, std::integral_constant <
bool,
125 std::is_convertible<T, DataItem_sptr>::value &&
126 !std::is_same<T,
decltype(
nullptr)>
::value > ());
135 return check(boost::any(
value));
144 return check(boost::any(std::static_pointer_cast<DataItem>(
value)));
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
IValidator is the basic interface for all validators for properties.
std::string runCheck(const T &value, const std::false_type &) const
Calls the validator for a type that is not a pointer type.
IValidator()=default
Constructor.
virtual std::string getValueForAlias(const std::string &alias) const
Implement this method for validators which wish to support aliasing for alloeed values.
std::string runCheckWithDataItemPtr(const T &value, const std::true_type &) const
Calls the validator for a pointer type that IS convertible to DataItem_sptr.
virtual bool isMultipleSelectionAllowed()
Is Multiple Selection Allowed.
std::string isValid(const char *value) const
Deal with a C-style string by first converting it to a std::string so that boost::any can deal with i...
std::string isValid(const TYPE &value) const
Calls the validator.
std::string runCheck(const T &value, const std::true_type &) const
Calls the validator for a type that is either a raw pointer or a std::shared pointer.
std::string runCheckWithDataItemPtr(const T &value, const std::false_type &) const
Calls the validator for a pointer type that is NOT convertible to DataItem_sptr.
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
virtual std::vector< std::string > allowedValues() const
The set of allowed values that this validator may have, if a discrete set exists.
virtual std::string check(const boost::any &) const =0
Checks the value based on the validator's rules.
virtual ~IValidator()=default
virtual Destructor
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.