Mantid
Loading...
Searching...
No Matches
BoundedValidator.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 +
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
16using namespace boost::python;
17
18namespace {
25template <typename T> BoundedValidator<T> *createBoundedValidator(object lower = object(), object upper = object()) {
26 auto validator = new BoundedValidator<T>();
28 validator->setLower(extract<T>(lower));
29 }
31 validator->setUpper(extract<T>(upper));
32 }
33 return validator;
34}
35
43template <typename T>
44BoundedValidator<T> *createExclusiveBoundedValidator(object lower = object(), object upper = object(),
45 const bool exclusive = false) {
46 auto validator = new BoundedValidator<T>();
47 if (lower.ptr() != Py_None) {
48 validator->setLower(extract<T>(lower));
49 validator->setLowerExclusive(exclusive);
50 }
51 if (upper.ptr() != Py_None) {
52 validator->setUpper(extract<T>(upper));
53 validator->setUpperExclusive(exclusive);
54 }
55 return validator;
56}
57
59#define EXPORT_BOUNDEDVALIDATOR(ElementType, prefix) \
60 class_<BoundedValidator<ElementType>, bases<IValidator>, boost::noncopyable>(#prefix "BoundedValidator") \
61 .def("__init__", make_constructor(&createBoundedValidator<ElementType>, default_call_policies(), \
62 (arg("lower") = object(), arg("upper") = object()))) \
63 .def("__init__", make_constructor(&createExclusiveBoundedValidator<ElementType>, default_call_policies(), \
64 (arg("lower") = object(), arg("upper") = object(), arg("exclusive") = false))) \
65 .def("setLower", &BoundedValidator<ElementType>::setLower, (arg("self"), arg("lower")), "Set the lower bound") \
66 .def("setUpper", &BoundedValidator<ElementType>::setUpper, (arg("self"), arg("upper")), "Set the upper bound") \
67 .def("setLowerExclusive", &BoundedValidator<ElementType>::setLowerExclusive, (arg("self"), arg("exclusive")), \
68 "Sets if the lower bound is exclusive") \
69 .def("setUpperExclusive", &BoundedValidator<ElementType>::setUpperExclusive, (arg("self"), arg("exclusive")), \
70 "Sets if the upper bound is exclsuive") \
71 .def("setExclusive", &BoundedValidator<ElementType>::setExclusive, (arg("self"), arg("exclusive")), \
72 "Sets both bounds to be inclusive/exclusive") \
73 .def("lower", &BoundedValidator<ElementType>::lower, arg("self"), "Returns the lower bound") \
74 .def("upper", &BoundedValidator<ElementType>::upper, arg("self"), "Returns the upper bound") \
75 .def("setBounds", &BoundedValidator<ElementType>::setBounds, (arg("self"), arg("lower"), arg("upper")), \
76 "Set both bounds") \
77 .def("hasLower", &BoundedValidator<ElementType>::hasLower, arg("self"), \
78 "Returns True if a lower bound has been set") \
79 .def("hasUpper", &BoundedValidator<ElementType>::hasUpper, arg("self"), \
80 "Returns True if an upper bound has been set") \
81 .def("isLowerExclusive", &BoundedValidator<ElementType>::isLowerExclusive, arg("self"), \
82 "Returns True if the lower bound is exclusive") \
83 .def("isUpperExclusive", &BoundedValidator<ElementType>::isUpperExclusive, arg("self"), \
84 "Returns True if the upper bound is exclusive");
85} // namespace
86
88 EXPORT_BOUNDEDVALIDATOR(double, Float);
89 EXPORT_BOUNDEDVALIDATOR(long, Int);
90}
void export_BoundedValidator()
#define EXPORT_BOUNDEDVALIDATOR(ElementType, prefix)
A macro for generating exports for each type.
double lower
lower and upper bounds on the multiplier, if known
double upper
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43
bool isNone(PyObject *ptr)
Definition: IsNone.h:26