10#include <unordered_set>
17 :
IValidator(), m_children(), m_relation(relation) {}
28 std::unordered_set<std::string> elem_unique;
29 std::unordered_multiset<std::string> elem_all;
31 int n_combinations(0);
33 std::vector<std::string> subs = itr->allowedValues();
36 elem_unique.insert(subs.begin(), subs.end());
37 elem_all.insert(subs.begin(), subs.end());
41 if (n_combinations < 2)
42 return std::vector<std::string>(elem_unique.begin(), elem_unique.end());
44 for (
const auto &its : elem_unique) {
45 auto im = elem_all.find(its);
48 std::unordered_set<std::string> rez;
49 for (
const auto &im : elem_all) {
52 return std::vector<std::string>(rez.begin(), rez.end());
60 std::shared_ptr<CompositeValidator> copy = std::make_shared<CompositeValidator>(
m_relation);
62 copy->add(itr->clone());
83 throw std::runtime_error(
"Unimplemented composite validator relation");
100 std::stringstream errorStream;
106 const auto errorMessage = validator->check(
value);
107 if (errorMessage.empty()) {
111 errorStream << errorMessage <<
"\n";
131 return "Invalid property. You must statisfy one of the following "
double value
The value of the point.
void add()
Add a validator based on a template type.
std::string buildErrorMessage(const bool valid, const std::string &errors) const
build an error message for OR relations
IValidator_sptr clone() const override
Clones this and the children into a new Validator.
std::string check(const boost::any &value) const override
Verify the value with the child validators.
CompositeValidator(const CompositeRelation &relation=CompositeRelation::AND)
Default constructor.
~CompositeValidator() override
Destructor.
std::string checkAll(const boost::any &value) const
Verify the value with the child validators with logical "and" relationship.
std::vector< std::string > allowedValues() const override
Return the instersection of allowed values from children.
const CompositeRelation m_relation
Store what relationship child validators have.
std::list< IValidator_sptr > m_children
A container for the child validators.
std::string checkAny(const boost::any &value) const
Verify the value with the child validators with logical "or" relationship.
IValidator is the basic interface for all validators for properties.
CompositeRelation
A composite validator that can combine any 2+ arbitrary validators together.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.