Mantid
Loading...
Searching...
No Matches
Public Types | Static Public Member Functions | List of all members
Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType > Struct Template Reference

A helper struct to export templated DataService<> types to Python. More...

#include <DataServiceExporter.h>

Public Types

using PythonType = boost::python::class_< SvcType, boost::noncopyable >
 
using WeakPtr = std::weak_ptr< typename SvcPtrType::element_type >
 

Static Public Member Functions

static void addItem (SvcType &self, const std::string &name, const boost::python::object &item)
 Add an item into the service, if it exists then an error is raised. More...
 
static void addOrReplaceItem (SvcType &self, const std::string &name, const boost::python::object &item)
 Add or replace an item into the service, if it exists then an error is raised. More...
 
static void clearItems (SvcType &self)
 Remove an item from the service. More...
 
static PythonType define (const char *pythonClassName)
 Define the necessary boost.python framework to expor the templated DataService type Note: This does not add the Instance method as that is on the SingletonHolder typedef. More...
 
static SvcPtrType extractCppValue (const boost::python::object &pyvalue)
 Extract a SvcPtrType C++ value from the Python object. More...
 
static boost::python::list getObjectNamesAsList (SvcType const *const self, const std::string &contain)
 Return a Python list of object names from the ADS as this is far easier to work with than a set. More...
 
static void removeItem (SvcType &self, const std::string &name)
 Remove an item from the service. More...
 
static WeakPtr retrieveOrKeyError (SvcType &self, const std::string &name)
 Retrieves a shared_ptr from the ADS and raises a Python KeyError if it does not exist. More...
 

Detailed Description

template<typename SvcType, typename SvcPtrType>
struct Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >

A helper struct to export templated DataService<> types to Python.

Template Parameters
SvcTypeType of DataService to export
SvcHeldTypeThe type held within the DataService map

Definition at line 29 of file DataServiceExporter.h.

Member Typedef Documentation

◆ PythonType

template<typename SvcType , typename SvcPtrType >
using Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::PythonType = boost::python::class_<SvcType, boost::noncopyable>

Definition at line 31 of file DataServiceExporter.h.

◆ WeakPtr

template<typename SvcType , typename SvcPtrType >
using Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::WeakPtr = std::weak_ptr<typename SvcPtrType::element_type>

Definition at line 32 of file DataServiceExporter.h.

Member Function Documentation

◆ addItem()

template<typename SvcType , typename SvcPtrType >
static void Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addItem ( SvcType &  self,
const std::string &  name,
const boost::python::object &  item 
)
inlinestatic

Add an item into the service, if it exists then an error is raised.

Parameters
selfA reference to the calling object
nameThe name to assign to this in the service
itemA boost.python wrapped SvcHeldType object

Definition at line 88 of file DataServiceExporter.h.

References Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::extractCppValue().

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().

◆ addOrReplaceItem()

template<typename SvcType , typename SvcPtrType >
static void Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addOrReplaceItem ( SvcType &  self,
const std::string &  name,
const boost::python::object &  item 
)
inlinestatic

Add or replace an item into the service, if it exists then an error is raised.

Parameters
selfA reference to the calling object
nameThe name to assign to this in the service
itemA boost.python wrapped SvcHeldType object

Definition at line 100 of file DataServiceExporter.h.

References Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::extractCppValue().

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().

◆ clearItems()

template<typename SvcType , typename SvcPtrType >
static void Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::clearItems ( SvcType &  self)
inlinestatic

Remove an item from the service.

Parameters
selfA reference to the calling object

Definition at line 119 of file DataServiceExporter.h.

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().

◆ define()

template<typename SvcType , typename SvcPtrType >
static PythonType Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define ( const char *  pythonClassName)
inlinestatic

Define the necessary boost.python framework to expor the templated DataService type Note: This does not add the Instance method as that is on the SingletonHolder typedef.

To add this call the following methods on the object this function returns .def("Instance", &SingletonType::Instance, return_value_policy<reference_existing_object>(), "Return a reference to the ADS singleton") .staticmethod("Instance") where SingletonType is the typedef of the SingletonHolder, e.g. AnalysisDataService

Parameters
pythonClassNameThe name that the class should have in Python
Returns
The new class object that wraps the given C++ type

Definition at line 49 of file DataServiceExporter.h.

References Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addItem(), Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addOrReplaceItem(), Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::clearItems(), Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::getObjectNamesAsList(), Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::removeItem(), and Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::retrieveOrKeyError().

◆ extractCppValue()

template<typename SvcType , typename SvcPtrType >
static SvcPtrType Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::extractCppValue ( const boost::python::object &  pyvalue)
inlinestatic

Extract a SvcPtrType C++ value from the Python object.

Parameters
pyvalueValue of the
Returns
The extracted value or thows an std::invalid_argument error

Definition at line 129 of file DataServiceExporter.h.

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addItem(), and Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::addOrReplaceItem().

◆ getObjectNamesAsList()

template<typename SvcType , typename SvcPtrType >
static boost::python::list Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::getObjectNamesAsList ( SvcType const *const  self,
const std::string &  contain 
)
inlinestatic

Return a Python list of object names from the ADS as this is far easier to work with than a set.

Parameters
self:: A reference to the ADS object that called this method
contain:: If provided, the function will return only names that contain this string
Returns
A python list created from the set of strings

Definition at line 176 of file DataServiceExporter.h.

References Mantid::Kernel::Auto, and Mantid::Kernel::Unsorted.

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().

◆ removeItem()

template<typename SvcType , typename SvcPtrType >
static void Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::removeItem ( SvcType &  self,
const std::string &  name 
)
inlinestatic

Remove an item from the service.

Parameters
selfA reference to the calling object
nameThe name of the item in the service to remove

Definition at line 110 of file DataServiceExporter.h.

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().

◆ retrieveOrKeyError()

template<typename SvcType , typename SvcPtrType >
static WeakPtr Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::retrieveOrKeyError ( SvcType &  self,
const std::string &  name 
)
inlinestatic

Retrieves a shared_ptr from the ADS and raises a Python KeyError if it does not exist.

Parameters
self:: A pointer to the object calling this function. Allows it to act as a member function
name:: The name of the object to retrieve
Returns
A shared_ptr to the named object. If the name does not exist it sets a KeyError error indicator.

Definition at line 153 of file DataServiceExporter.h.

Referenced by Mantid::PythonInterface::DataServiceExporter< SvcType, SvcPtrType >::define().


The documentation for this struct was generated from the following file: