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 if (value.size() == 1 && value[0] == 0.0) {
44 return "Cannot have a zero bin width";
45 } else {
46 for (size_t i = 1; i < value.size(); i += 2) {
47 if (value[i] == 0.0) {
48 return "Cannot have a zero bin width";
49 }
50 }
51 }
52
53 // bin boundary values must be in increasing order
54 double previous = value[0];
55 for (size_t i = 2; i < value.size(); i += 2) {
56 if ((value[i - 1] < 0) && (previous <= 0)) {
57 return "Bin boundaries must be positive for logarithmic binning";
58 }
59 if (value[i] <= previous) {
60 return "Bin boundary values must be given in order of increasing value";
61 } else
62 previous = value[i];
63 }
64
65 // All's OK if we get to here
66 return "";
67}
68
69} // 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