Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Types | List of all members
Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm > Class Template Reference

Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived an Algorithm. More...

#include <AlgorithmAdapter.h>

Inheritance diagram for Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >:

Public Member Functions

 AlgorithmAdapter ()=delete
 Disable default constructor - The PyObject must be supplied to construct the object. More...
 
 AlgorithmAdapter (const AlgorithmAdapter &)=delete
 Disable copy operator. More...
 
 AlgorithmAdapter (PyObject *self)
 A constructor that looks like a Python init method. More...
 
AlgorithmAdapteroperator= (const AlgorithmAdapter &)=delete
 Disable assignment operator. More...
 
void setWikiSummary (const std::string &summary)
 Set the summary text. More...
 
Algorithm virtual methods
const std::string name () const override
 Returns the name of the algorithm. More...
 
int version () const override
 Returns a version of the algorithm. More...
 
const std::string summary () const override
 Returns the summary for the algorithm. More...
 
const std::string category () const override
 Returns a category of the algorithm. More...
 
const std::vector< std::string > seeAlso () const override
 Returns seeAlso related algorithms. More...
 
const std::string alias () const override
 Allow the method returning the algorithm aliases to be overridden. More...
 
const std::string aliasDeprecated () const override
 Returns optional documentation URL of the algorithm. More...
 
const std::string helpURL () const override
 Optional documentation URL of the algorithm, empty string if not overridden. More...
 
bool isRunning () const override
 Allow the isRunning method to be overridden. More...
 
void cancel () override
 Allow the cancel method to be overridden. More...
 
bool checkGroups () override
 A return of false will allow processing workspace groups as a whole. More...
 
std::map< std::string, std::string > validateInputs () override
 Returns the validateInputs result of the algorithm. More...
 

Private Types

using SuperClass = BaseAlgorithm
 

Property declarations

The first function matches the base-classes signature so a different name is used consistently to avoid accidentally calling the wrong function internally From Python they will still be called declareProperty

PyObject * m_self
 The Python portion of the object. More...
 
PyObject * m_isRunningObj
 A pointer to an overridden isRunning method. More...
 
std::string m_wikiSummary
 Here for deprecated setWikiSummary method. More...
 
static void declarePyAlgProperty (boost::python::object &self, Kernel::Property *prop, const std::string &doc="")
 Declare a preconstructed property. More...
 
static void declarePyAlgProperty (boost::python::object &self, const std::string &name, const boost::python::object &defaultValue, const boost::python::object &validator=boost::python::object(), const std::string &doc="", const int direction=Kernel::Direction::Input)
 Declare a property using the type of the defaultValue with a validator and doc string. More...
 
static void declarePyAlgProperty (boost::python::object &self, const std::string &name, const boost::python::object &defaultValue, const std::string &doc, const int direction=Kernel::Direction::Input)
 Declare a property with a documentation string. More...
 
static void declarePyAlgProperty (boost::python::object &self, const std::string &name, const boost::python::object &defaultValue, const int direction)
 Declare a property using the type of the defaultValue. More...
 
PyObject * getSelf () const
 Returns the PyObject that owns this wrapper, i.e. More...
 
void init () override
 Private init for this algorithm. More...
 
void exec () override
 Private exec for this algorithm. More...
 

Detailed Description

template<typename BaseAlgorithm>
class Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >

Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python object that is derived an Algorithm.

The templated-base class provides a mechanism to reuse the same adapter class for other classes that inherit from a different Algorithm sub class

Definition at line 27 of file AlgorithmAdapter.h.

Member Typedef Documentation

◆ SuperClass

template<typename BaseAlgorithm >
using Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::SuperClass = BaseAlgorithm
private

Definition at line 28 of file AlgorithmAdapter.h.

Constructor & Destructor Documentation

◆ AlgorithmAdapter() [1/3]

template<typename BaseAlgorithm >
Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::AlgorithmAdapter ( PyObject *  self)

A constructor that looks like a Python init method.

Construct the "wrapper" and stores the reference to the PyObject.

Parameters
selfA reference to the calling Python object

