Mantid
Loading...
Searching...
No Matches
CompositeValidator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
10#include "MantidKernel/System.h"
11
12#include <memory>
13
14#include <algorithm>
15#include <list>
16#include <string>
17#include <vector>
18
19namespace Mantid {
20namespace Kernel {
21
28enum class CompositeRelation { AND = 0, OR = 1 };
29
30class MANTID_KERNEL_DLL CompositeValidator : public IValidator {
31public:
33 CompositeValidator(const CompositeRelation &relation = CompositeRelation::AND);
35 ~CompositeValidator() override;
36
38 std::string getType() const { return "composite"; }
40 std::vector<std::string> allowedValues() const override;
42 IValidator_sptr clone() const override;
44 void add(const IValidator_sptr &child);
47 template <typename T> void add() { this->add(std::make_shared<T>()); }
51 template <typename T, typename U> void add(const U &arg) { this->add(std::make_shared<T>(arg)); }
54 template <typename T> bool contains() {
55 // avoid std::dynamic_pointer cast to avoid constructing
56 // a temporary shared_ptr type
57 return std::any_of(m_children.cbegin(), m_children.cend(),
58 [](const IValidator_sptr &validator) { return dynamic_cast<T *>(validator.get()) != nullptr; });
59 }
60
61private:
63 std::string check(const boost::any &value) const override;
65 std::string checkAll(const boost::any &value) const;
67 std::string checkAny(const boost::any &value) const;
69 std::string buildErrorMessage(const bool valid, const std::string &errors) const;
72
74 std::list<IValidator_sptr> m_children;
77};
78
79} // namespace Kernel
80} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
void add()
Add a validator based on a template type.
std::string getType() const
Gets the type of the validator.
CompositeValidator(const CompositeValidator &)
Private Copy constructor: NO DIRECT COPY ALLOWED.
void add(const U &arg)
Add a validator based on the first template type with the second as an argument.
bool contains()
Returns true if the child list contains a validator of the specified template type.
const CompositeRelation m_relation
Store what relationship child validators have.
std::list< IValidator_sptr > m_children
A container for the child validators.
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43
CompositeRelation
A composite validator that can combine any 2+ arbitrary validators together.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
Helper class which provides the Collimation Length for SANS instruments.