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 <memory>
10#include <sstream>
11
12namespace Mantid::Kernel {
13
18template <typename TYPE>
20 : TypedValidator<std::vector<TYPE>>(), m_actualValidator(abv.m_actualValidator) {}
21
27template <typename TYPE>
28ArrayBoundedValidator<TYPE>::ArrayBoundedValidator(const TYPE lowerBound, const TYPE upperBound) noexcept
29 : TypedValidator<std::vector<TYPE>>(), m_actualValidator(lowerBound, upperBound) {}
30
31template <typename TYPE>
32ArrayBoundedValidator<TYPE>::ArrayBoundedValidator(TYPE lowerBound, TYPE upperBound, bool exclusive) noexcept
33 : TypedValidator<std::vector<TYPE>>(), m_actualValidator(lowerBound, upperBound, exclusive) {}
34
39template <typename TYPE>
41 : TypedValidator<std::vector<TYPE>>(), m_actualValidator(bv) {}
42
47template <typename TYPE> IValidator_sptr ArrayBoundedValidator<TYPE>::clone() const {
48 return std::make_shared<ArrayBoundedValidator<TYPE>>(*this);
49}
50
57template <typename TYPE> std::string ArrayBoundedValidator<TYPE>::checkValidity(const std::vector<TYPE> &value) const {
58 // declare a class that can do conversions to string
59 std::ostringstream error;
60 // load in the "no error" condition
61 error << "";
62 typename std::vector<TYPE>::const_iterator it;
63 std::size_t index = 0;
64 for (it = value.begin(); it != value.end(); ++it) {
65 std::string retval = m_actualValidator.isValid(*it);
66 if (!retval.empty()) {
67 error << "At index " << index << ": " << retval;
68 }
69 index++;
70 }
71
72 return error.str();
73}
74
75template <typename TYPE> bool ArrayBoundedValidator<TYPE>::hasLower() const noexcept {
76 return m_actualValidator.hasLower();
77}
78
79template <typename TYPE> bool ArrayBoundedValidator<TYPE>::hasUpper() const noexcept {
80 return m_actualValidator.hasUpper();
81}
82
83template <typename TYPE> TYPE ArrayBoundedValidator<TYPE>::lower() const noexcept { return m_actualValidator.lower(); }
84
85template <typename TYPE> TYPE ArrayBoundedValidator<TYPE>::upper() const noexcept { return m_actualValidator.upper(); }
86
87template <typename TYPE> bool ArrayBoundedValidator<TYPE>::isLowerExclusive() const noexcept {
88 return m_actualValidator.isLowerExclusive();
89}
91template <typename TYPE> bool ArrayBoundedValidator<TYPE>::isUpperExclusive() const noexcept {
92 return m_actualValidator.isUpperExclusive();
93}
95template <typename TYPE> void ArrayBoundedValidator<TYPE>::setLowerExclusive(const bool exclusive) noexcept {
96 m_actualValidator.setLowerExclusive(exclusive);
97}
99template <typename TYPE> void ArrayBoundedValidator<TYPE>::setUpperExclusive(const bool exclusive) noexcept {
100 m_actualValidator.setUpperExclusive(exclusive);
101}
102
104template <typename TYPE> void ArrayBoundedValidator<TYPE>::setExclusive(const bool exclusive) noexcept {
105 m_actualValidator.setLowerExclusive(exclusive);
106 m_actualValidator.setUpperExclusive(exclusive);
107}
108
109template <typename TYPE> void ArrayBoundedValidator<TYPE>::setLower(const TYPE &value) noexcept {
110 m_actualValidator.setLower(value);
111}
112
113template <typename TYPE> void ArrayBoundedValidator<TYPE>::setUpper(const TYPE &value) noexcept {
114 m_actualValidator.setUpper(value);
115}
116
117template <typename TYPE> void ArrayBoundedValidator<TYPE>::clearLower() noexcept { m_actualValidator.clearLower(); }
118
119template <typename TYPE> void ArrayBoundedValidator<TYPE>::clearUpper() noexcept { m_actualValidator.clearUpper(); }
120
121template <typename TYPE> void ArrayBoundedValidator<TYPE>::setError(const TYPE &value) noexcept {
122 m_actualValidator.setError(value);
123}
124
125// Required explicit instantiations
126template class ArrayBoundedValidator<double>;
127template class ArrayBoundedValidator<int32_t>;
128template class ArrayBoundedValidator<int64_t>;
129#if defined(_WIN32) || defined(__clang__) && defined(__APPLE__)
130template class ArrayBoundedValidator<long>;
131#endif
132
133} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Kernel/ArrayBoundedValidator.h.
TYPE upper() const noexcept
Return the upper bound value.
void setError(const TYPE &value) noexcept
Set the allowed error.
void setUpperExclusive(const bool exclusive) noexcept
Set the upper bound to be exclusive.
void setLower(const TYPE &value) noexcept
Set lower bound value.
IValidator_sptr clone() const override
Clone the current state.
bool isUpperExclusive() const noexcept
Check if upper bound is exclusive.
void clearUpper() noexcept
Clear upper bound value.
bool hasLower() const noexcept
Return if it has a lower bound.
TYPE lower() const noexcept
Return the lower bound value.
std::string checkValidity(const std::vector< TYPE > &value) const override
Function that actually does the work of checking the validity of the array elements.
void clearLower() noexcept
Clear lower bound value.
void setLowerExclusive(const bool exclusive) noexcept
Set the lower bound to be exclusive.
bool hasUpper() const noexcept
Return if it has a lower bound.
void setExclusive(const bool exclusive) noexcept
Set both the upper and lower bounds to be exclusive.
void setUpper(const TYPE &value) noexcept
Set upper bound value.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26