Mantid
Loading...
Searching...
No Matches
RebinParamsValidator.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 <memory>
9
10namespace Mantid::Kernel {
11RebinParamsValidator::RebinParamsValidator(bool allowEmpty, bool allowRange)
12 : m_allowEmpty(allowEmpty), m_allowRange(allowRange) {}
13
14IValidator_sptr RebinParamsValidator::clone() const { return std::make_shared<RebinParamsValidator>(*this); }
15
20std::string RebinParamsValidator::checkValidity(const std::vector<double> &value) const {
21 // array must not be empty
22 if (value.empty()) {
23 if (m_allowEmpty) // unless allowed in the constructor
24 return "";
25 else
26 return "Enter values for this property";
27 }
28
29 if (m_allowRange && value.size() == 2) {
30 if (value[0] < value[1])
31 return "";
32 else
33 return "When giving a range the second value must be larger than the "
34 "first";
35 }
36
37 // it must have an odd number of values (and be at least 3 elements long)
38 if (value.size() % 2 == 0) {
39 return "The number of bin boundary parameters provided must be odd";
40 }
41
42 // bin widths must not be zero
43 for (size_t i = 1; i < value.size(); i += 2) {
44 if (value[i] == 0.0) {
45 return "Cannot have a zero bin width";
46 }
47 }
48
49 // bin boundary values must be in increasing order
50 double previous = value[0];
51 for (size_t i = 2; i < value.size(); i += 2) {
52 if ((value[i - 1] < 0) && (previous <= 0)) {
53 return "Bin boundaries must be positive for logarithmic binning";
54 }
55 if (value[i] <= previous) {
56 return "Bin boundary values must be given in order of increasing value";
57 } else
58 previous = value[i];
59 }
60
61 // All's OK if we get to here
62 return "";
63}
64
65} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
IValidator_sptr clone() const override
std::string checkValidity(const std::vector< double > &value) const override
Check on the inputed bin boundaries and widths.
RebinParamsValidator(bool allowEmpty=false, bool allowRange=false)
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26