Mantid
Loading...
Searching...
No Matches
CompositeValidator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8#include <boost/python/class.hpp>
9#include <boost/python/default_call_policies.hpp>
10#include <boost/python/enum.hpp>
11#include <boost/python/list.hpp>
12#include <boost/python/make_constructor.hpp>
13
18using namespace boost::python;
19
20namespace {
24CompositeValidator *createCompositeValidator(const boost::python::list &validators, const CompositeRelation &relation) {
25 namespace bpl = boost::python;
26 auto composite = new CompositeValidator(relation);
27 const bpl::ssize_t nitems = bpl::len(validators);
28 for (bpl::ssize_t i = 0; i < nitems; ++i) {
29 try {
30 composite->add(bpl::extract<IValidator_sptr>(validators[i]));
31 } catch (boost::python::error_already_set &) {
32 std::stringstream os;
33 os << "Cannot extract Validator from element " << i;
34 throw std::invalid_argument(os.str());
35 }
36 }
37 return composite;
38}
39} // namespace
40
42 enum_<CompositeRelation>("CompositeRelation").value("AND", CompositeRelation::AND).value("OR", CompositeRelation::OR);
43
44 class_<CompositeValidator, bases<IValidator>, boost::noncopyable>("CompositeValidator")
45 .def("__init__", make_constructor(&createCompositeValidator, default_call_policies(),
46 (arg("validators"), arg("relation") = CompositeRelation::AND)))
47 .def("add", (void (CompositeValidator::*)(const IValidator_sptr &)) & CompositeValidator::add,
48 (arg("self"), arg("other")), "Add another validator to the list");
49}
void export_CompositeValidator()
void add()
Add a validator based on a template type.
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