Mantid
Loading...
Searching...
No Matches
FileProperty.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 +
11
12#include <boost/python/bases.hpp>
13#include <boost/python/class.hpp>
14#include <boost/python/default_call_policies.hpp>
15#include <boost/python/enum.hpp>
16#include <boost/python/make_constructor.hpp>
17#include <boost/python/overloads.hpp>
18#include <memory>
19
23namespace bpl = boost::python;
24
26 bpl::enum_<FileProperty::FileAction>("FileAction")
27 .value("Save", FileProperty::Save)
28 .value("OptionalSave", FileProperty::OptionalSave)
29 .value("Load", FileProperty::Load)
30 .value("OptionalLoad", FileProperty::OptionalLoad)
31 .value("Directory", FileProperty::Directory)
32 .value("OptionalDirectory", FileProperty::OptionalDirectory);
33}
34
35namespace {
47FileProperty *createFileProperty(const std::string &name, const std::string &defaultValue, unsigned int action,
48 const bpl::object &extensions = bpl::object(),
49 unsigned direction = Mantid::Kernel::Direction::Input) {
50 std::vector<std::string> extsAsVector;
51 if (!Mantid::PythonInterface::isNone(extensions)) {
52 bpl::extract<std::string> extractor(extensions);
53 if (extractor.check()) {
54 extsAsVector = std::vector<std::string>(1, extractor());
55 } else {
56 extsAsVector = PySequenceToVector<std::string>(extensions)();
57 }
58 }
59 return new FileProperty(name, defaultValue, action, extsAsVector, direction);
60}
61} // namespace
62
64 bpl::class_<FileProperty, bpl::bases<PropertyWithValue<std::string>>, boost::noncopyable>("FileProperty",
65 bpl::no_init)
66 .def("__init__", bpl::make_constructor(&createFileProperty, bpl::default_call_policies(),
67 (bpl::arg("name"), bpl::arg("defaultValue"), bpl::arg("action"),
68 bpl::arg("extensions") = bpl::object(),
69 bpl::arg("direction") = Mantid::Kernel::Direction::Input)));
70}
void export_FileProperty()
void export_ActionEnum()
A specialized class for dealing with file properties.
Definition: FileProperty.h:42
@ Directory
to specify a directory that must exist
Definition: FileProperty.h:54
@ OptionalSave
to specify a file to write to but an empty string is
Definition: FileProperty.h:50
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Definition: FileProperty.h:53
@ OptionalDirectory
to specify a directory that does not have to exist
Definition: FileProperty.h:55
@ Save
to specify a file to write to, the file may or may not exist
Definition: FileProperty.h:49
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
The concrete, templated class for properties.
bool isNone(PyObject *ptr)
Definition: IsNone.h:26
@ Input
An input workspace.
Definition: Property.h:53
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...