Mantid
Loading...
Searching...
No Matches
ArrayBoundedValidator.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
9#include <boost/python/class.hpp>
10#include <boost/python/default_call_policies.hpp>
11#include <boost/python/make_constructor.hpp>
12#include <boost/python/overloads.hpp>
13#include <boost/python/return_value_policy.hpp>
14
17using namespace boost::python;
18
19namespace {
20
28template <typename T>
29ArrayBoundedValidator<T> *createExclusiveArrayBoundedValidator(object lower = object(), object upper = object(),
30 const bool exclusive = false) {
31 auto validator = std::make_unique<ArrayBoundedValidator<T>>();
32 if (lower.ptr() != Py_None) {
33 validator->setLower(extract<T>(lower));
34 validator->setLowerExclusive(exclusive);
35 }
36 if (upper.ptr() != Py_None) {
37 validator->setUpper(extract<T>(upper));
38 validator->setUpperExclusive(exclusive);
39 }
40 return validator.release();
41}
42
43#define EXPORT_ARRAYBOUNDEDVALIDATOR(type, prefix) \
44 class_<ArrayBoundedValidator<type>, bases<IValidator>, boost::noncopyable>(#prefix "ArrayBoundedValidator") \
45 .def(init<type, type>((arg("self"), arg("lowerBound"), arg("upperBound")), \
46 "Construct a validator to ensure each value is in the given range")) \
47 .def("__init__", make_constructor(&createExclusiveArrayBoundedValidator<type>, default_call_policies(), \
48 (arg("lower") = object(), arg("upper") = object(), arg("exclusive") = false))) \
49 .def("hasLower", &ArrayBoundedValidator<type>::hasLower, arg("self"), \
50 "Return true if a lower bound has been set") \
51 .def("hasUpper", &ArrayBoundedValidator<type>::hasUpper, arg("self"), \
52 "Return true if an upper bound has been set") \
53 .def("lower", &ArrayBoundedValidator<type>::lower, arg("self"), "Return the lower bound") \
54 .def("upper", &ArrayBoundedValidator<type>::upper, arg("self"), "Return the upper bound") \
55 .def("setLowerExclusive", &ArrayBoundedValidator<type>::setLowerExclusive, (arg("self"), arg("exclusive")), \
56 "Set if the lower bound is exclusive") \
57 .def("setUpperExclusive", &ArrayBoundedValidator<type>::setUpperExclusive, (arg("self"), arg("exclusive")), \
58 "Set if the upper bound is exclusive") \
59 .def("setExclusive", &ArrayBoundedValidator<type>::setExclusive, (arg("self"), arg("exclusive")), \
60 "Set if the bounds are exclusive") \
61 .def("isLowerExclusive", &ArrayBoundedValidator<type>::isLowerExclusive, arg("self"), \
62 "Return True if the lower bound is exclusive") \
63 .def("isUpperExclusive", &ArrayBoundedValidator<type>::isUpperExclusive, arg("self"), \
64 "Return True if the upper bound is exclusive") \
65 .def("setLower", &ArrayBoundedValidator<type>::setLower, (arg("self"), arg("lower")), "Set the lower bound") \
66 .def("setUpper", &ArrayBoundedValidator<type>::setUpper, (arg("self"), arg("upper")), "Set the upper bound") \
67 .def("clearLower", &ArrayBoundedValidator<type>::clearLower, arg("self"), "Clear any set lower bound") \
68 .def("clearUpper", &ArrayBoundedValidator<type>::clearUpper, arg("self"), "Clear any set upper bound");
69} // namespace
70
72 EXPORT_ARRAYBOUNDEDVALIDATOR(double, Float);
74}
void export_ArrayBoundedValidator()
#define EXPORT_ARRAYBOUNDEDVALIDATOR(type, prefix)
double lower
lower and upper bounds on the multiplier, if known
double upper
Kernel/ArrayBoundedValidator.h.
void setLower(const TYPE &value) noexcept
Set lower bound value.
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43