Mantid
Loading...
Searching...
No Matches
WorkspacePropertyExporter.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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
12#include <boost/python/args.hpp>
13#include <boost/python/make_constructor.hpp>
14#include <boost/python/register_ptr_to_python.hpp>
15
16namespace Mantid {
17namespace PythonInterface {
23template <typename WorkspaceType> struct WorkspacePropertyExporter {
27 using WorkspaceType_sptr = std::shared_ptr<WorkspaceType>;
28
38 static TypedWorkspaceProperty *createPropertyWithValidator(const std::string &name, const std::string &wsName,
39 const unsigned int direction,
40 Kernel::IValidator const *validator) {
41 return new TypedWorkspaceProperty(name, wsName, direction, validator->clone());
42 }
43
54 static TypedWorkspaceProperty *createPropertyWithOptionalFlag(const std::string &name, const std::string &wsName,
55 const unsigned int direction,
57 Kernel::IValidator const *validator) {
58 return new TypedWorkspaceProperty(name, wsName, direction, optional, validator->clone());
59 }
60
73 static TypedWorkspaceProperty *createPropertyWithLockFlag(const std::string &name, const std::string &wsName,
74 const unsigned int direction,
76 API::LockMode::Type locking,
77 Kernel::IValidator const *validator) {
78 return new TypedWorkspaceProperty(name, wsName, direction, optional, locking, validator->clone());
79 }
80
86 static Mantid::API::Workspace_sptr value(const TypedWorkspaceProperty &self) { return self.operator()(); }
87
96 static void define(const char *pythonClassName) {
97 using namespace boost::python;
100
101 std::string basePropName = std::string(pythonClassName) + "PropertyWithValue";
103 register_ptr_to_python<TypedWorkspaceProperty *>();
104
105 class_<TypedWorkspaceProperty, bases<PropertyWithValue<WorkspaceType_sptr>, IWorkspaceProperty>,
106 boost::noncopyable>(pythonClassName, no_init)
107 .def(init<const std::string &, const std::string &, const unsigned int>(
108 args("name", "defaultValue", "direction")))
109 .def(init<const std::string &, const std::string &, const unsigned int, API::PropertyMode::Type>(
110 args("name", "defaultValue", "direction", "optional")))
111 .def(init<const std::string &, const std::string &, const unsigned int, API::PropertyMode::Type,
112 API::LockMode::Type>(args("name", "defaultValue", "direction", "optional", "locking")))
113 // These variants require the validator object to be cloned
114 .def("__init__", make_constructor(&createPropertyWithValidator, default_call_policies(),
115 (arg("name"), arg("defaultValue"), arg("direction"), arg("validator"))))
116 .def("__init__", make_constructor(&createPropertyWithOptionalFlag, default_call_policies(),
117 args("name", "defaultValue", "direction", "optional", "validator")))
118 .def("__init__",
119 make_constructor(&createPropertyWithLockFlag, default_call_policies(),
120 args("name", "defaultValue", "direction", "optional", "locking", "validator")))
121 .def("isOptional", &TypedWorkspaceProperty::isOptional, arg("self"),
122 "Returns true if the property has been marked as optional")
123
124 .add_property("value", &value);
125 }
126};
127} // namespace PythonInterface
128} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
An interface that is implemented by WorkspaceProperty.
A property class for workspaces.
IValidator is the basic interface for all validators for properties.
Definition IValidator.h:37
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Helper class which provides the Collimation Length for SANS instruments.
A helper struct to export WorkspaceProperty<> types to Python.
Mantid::API::WorkspaceProperty< WorkspaceType > TypedWorkspaceProperty
The export type.
static Mantid::API::Workspace_sptr value(const TypedWorkspaceProperty &self)
Ensure the stored type is always a Workspace_sptr This allows a reference to a Workspace_sptr to be u...
static TypedWorkspaceProperty * createPropertyWithValidator(const std::string &name, const std::string &wsName, const unsigned int direction, Kernel::IValidator const *validator)
Factory function to act as a constructor so that the validator can be cloned rather than passing in t...
static void define(const char *pythonClassName)
Defines the necessary exports for a WorkspaceProperty<WorkspaceType>.
static TypedWorkspaceProperty * createPropertyWithLockFlag(const std::string &name, const std::string &wsName, const unsigned int direction, API::PropertyMode::Type optional, API::LockMode::Type locking, Kernel::IValidator const *validator)
Factory function to act as a constructor so that the validator can be cloned rather than passing in t...
static TypedWorkspaceProperty * createPropertyWithOptionalFlag(const std::string &name, const std::string &wsName, const unsigned int direction, API::PropertyMode::Type optional, Kernel::IValidator const *validator)
Factory function to act as a constructor so that the validator can be cloned rather than passing in t...
std::shared_ptr< WorkspaceType > WorkspaceType_sptr
Shared pointer to Worksapce type.