Mantid
Loading...
Searching...
No Matches
ArrayOrderedPairsValidator.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 <cstdint>
10#include <memory>
11#include <sstream>
12
13namespace Mantid::Kernel {
14
20 return std::make_shared<ArrayOrderedPairsValidator<TYPE>>(*this);
21}
22
29template <typename TYPE>
30std::string ArrayOrderedPairsValidator<TYPE>::checkValidity(const std::vector<TYPE> &value) const {
31 std::stringstream error;
32 error << "";
33 // Check the number of entries is even
34 if (value.size() % 2 != 0) {
35 error << "Array has an odd number of entries (" << std::to_string(value.size()) << ").";
36 } else {
37 // Check that each pair is ordered.
38 for (auto it = value.begin(); it != value.end(); it += 2) {
39 if (*it > *(it + 1)) {
40 error << "Pair (" << *it << ", " << *(it + 1) << ") is not ordered.\n";
41 }
42 }
43 }
44 return error.str();
45}
46
47// Required explicit instantiations
51#if defined(_WIN32) || defined(__clang__) && defined(__APPLE__)
53#endif
54
55} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::string checkValidity(const std::vector< TYPE > &value) const override
Function that actually does the work of checking the validity of the array elements.
IValidator_sptr clone() const override
Clone the current state.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
std::string to_string(const wide_integer< Bits, Signed > &n)