Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::CompositeValidator Class Reference

#include <CompositeValidator.h>

Inheritance diagram for Mantid::Kernel::CompositeValidator:
Mantid::Kernel::IValidator

Public Member Functions

template<typename T >
void add ()
 Add a validator based on a template type. More...
 
void add (const IValidator_sptr &child)
 Adds a validator to the group of validators to check. More...
 
template<typename T , typename U >
void add (const U &arg)
 Add a validator based on the first template type with the second as an argument. More...
 
std::vector< std::string > allowedValues () const override
 Return the instersection of allowed values from children. More...
 
IValidator_sptr clone () const override
 Clones this and the children into a new Validator. More...
 
 CompositeValidator (const CompositeRelation &relation=CompositeRelation::AND)
 Default constructor. More...
 
template<typename T >
bool contains ()
 Returns true if the child list contains a validator of the specified template type. More...
 
std::string getType () const
 Gets the type of the validator. More...
 
 ~CompositeValidator () override
 Destructor. More...
 
- Public Member Functions inherited from Mantid::Kernel::IValidator
virtual std::vector< std::string > allowedValues () const
 The set of allowed values that this validator may have, if a discrete set exists. More...
 
virtual std::string check (const boost::any &) const =0
 Checks the value based on the validator's rules. More...
 
virtual IValidator_sptr clone () const =0
 Make a copy of the present type of validator. More...
 
virtual std::string getValueForAlias (const std::string &alias) const
 Implement this method for validators which wish to support aliasing for alloeed values. More...
 
virtual bool isMultipleSelectionAllowed ()
 Is Multiple Selection Allowed. More...
 
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 it, calls isValid(std::string) More...
 
template<typename TYPE >
std::string isValid (const TYPE &value) const
 Calls the validator. More...
 
 IValidator ()=default
 Constructor. More...
 
virtual ~IValidator ()=default
 virtual Destructor More...
 

Private Member Functions

std::string buildErrorMessage (const bool valid, const std::string &errors) const
 build an error message for OR relations More...
 
std::string check (const boost::any &value) const override
 Verify the value with the child validators. More...
 
std::string checkAll (const boost::any &value) const
 Verify the value with the child validators with logical "and" relationship. More...
 
std::string checkAny (const boost::any &value) const
 Verify the value with the child validators with logical "or" relationship. More...
 
 CompositeValidator (const CompositeValidator &)
 Private Copy constructor: NO DIRECT COPY ALLOWED. More...
 

Private Attributes

std::list< IValidator_sptrm_children
 A container for the child validators. More...
 
const CompositeRelation m_relation
 Store what relationship child validators have. More...
 

Detailed Description

Definition at line 30 of file CompositeValidator.h.

Constructor & Destructor Documentation

◆ CompositeValidator() [1/2]

Mantid::Kernel::CompositeValidator::CompositeValidator ( const CompositeRelation relation = CompositeRelation::AND)

Default constructor.

Definition at line 16 of file CompositeValidator.cpp.

◆ ~CompositeValidator()

Mantid::Kernel::CompositeValidator::~CompositeValidator ( )
override

Destructor.

Definition at line 20 of file CompositeValidator.cpp.

References m_children.

◆ CompositeValidator() [2/2]

Mantid::Kernel::CompositeValidator::CompositeValidator ( const CompositeValidator )
private

Private Copy constructor: NO DIRECT COPY ALLOWED.

Member Function Documentation

◆ add() [1/3]

template<typename T >
void Mantid::Kernel::CompositeValidator::add ( )
inline

Add a validator based on a template type.

Useful for validators that need no arguments

Definition at line 47 of file CompositeValidator.h.

References add().

Referenced by add(), and export_CompositeValidator().

◆ add() [2/3]

void Mantid::Kernel::CompositeValidator::add ( const IValidator_sptr child)

Adds a validator to the group of validators to check.

Parameters
child:: A pointer to the validator to add

Definition at line 70 of file CompositeValidator.cpp.

References m_children.

◆ add() [3/3]

template<typename T , typename U >
void Mantid::Kernel::CompositeValidator::add ( const U &  arg)
inline

Add a validator based on the first template type with the second as an argument.

The argument is used to feed into the validator constructor

Definition at line 51 of file CompositeValidator.h.

References add().

Referenced by add().

◆ allowedValues()

std::vector< std::string > Mantid::Kernel::CompositeValidator::allowedValues ( ) const
overridevirtual

Return the instersection of allowed values from children.

The allowed values for the composite validator.

This returns the intersection of the allowedValues for the child validators

Returns

Reimplemented from Mantid::Kernel::IValidator.

Definition at line 27 of file CompositeValidator.cpp.

References m_children.

◆ buildErrorMessage()

std::string Mantid::Kernel::CompositeValidator::buildErrorMessage ( const bool  valid,
const std::string &  errors 
) const
private

build an error message for OR relations

Return a user friendly error message.

Returns empty string if no errors were found.

Parameters
valid:: whether all the validator succeded
errors:: the combined list of errors from the child validators
Returns
a user friendly message with all the child validator messages combined.

Definition at line 129 of file CompositeValidator.cpp.

Referenced by checkAny().

◆ check()

std::string Mantid::Kernel::CompositeValidator::check ( const boost::any &  value) const
overrideprivatevirtual

Verify the value with the child validators.

Checks the value of all child validators.

Fails if any child fails.

Parameters
value:: The workspace to test
Returns
A user level description of the first problem it finds otherwise ""

Implements Mantid::Kernel::IValidator.

Definition at line 76 of file CompositeValidator.cpp.

References Mantid::Kernel::AND, checkAll(), checkAny(), m_relation, Mantid::Kernel::OR, and value.

◆ checkAll()

std::string Mantid::Kernel::CompositeValidator::checkAll ( const boost::any &  value) const
private

Verify the value with the child validators with logical "and" relationship.

Definition at line 87 of file CompositeValidator.cpp.

References error, m_children, and value.

Referenced by check().

◆ checkAny()

std::string Mantid::Kernel::CompositeValidator::checkAny ( const boost::any &  value) const
private

Verify the value with the child validators with logical "or" relationship.

Definition at line 99 of file CompositeValidator.cpp.

References buildErrorMessage(), m_children, and value.

Referenced by check().

◆ clone()

Kernel::IValidator_sptr Mantid::Kernel::CompositeValidator::clone ( ) const
overridevirtual

Clones this and the children into a new Validator.

Clone the validator.

Returns
A newly constructed validator object. Each child is also cloned

Implements Mantid::Kernel::IValidator.

Definition at line 59 of file CompositeValidator.cpp.

References m_children, and m_relation.

◆ contains()

template<typename T >
bool Mantid::Kernel::CompositeValidator::contains ( )
inline

Returns true if the child list contains a validator of the specified template type.

Definition at line 54 of file CompositeValidator.h.

◆ getType()

std::string Mantid::Kernel::CompositeValidator::getType ( ) const
inline

Gets the type of the validator.

Definition at line 38 of file CompositeValidator.h.

Member Data Documentation

◆ m_children

std::list<IValidator_sptr> Mantid::Kernel::CompositeValidator::m_children
private

A container for the child validators.

Definition at line 74 of file CompositeValidator.h.

Referenced by add(), allowedValues(), checkAll(), checkAny(), clone(), and ~CompositeValidator().

◆ m_relation

const CompositeRelation Mantid::Kernel::CompositeValidator::m_relation
private

Store what relationship child validators have.

Definition at line 76 of file CompositeValidator.h.

Referenced by check(), and clone().


The documentation for this class was generated from the following files: