12#include <boost/lexical_cast.hpp>
17#include <unordered_set>
29template <
typename TYPE>
class ListValidator :
public TypedValidator<TYPE> {
41 const std::map<std::string, std::string> &aliases = std::map<std::string, std::string>(),
42 const bool allowMultiSelection =
false)
49 if (values.end() == std::find(values.begin(), values.end(), boost::lexical_cast<TYPE>(aliasIt->second))) {
50 throw std::invalid_argument(
"Alias " + aliasIt->first +
" refers to invalid value " + aliasIt->second);
63 std::vector<std::string> allowedStrings;
67 allowedStrings.emplace_back(boost::lexical_cast<std::string>(*cit));
69 return allowedStrings;
91 throw std::invalid_argument(
"Unknown alias found " + alias);
93 return aliasIt->second;
99 if (isMultiSelectionAllowed) {
116 return "Select a value";
119 std::ostringstream os;
120 os <<
"The value \"" <<
value <<
"\" is not in the list of allowed values";
144 std::string strValue = boost::lexical_cast<std::string>(
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 ...
Marks code as not implemented yet.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
bool isMultipleSelectionAllowed() override
bool isEmpty(const T &value) const
Is the value considered empty.
bool isAlias(const std::string &value) const
Test if a value is an alias of an alowed value.
IValidator_sptr clone() const override
Clone the validator.
std::string getValueForAlias(const std::string &alias) const override
Return an allowed value (as a string) given an alias.
bool isEmpty(const std::string &value) const
Is the value considered empty.
std::string checkValidity(const TYPE &value) const override
Checks if the string passed is in the list.
bool m_allowMultiSelection
if the validator should allow multiple selection
std::map< std::string, std::string > m_aliases
The optional aliases for the allowed values.
bool isAlias(const T &value) const
Test if a value is an alias of an alowed value.
ListValidator()
Default constructor. Sets up an empty list of valid values.
void addAllowedValue(const TYPE &value)
Add value to the list of allowable values if it's not already there.
void setMultipleSelectionAllowed(const bool isMultiSelectionAllowed)
std::vector< std::string > allowedValues() const override
Returns the set of allowed values currently defined.
std::vector< TYPE > m_allowedValues
The set of valid values.
ListValidator(const T &values, const std::map< std::string, std::string > &aliases=std::map< std::string, std::string >(), const bool allowMultiSelection=false)
Constructor.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.