Mantid
Loading...
Searching...
No Matches
SpinStateValidator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 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 +
10
11#include <boost/python/class.hpp>
12#include <boost/python/default_call_policies.hpp>
13#include <boost/python/list.hpp>
14#include <boost/python/make_constructor.hpp>
15
17using Mantid::Kernel::TypedValidator;
19using namespace boost::python;
20
21std::shared_ptr<SpinStateValidator>
22createSpinStateValidator(list allowedNumberOfSpins, const bool acceptSingleStates = false,
23 const std::string &paraIndicator = "0", const std::string &antiIndicator = "1",
24 const bool optional = false, const std::string &extraIndicator = "") {
25
26 std::unordered_set<int> allowedNumberOfSpinsSet;
27 for (int i = 0; i < len(allowedNumberOfSpins); i++) {
28 int spinN = extract<int>(allowedNumberOfSpins[i]);
29 allowedNumberOfSpinsSet.insert(spinN);
30 }
31
32 return std::make_shared<SpinStateValidator>(allowedNumberOfSpinsSet, acceptSingleStates, paraIndicator, antiIndicator,
33 optional, extraIndicator);
34}
35
37 TypedValidatorExporter<std::string>::define("StringTypedValidator");
38
39 class_<SpinStateValidator, bases<TypedValidator<std::string>>, std::shared_ptr<SpinStateValidator>,
40 boost::noncopyable>("SpinStateValidator", no_init)
41 .def("__init__",
42 make_constructor(&createSpinStateValidator, default_call_policies(),
43 (arg("allowedNumberOfSpins"), arg("acceptSingleStates") = false, arg("paraIndicator") = "0",
44 arg("antiIndicator") = "1", arg("optional") = false, arg("extraIndicator") = "")),
45 "Will check that a string matches the form 01,00 or 00,10,11,01, for example. This is used for specifying "
46 "the order of input workspaces relative to spin states.");
47}
std::shared_ptr< SpinStateValidator > createSpinStateValidator(list allowedNumberOfSpins, const bool acceptSingleStates=false, const std::string &paraIndicator="0", const std::string &antiIndicator="1", const bool optional=false, const std::string &extraIndicator="")
void export_SpinStateValidator()
Declares a simple static struct to export a TypedValidator to Python.
static void define(const char *pythonClassName)