15#include <boost/python/class.hpp>
16#include <boost/python/def.hpp>
17#include <boost/python/dict.hpp>
18#include <boost/python/list.hpp>
19#include <boost/python/overloads.hpp>
25#include <frameobject.h>
48 const auto keys = self->
getKeys(includeHidden);
50 for (
const auto &key : keys) {
52 object name(handle<>(to_python_value<const std::string &>()(algInfo.first)));
53 object ver(handle<>(to_python_value<const int &>()(algInfo.second)));
57 if (inventory.has_key(name)) {
58 versions = inventory.get(name);
61 inventory[name] = versions;
63 versions.attr(
"append")(ver);
73list getDescriptors(
AlgorithmFactoryImpl const *
const self,
bool includeHidden =
false,
bool includeAlias =
false) {
74 const auto descriptors = self->
getDescriptors(includeHidden, includeAlias);
76 for (
const auto &descr : descriptors) {
77 pyDescriptors.append(boost::python::object(descr));
93 dict pythonCategories;
94 for (
auto &it : categories) {
95 object categoryName(handle<>(to_python_value<const std::string &>()(it.first)));
96 pythonCategories[categoryName] = it.second;
99 return pythonCategories;
107std::recursive_mutex PYALG_REGISTER_MUTEX;
119 std::lock_guard<std::recursive_mutex> lock(PYALG_REGISTER_MUTEX);
121 static auto *
const pyAlgClass = (PyObject *)converter::registered<Algorithm>::converters.to_python_target_type();
123 PyObject *classObject(
nullptr);
124 if (PyObject_IsInstance(
obj.ptr(), pyAlgClass)) {
125 classObject = PyObject_GetAttrString(
obj.ptr(),
"__class__");
126 }
else if (PyObject_IsSubclass(
obj.ptr(), pyAlgClass)) {
127 classObject =
obj.ptr();
130 throw std::invalid_argument(
"Cannot register an algorithm that does not derive from Algorithm.");
132 boost::python::object classType(handle<>(borrowed(classObject)));
134 std::unique_ptr<Mantid::Kernel::AbstractInstantiator<Algorithm>> temp =
135 std::make_unique<PythonObjectInstantiator<Algorithm>>(classType);
136 auto descr = self.subscribe(std::move(temp), AlgorithmFactoryImpl::OverwriteCurrent);
149BOOST_PYTHON_FUNCTION_OVERLOADS(getDescriptors_overloads, getDescriptors, 1, 3)
160 class_<AlgorithmDescriptor>(
"AlgorithmDescriptor")
166 class_<AlgorithmFactoryImpl, boost::noncopyable>(
"AlgorithmFactoryImpl", no_init)
168 existsOverloader((arg(
"name"), arg(
"version") = -1),
"Returns true if the given algorithm exists with "
169 "an option to specify the version"))
171 .def(
"getRegisteredAlgorithms", &getRegisteredAlgorithms, (arg(
"self"), arg(
"include_hidden")),
172 "Returns a Python dictionary of currently registered algorithms")
174 "Returns the highest version of the named algorithm. Throws "
175 "ValueError if no algorithm can be found")
176 .def(
"subscribe", &subscribe, (arg(
"self"), arg(
"object")),
177 "Register a Python class derived from "
178 "PythonAlgorithm into the factory")
179 .def(
"getDescriptors", &getDescriptors,
180 getDescriptors_overloads((arg(
"self"), arg(
"include_hidden") =
false, arg(
"include_alias") =
false),
181 "Return a list of descriptors of registered algorithms. Each "
182 "descriptor is a list: [name, version, category, alias]."))
183 .def(
"getCategoriesandState", &getCategoriesandState,
184 "Return the categories of the algorithms. This includes those within "
185 "the Factory itself and any cleanly constructed algorithms stored "
188 "Returns the highest version of the named algorithm. Throws "
189 "ValueError if no algorithm can be found")
190 .def(
"enableNotifications", &AlgorithmFactoryImpl::enableNotifications)
191 .def(
"disableNotifications", &AlgorithmFactoryImpl::disableNotifications)
194 "Returns a reference to the AlgorithmFactory singleton")
195 .staticmethod(
"Instance");
#define GET_POINTER_SPECIALIZATION(TYPE)
void export_AlgorithmFactory()
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(valueAsPrettyStrOverloader, valueAsPrettyStr, 0, 2) void export_Property()
double obj
the value of the quadratic function
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
The AlgorithmFactory class is in charge of the creation of concrete instances of Algorithms.
bool exists(const std::string &algorithmName, const int version=-1)
Does an algorithm of the given name and version exist.
int highestVersion(const std::string &algorithmName) const
Returns the highest version of the algorithm currently registered.
std::vector< AlgorithmDescriptor > getDescriptors(bool includeHidden=false, bool includeAliases=false) const
Returns algorithm descriptors.
void unsubscribe(const std::string &algorithmName, const int version)
Unsubscribe the given algorithm.
std::pair< std::string, int > decodeName(const std::string &mangledName) const
unmangles the names used as keys into the name and version
const std::vector< std::string > getKeys() const override
Get the algorithm names and version - mangled use decodeName to separate.
const std::map< std::string, bool > getCategoriesWithState() const
Get the algorithm categories.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
RAII handler to temporarily remove and reinstall a Python trace function.
std::string category
category
std::string name
Algorithm Name.