28constexpr int LOWER_BOUND = -1;
29constexpr int UPPER_BOUND = 1;
36 : TypedValidator<
TYPE>(), m_hasLowerBound(false), m_hasUpperBound(false), m_lowerExclusive(false),
37 m_upperExclusive(false), m_lowerBound(
TYPE()), m_upperBound(
TYPE()), m_hasError(false) {}
45 : TypedValidator<
TYPE>(), m_hasLowerBound(true), m_hasUpperBound(true), m_lowerExclusive(exclusive),
46 m_upperExclusive(exclusive), m_lowerBound(lowerBound), m_upperBound(upperBound), m_hasError(false) {}
49 bool hasLower() const noexcept {
return m_hasLowerBound; }
51 bool hasUpper() const noexcept {
return m_hasUpperBound; }
53 TYPE lower() const noexcept {
return m_lowerBound; }
55 TYPE upper() const noexcept {
return m_upperBound; }
67 setLowerExclusive(exclusive);
68 setUpperExclusive(exclusive);
73 m_hasLowerBound =
true;
79 m_hasUpperBound =
true;
85 m_hasLowerBound =
false;
86 m_lowerBound =
TYPE();
90 m_hasUpperBound =
false;
91 m_upperBound =
TYPE();
143 std::ostringstream
error;
148 if (m_hasLowerBound && (
value < (errorAdjustment(m_lowerBound, LOWER_BOUND)) ||
149 (
value == (errorAdjustment(m_lowerBound, LOWER_BOUND)) && m_lowerExclusive))) {
150 error <<
"Selected value " <<
value <<
" is ";
151 (m_lowerExclusive) ?
error <<
"<=" :
error <<
"<";
152 error <<
" the lower bound (" << m_lowerBound;
153 (
error.str() !=
"" && m_hasError) ?
error <<
" +/- " << m_error <<
")" :
error <<
")";
156 if (m_hasUpperBound && (
value > (errorAdjustment(m_upperBound, UPPER_BOUND)) ||
157 (
value == (errorAdjustment(m_upperBound, UPPER_BOUND)) && m_upperExclusive))) {
158 error <<
"Selected value " <<
value <<
" is ";
159 (m_upperExclusive) ?
error <<
">=" :
error <<
">";
160 error <<
" the upper bound (" << m_upperBound;
161 (
error.str() !=
"" && m_hasError) ?
error <<
" +/- " << m_error <<
")" :
error <<
")";
168 return boundingValue;
174 throw std::invalid_argument(
"BoundedValidator<std::string> does not support error.");
179 m_hasError ? adjValue = boundingValue + m_error *boundID : adjValue = boundingValue;
184 m_hasError ? adjValue = boundingValue + m_error *boundID : adjValue = boundingValue;
double value
The value of the point.
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
double lower
lower and upper bounds on the multiplier, if known
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
bool isUpperExclusive() const noexcept
Check if upper bound is exclusive.
bool m_upperExclusive
Upper bound is exclusive.
void setExclusive(const bool exclusive) noexcept
Set both the upper and lower bounds to be exclusive.
TYPE m_lowerBound
the lower bound
TYPE m_error
the allowed error
bool m_hasError
Has an error set true/false.
void setLower(const TYPE &value) noexcept
Set lower bound value.
TYPE m_upperBound
the upper bound
void setBounds(const TYPE &lower, const TYPE &upper) noexcept
Set both bounds (lower and upper) at the same time.
void setLowerExclusive(const bool exclusive) noexcept
Set the lower bound to be exclusive.
bool hasUpper() const noexcept
Return if it has a lower bound.
TYPE errorAdjustment(const TYPE &boundingValue, const int boundID) const
void clearLower() noexcept
Clear lower bound value.
BoundedValidator() noexcept
No-arg Constructor.
TYPE upper() const noexcept
Return the upper bound value.
void setUpper(const TYPE &value) noexcept
Set upper bound value.
bool hasLower() const noexcept
Return if it has a lower bound.
bool m_hasUpperBound
Has a upper bound set true/false.
BoundedValidator(const TYPE &lowerBound, const TYPE &upperBound, bool exclusive=false) noexcept
Constructor.
void setUpperExclusive(const bool exclusive) noexcept
Set the upper bound to be exclusive.
std::string checkValidity(const TYPE &value) const override
Checks that the value is within any upper and lower limits.
bool isLowerExclusive() const noexcept
Check if lower bound is exclusive.
bool m_lowerExclusive
Lower bound is exclusive.
void clearBounds() noexcept
Clear both bounds (lower and upper) at the same time.
void setError(const TYPE &value)
Set the allowed error.
IValidator_sptr clone() const override
Clone the current state.
bool m_hasLowerBound
Has a lower bound set true/false.
void clearUpper() noexcept
Clear upper bound value.
TYPE lower() const noexcept
Return the lower bound value.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.