Definition at line 33 of file AlgorithmAdapter.cpp.

References Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::m_isRunningObj, and Mantid::PythonInterface::typeHasAttribute().

◆ AlgorithmAdapter() [2/3]

template<typename BaseAlgorithm >
Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::AlgorithmAdapter ( )
delete

Disable default constructor - The PyObject must be supplied to construct the object.

◆ AlgorithmAdapter() [3/3]

template<typename BaseAlgorithm >
Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::AlgorithmAdapter ( const AlgorithmAdapter< BaseAlgorithm > &  )
delete

Disable copy operator.

Member Function Documentation

◆ alias()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::alias
override

Allow the method returning the algorithm aliases to be overridden.

Returns the aliases of the algorithm.

If not overridden returns the base algorithm implementation

Definition at line 112 of file AlgorithmAdapter.cpp.

◆ aliasDeprecated()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::aliasDeprecated
override

Returns optional documentation URL of the algorithm.

Returns the expiration date (in ISO8601 format) of algorithm aliases.

Allow the method returning the expiration date (in ISO8601 format) for the algorithm aliases to be overridden

If not overridden, returns the base algorithm implementation

Definition at line 124 of file AlgorithmAdapter.cpp.

◆ cancel()

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::cancel
override

Allow the cancel method to be overridden.

Definition at line 176 of file AlgorithmAdapter.cpp.

◆ category()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::category
override

Returns a category of the algorithm.

Returns the category of the algorithm.

If not overridden it return defaultCategory()

Definition at line 78 of file AlgorithmAdapter.cpp.

◆ checkGroups()

template<typename BaseAlgorithm >
bool Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::checkGroups
override

A return of false will allow processing workspace groups as a whole.

Returns checkGroups.

If false, workspace groups will be treated as a whole If true, the algorithm will act on each component of the workspace group individually

Definition at line 66 of file AlgorithmAdapter.cpp.

◆ declarePyAlgProperty() [1/4]

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::declarePyAlgProperty ( boost::python::object &  self,
const std::string &  name,
const boost::python::object &  defaultValue,
const boost::python::object &  validator = boost::python::object(),
const std::string &  doc = "",
const int  direction = Kernel::Direction::Input 
)
static

Declare a property using the type of the defaultValue with a validator and doc string.

Declare a property using the type of the defaultValue, a documentation string and validator.

Parameters
selfA reference to the calling Python object
name:: The name of the new property
defaultValue:: A default value for the property. The type is mapped to a C++ type
validator:: A validator object
doc:: The documentation string
direction:: The direction of the property

Definition at line 264 of file AlgorithmAdapter.cpp.

References Mantid::PythonInterface::Registry::PropertyWithValueFactory::create().

◆ declarePyAlgProperty() [2/4]

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::declarePyAlgProperty ( boost::python::object &  self,
const std::string &  name,
const boost::python::object &  defaultValue,
const int  direction 
)
static

Declare a property using the type of the defaultValue.

Parameters
selfA reference to the calling Python object
name:: The name of the new property
defaultValue:: A default value for the property. The type is mapped to a C++ type
direction:: The direction of the property

Definition at line 303 of file AlgorithmAdapter.cpp.

◆ declarePyAlgProperty() [3/4]

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::declarePyAlgProperty ( boost::python::object &  self,
const std::string &  name,
const boost::python::object &  defaultValue,
const std::string &  doc,
const int  direction = Kernel::Direction::Input 
)
static

Declare a property with a documentation string.

Declare a property using the type of the defaultValue and a documentation string.

Parameters
selfA reference to the calling Python object
name:: The name of the new property
defaultValue:: A default value for the property. The type is mapped to a C++ type
doc:: The documentation string
direction:: The direction of the property

Definition at line 285 of file AlgorithmAdapter.cpp.

References Mantid::PythonInterface::Registry::PropertyWithValueFactory::create().

◆ declarePyAlgProperty() [4/4]

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::declarePyAlgProperty ( boost::python::object &  self,
Kernel::Property prop,
const std::string &  doc = "" 
)
static

Declare a preconstructed property.

Declare a specialized property

