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
11#include <boost/python/args.hpp>
12#include <boost/python/make_constructor.hpp>
13#include <boost/python/register_ptr_to_python.hpp>
14
15namespace Mantid {
16namespace PythonInterface {
22template <typename WorkspaceType> struct WorkspacePropertyExporter {
26 using WorkspaceType_sptr = std::shared_ptr<WorkspaceType>;
27
37 static TypedWorkspaceProperty *createPropertyWithValidator(const std::string &name, const std::string &wsName,
38 const unsigned int direction,
39 Kernel::IValidator *validator) {
40 return new TypedWorkspaceProperty(name, wsName, direction, validator->clone());
41 }
42
53 static TypedWorkspaceProperty *createPropertyWithOptionalFlag(const std::string &name, const std::string &wsName,
54 const unsigned int direction,
56 Kernel::IValidator *validator) {
57 return new TypedWorkspaceProperty(name, wsName, direction, optional, validator->clone());
58 }
59
72 static TypedWorkspaceProperty *createPropertyWithLockFlag(const std::string &name, const std::string &wsName,
73 const unsigned int direction,
75 API::LockMode::Type locking,
76 Kernel::IValidator *validator) {
77 return new TypedWorkspaceProperty(name, wsName, direction, optional, locking, validator->clone());
78 }
79
85 static Mantid::API::Workspace_sptr value(const TypedWorkspaceProperty &self) { return self.operator()(); }
86
95 static void define(const char *pythonClassName) {
96 using namespace boost::python;
99
100 std::string basePropName = std::string(pythonClassName) + "PropertyWithValue";
102 register_ptr_to_python<TypedWorkspaceProperty *>();
103
104 class_<TypedWorkspaceProperty, bases<PropertyWithValue<WorkspaceType_sptr>, IWorkspaceProperty>,
105 boost::noncopyable>(pythonClassName, no_init)
106 .def(init<const std::string &, const std::string &, const unsigned int>(
107 args("name", "defaultValue", "direction")))
108 .def(init<const std::string &, const std::string &, const unsigned int, API::PropertyMode::Type>(
109 args("name", "defaultValue", "direction", "optional")))
110 .def(init<const std::string &, const std::string &, const unsigned int, API::PropertyMode::Type,
111 API::LockMode::Type>(args("name", "defaultValue", "direction", "optional", "locking")))
112 // These variants require the validator object to be cloned
113 .def("__init__", make_constructor(&createPropertyWithValidator, default_call_policies(),
114 (arg("name"), arg("defaultValue"), arg("direction"), arg("validator"))))
115 .def("__init__", make_constructor(&createPropertyWithOptionalFlag, default_call_policies(),
116 args("name", "defaultValue", "direction", "optional", "validator")))
117 .def("__init__",
118 make_constructor(&createPropertyWithLockFlag, default_call_policies(),
119 args("name", "defaultValue", "direction", "optional", "locking", "validator")))
120 .def("isOptional", &TypedWorkspaceProperty::isOptional, arg("self"),
121 "Returns true if the property has been marked as optional")
122
123 .add_property("value", &value);
124 }
125};
126} // namespace PythonInterface
127} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
An interface that is implemented by WorkspaceProperty.
A property class for workspaces.
bool isOptional() const override
Is the input workspace property optional (can be blank)?
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43
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
Definition: Workspace_fwd.h:20
Helper class which provides the Collimation Length for SANS instruments.
static void define(const char *pythonClassName)
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 *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 *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 *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.