Mantid
Loading...
Searching...
No Matches
LambdaValidator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2023 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 +
7#pragma once
8
11#include <functional>
12
13namespace Mantid::Kernel {
14
23template <typename ParamType> class DLLExport LambdaValidator : public TypedValidator<ParamType> {
24 using ValidatorFunction = std::function<std::string(ParamType)>;
25
26public:
28 : m_validatorFunction([](GNU_UNUSED ParamType x) { return "Error: validator function is not initialized"; }) {}
29 LambdaValidator(const ValidatorFunction &validatorFunction) : m_validatorFunction(validatorFunction) {};
30
31 IValidator_sptr clone() const override { return std::make_shared<LambdaValidator>(*this); }
32
33 void setValidatorFunction(const ValidatorFunction &validatorFunction) { m_validatorFunction = validatorFunction; };
34
35private:
36 std::string checkValidity(const ParamType &value) const override { return m_validatorFunction(value); }
37
39};
40
41// namespace Kernel
42
43} // namespace Mantid::Kernel
double value
The value of the point.
Definition FitMW.cpp:51
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:37
#define GNU_UNUSED
LambdaValidator provides a quick way to create custom validation objects using a validator function o...
std::string checkValidity(const ParamType &value) const override
LambdaValidator(const ValidatorFunction &validatorFunction)
IValidator_sptr clone() const override
ValidatorFunction m_validatorFunction
void setValidatorFunction(const ValidatorFunction &validatorFunction)
std::function< std::string(ParamType)> ValidatorFunction
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26