Mantid
Loading...
Searching...
No Matches
ListValidator.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 +
9
10#include <boost/python/class.hpp>
11#include <boost/python/default_call_policies.hpp>
12#include <boost/python/list.hpp>
13#include <boost/python/make_constructor.hpp>
14
15#include <string>
16
20using namespace boost::python;
21
22namespace {
23
30template <typename T> ListValidator<T> *createListValidator(const boost::python::list &allowedValues) {
31 return new ListValidator<T>(Converters::PySequenceToVector<T>(allowedValues)());
32}
33
34#define EXPORT_LISTVALIDATOR(type, prefix) \
35 class_<ListValidator<type>, bases<IValidator>, boost::noncopyable>(#prefix "ListValidator") \
36 .def("__init__", make_constructor(&createListValidator<type>, default_call_policies(), arg("allowedValues"))) \
37 .def("addAllowedValue", &ListValidator<type>::addAllowedValue, (arg("self"), arg("value")), \
38 "Adds a value to the list of accepted values");
39} // namespace
40
42 EXPORT_LISTVALIDATOR(std::string, String);
43 EXPORT_LISTVALIDATOR(long, Int);
44}
#define EXPORT_LISTVALIDATOR(type, prefix)
void export_ListValidator()
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
Definition: ListValidator.h:29
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...