Parameters
selfA reference to the calling Python object
prop:: A pointer to a property
doc:: An optional doc string

Definition at line 242 of file AlgorithmAdapter.cpp.

References Mantid::Kernel::Property::clone().

◆ exec()

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::exec
overrideprivate

Private exec for this algorithm.

Expected to be overridden in the subclass by a function named PyExec

Definition at line 325 of file AlgorithmAdapter.cpp.

◆ getSelf()

template<typename BaseAlgorithm >
PyObject * Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::getSelf ( ) const
inlineprotected

Returns the PyObject that owns this wrapper, i.e.

self

Returns
A pointer to self

Definition at line 109 of file AlgorithmAdapter.h.

References Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::m_self.

◆ helpURL()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::helpURL
override

Optional documentation URL of the algorithm, empty string if not overridden.

Definition at line 147 of file AlgorithmAdapter.cpp.

◆ init()

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::init
overrideprivate

Private init for this algorithm.

Expected to be overridden in the subclass by a function named PyInit

Definition at line 317 of file AlgorithmAdapter.cpp.

◆ isRunning()

template<typename BaseAlgorithm >
bool Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::isRunning
override

Allow the isRunning method to be overridden.

Returns
True if the algorithm is considered to be running

Definition at line 158 of file AlgorithmAdapter.cpp.

References GNU_DIAG_OFF, and GNU_DIAG_ON.

◆ name()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::name
override

Returns the name of the algorithm.

Returns the name of the algorithm

This cannot be overridden in Python.

Definition at line 45 of file AlgorithmAdapter.cpp.

◆ operator=()

template<typename BaseAlgorithm >
AlgorithmAdapter & Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::operator= ( const AlgorithmAdapter< BaseAlgorithm > &  )
delete

Disable assignment operator.

◆ seeAlso()

template<typename BaseAlgorithm >
const std::vector< std::string > Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::seeAlso
override

Returns seeAlso related algorithms.

If not overridden it returns an empty vector of strings

Definition at line 98 of file AlgorithmAdapter.cpp.

◆ setWikiSummary()

template<typename BaseAlgorithm >
void Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::setWikiSummary ( const std::string &  summary)

Set the summary text.

Parameters
summaryWiki text

Definition at line 221 of file AlgorithmAdapter.cpp.

◆ summary()

template<typename BaseAlgorithm >
const std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::summary
override

Returns the summary for the algorithm.

Returns the summary of the algorithm.

If not overridden it returns defaultSummary

Definition at line 136 of file AlgorithmAdapter.cpp.

◆ validateInputs()

template<typename BaseAlgorithm >
std::map< std::string, std::string > Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::validateInputs
override

Returns the validateInputs result of the algorithm.

Perform validation of ALL the input properties of the algorithm.

This is to be overridden by specific algorithms. It will be called in dialogs after parsing all inputs and setting the properties, but BEFORE executing.

Returns
a map where: Key = string name of the the property; Value = string describing the problem with the property.

Definition at line 187 of file AlgorithmAdapter.cpp.

References value.

◆ version()

template<typename BaseAlgorithm >
int Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::version
override

Returns a version of the algorithm.

Returns the version of the algorithm.

If not overridden it returns 1

Definition at line 53 of file AlgorithmAdapter.cpp.

Member Data Documentation

◆ m_isRunningObj

template<typename BaseAlgorithm >
PyObject* Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::m_isRunningObj
private

A pointer to an overridden isRunning method.

Definition at line 123 of file AlgorithmAdapter.h.

Referenced by Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::AlgorithmAdapter().

◆ m_self

template<typename BaseAlgorithm >
PyObject* Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::m_self
private

The Python portion of the object.

Definition at line 121 of file AlgorithmAdapter.h.

Referenced by Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::getSelf().

◆ m_wikiSummary

template<typename BaseAlgorithm >
std::string Mantid::PythonInterface::AlgorithmAdapter< BaseAlgorithm >::m_wikiSummary
private

Here for deprecated setWikiSummary method.

Definition at line 126 of file AlgorithmAdapter.h.


The documentation for this class was generated from the following files: