ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
PyUserInputValidator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <pybind11/pybind11.h>
6// pybind11.h must come first
7
8#include "PyArrayAccessor.h"
9#include "PyScalarAccessor.h"
10#include "UserInputValidator.h"
11
12#include <ChimeraTK/VariantUserTypes.h>
13
14namespace py = pybind11;
15
16namespace ChimeraTK {
17
18 /********************************************************************************************************************/
19
21 public:
23 explicit PyUserInputValidator(UserInputValidator&& other) : _impl(std::move(other)) {}
24
25 void add(const std::string& errorMessage, std::function<bool(void)>&, py::args& args);
26 bool validate(ChimeraTK::TransferElementID& change) { return _impl.validate(change); }
27 bool validateAll() { return _impl.validateAll(); }
28 void setErrorFunction(const std::function<void(const std::string&)>& errorFunction) {
29 _impl.setErrorFunction(errorFunction);
30 };
31
32 void setFallback(PyScalarAccessor& acc, UserTypeVariantNoVoid value);
33
34 // UserTypeTemplateVariantNoVoid expects a single template argument, std::vector has multiple (with defaults)...
35 template<typename T>
36 using Vector = std::vector<T>;
37 void setFallback(PyArrayAccessor& acc, const UserTypeTemplateVariantNoVoid<Vector>& value);
38
39 static void bind(py::module& mod);
40
41 protected:
43 };
44
45 /********************************************************************************************************************/
46
47} // namespace ChimeraTK
Helper class acting as a ArrayAccessor with a variant UserType.
PyUserInputValidator(UserInputValidator &&other)
bool validate(ChimeraTK::TransferElementID &change)
void add(const std::string &errorMessage, std::function< bool(void)> &, py::args &args)
static void bind(py::module &mod)
void setErrorFunction(const std::function< void(const std::string &)> &errorFunction)
void setFallback(PyScalarAccessor &acc, UserTypeVariantNoVoid value)
InvalidityTracer application module.
module_ module
Class to realise the validation of user input values.
bool validate(const ChimeraTK::TransferElementID &change)
Execute all validations for the given change.
void setErrorFunction(const std::function< void(const std::string &)> &errorFunction)
Define how to report error messages to the user.
bool validateAll()
Evaluate all validation conditions and correct all invalid values.