16#include <boost/python/class.hpp>
17#include <boost/python/copy_const_reference.hpp>
18#include <boost/python/def.hpp>
19#include <boost/python/dict.hpp>
20#include <boost/python/enum.hpp>
21#include <boost/python/implicit.hpp>
22#include <boost/python/list.hpp>
23#include <boost/python/make_function.hpp>
24#include <boost/python/overloads.hpp>
25#include <boost/python/register_ptr_to_python.hpp>
26#include <boost/python/return_value_policy.hpp>
60PyObject *unitAsUnicode(
const Property &self) {
61 static constexpr std::array<const char *, 2> codecs{
"utf-8",
"windows-1252"};
62 const auto &unitsBytes = self.
units();
63 for (
const auto &encoding : codecs) {
64 auto unitsPy = PyUnicode_Decode(unitsBytes.c_str(), unitsBytes.size(), encoding,
"strict");
71 const std::string allCodecsStr = []() {
72 auto it = codecs.begin();
73 std::string result = *it++;
74 for (; it != codecs.end(); ++it) {
80 const std::string helpMessage = std::string(
"Can't decode units string. Tried codecs=")
82 .append(
"\nTo try other codecs use Property.unitsAsBytes to retrieve the "
83 "original bytes object and use .decode().");
84 PyErr_SetString(PyExc_RuntimeError, helpMessage.c_str());
85 throw error_already_set();
93PyObject *unitsAsBytes(
const Property &self) {
return PyBytes_FromString(self.
units().c_str()); }
103BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(valueAsPrettyStrOverloader, valueAsPrettyStr, 0, 2)
108 register_ptr_to_python<Property *>();
114 enum_<Direction::Type>(
"Direction")
121 class_<Property, boost::noncopyable>(
"Property", no_init)
122 .add_property(
"name", make_function(&
Property::name, return_value_policy<copy_const_reference>()),
123 "The name of the property")
126 "An empty string if the property is valid, otherwise it "
127 "contains an error message.")
129 .add_property(
"isDefault", make_function(&
Property::isDefault),
"Is the property set at the default value")
131 .add_property(
"getDefault", make_function(&
Property::getDefault),
"Get the default value as a string")
133 .add_property(
"direction", &
Property::direction,
"Input, Output, InOut or Unknown. See the Direction class")
135 .add_property(
"documentation",
137 "The property's doc string")
141 .add_property(
"type", make_function(&
Property::type),
"Returns a string identifier for the type")
143 .add_property(
"units", &unitAsUnicode, &
Property::setUnits,
"The units attached to this property")
145 .add_property(
"unitsAsBytes", &unitsAsBytes,
146 "The units attached to this property as a encoded bytes object. It "
147 "is assumed the caller knows the correct endcoding used.")
150 "The value of the property. For a generic property, equivalent to valueAsStr.")
153 "The value of the property as a string. "
154 "For some property types, e.g. Workspaces, it is useful to "
155 "be able to refer to the string value directly")
158 valueAsPrettyStrOverloader((arg(
"maxLength") = 0, arg(
"collapseLists") =
true),
159 "The value of the property as a formatted string. "
160 "If maxLength is defined then the output may not contain the "
162 "contents of the property. The maxLength and collapseLists "
164 "do not work for all property types"))
168 .add_property(
"getGroup", make_function(&
Property::getGroup, return_value_policy<copy_const_reference>()),
169 "Return the 'group' of the property, that is, the header "
170 "in the algorithm's list of properties.")
172 .add_property(
"settings",
174 return_value_policy<return_by_value>()),
175 "Return the object managing this property's settings")
177 .add_static_property(
"EMPTY_DBL", emptyDouble)
178 .add_static_property(
"EMPTY_INT", emptyInt)
179 .add_static_property(
"EMPTY_LONG", emptyLong)
181 .def(
"setAutoTrim", &
Property::setAutoTrim, (arg(
"setting")),
"Setting automatic trimming of whitespaces.")
182 .def(
"getAutoTrim", &
Property::autoTrim,
"Gets the setting of automatic trimming of whitespaces.")
184 "Disable the creation of the Replace Workspace button.")
187 "A flag indicating that the property's value has been set programmatically:"
188 " for example, if the property's default value depends on an upstream property")
190 "Set or clear the flag indicating that the property's value has been set programmatically.");
#define GET_POINTER_SPECIALIZATION(TYPE)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
Base class for properties.
bool isDynamicDefault() const
Returns a flag indicating that the property's value has been set programmatically,...
virtual const std::string & units() const
Returns the units of the property, if any, as a string.
const IPropertySettings * getSettings() const
void setDocumentation(const std::string &documentation)
Sets the user level description of the property.
void setIsDynamicDefault(const bool &flag)
Set or clear the flag indicating whether or not the property's value has been set programmatically.
virtual std::string valueAsPrettyStr(const size_t maxLength=0, const bool collapseLists=true) const
Returns the value of the property as a pretty printed string.
void setDisableReplaceWSButton(const bool &disable)
Sets the property to disable the creation of the "Replace Workspace" button.
bool autoTrim() const
Returns if the property is set to automatically trim string unput values of whitespace.
unsigned int direction() const
returns the direction of the property
const std::string & documentation() const
Get the property's documentation string.
virtual std::string setValue(const std::string &)=0
Set the value of the property via a string.
virtual void setUnits(const std::string &unit)
Sets the units of the property, as a string.
virtual std::string isValid() const
Overridden function that checks whether the property, if not overriden returns "".
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
const std::string & name() const
Get the property's name.
void setAutoTrim(const bool &setting)
Sets if the property is set to automatically trim string unput values of whitespace.
const std::string & getGroup()
virtual std::vector< std::string > allowedValues() const
Returns the set of valid values for this property, if such a set exists.
const std::string type() const
Returns the type of the property as a string.
virtual std::string getDefault() const =0
Get the default value for the property which is the value the property was initialised with.
virtual std::string value() const =0
Returns the value of the property as a string.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr long EMPTY_LONG() noexcept
Returns what we consider an "empty" long within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Describes the direction (within an algorithm) of a Property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.
A struct to help export std::vector types.
static void wrap(std::string const &python_name)
a python wrapper