Mantid
Loading...
Searching...
No Matches
WorkspaceFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8#include "MantidAPI/Axis.h"
15
16#include <boost/python/class.hpp>
17#include <boost/python/overloads.hpp>
18
19using namespace boost::python;
20using namespace Mantid::API;
22
24
25namespace {
46Workspace_sptr createFromParentPtr(WorkspaceFactoryImpl const *const self, const MatrixWorkspace_sptr &parent,
47 size_t NVectors = size_t(-1), size_t XLength = size_t(-1),
48 size_t YLength = size_t(-1)) {
49 return self->create(parent, NVectors, XLength, YLength);
50}
51
53GNU_DIAG_OFF("unused-local-typedef")
54// Ignore -Wconversion warnings coming from boost::python
55// Seen with GCC 7.1.1 and Boost 1.63.0
56GNU_DIAG_OFF("conversion")
57
58BOOST_PYTHON_FUNCTION_OVERLOADS(createFromParent_Overload, createFromParentPtr, 2, 5)
59BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(createTable_Overload, createTable, 0, 1)
60BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(createPeaks_Overload, createPeaks, 0, 1)
61
62GNU_DIAG_ON("conversion")
63GNU_DIAG_ON("unused-local-typedef")
64} // namespace
65
67 const char *createFromParentDoc = "Create a workspace based on the given "
68 "one. The meta-data, instrument etc are "
69 "copied from the input"
70 "If the size parameters are passed then "
71 "the workspace will be a different size.";
72
73 const char *createFromScratchDoc = "Create a clean new worksapce of the given size.";
74 using createFromScratchPtr = MatrixWorkspace_sptr (WorkspaceFactoryImpl::*)(const std::string &, const size_t &,
75 const size_t &, const size_t &) const;
76
77 class_<WorkspaceFactoryImpl, boost::noncopyable>("WorkspaceFactoryImpl", no_init)
78 .def("create", &createFromParentPtr,
79 createFromParent_Overload(createFromParentDoc, (arg("self"), arg("parent"), arg("NVectors") = -1,
80 arg("XLength") = -1, arg("YLength") = -1)))
81
82 .def("create", (createFromScratchPtr)&WorkspaceFactoryImpl::create, createFromScratchDoc,
83 return_value_policy<AsType<Workspace_sptr>>(),
84 (arg("self"), arg("className"), arg("NVectors"), arg("XLength"), arg("YLength")))
85
86 .def("createTable", &WorkspaceFactoryImpl::createTable,
87 createTable_Overload(
88 "Creates an empty TableWorkspace",
89 (arg("self"), arg("className") = "TableWorkspace"))[return_value_policy<AsType<Workspace_sptr>>()])
90
91 .def("createPeaks", &WorkspaceFactoryImpl::createPeaks,
92 createPeaks_Overload(
93 "Creates an empty PeaksWorkspace",
94 (arg("self"), arg("className") = "PeaksWorkspace"))[return_value_policy<AsType<Workspace_sptr>>()])
95
96 .def("Instance", &WorkspaceFactory::Instance, return_value_policy<reference_existing_object>(),
97 "Returns the single instance of this class.")
98 .staticmethod("Instance");
99}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
void export_WorkspaceFactory()
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(valueAsPrettyStrOverloader, valueAsPrettyStr, 0, 2) void export_Property()
Definition: Property.cpp:102
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
The WorkspaceFactory class is in charge of the creation of all types of workspaces.
std::shared_ptr< ITableWorkspace > createTable(const std::string &className="TableWorkspace") const
Create a ITableWorkspace.
std::shared_ptr< IPeaksWorkspace > createPeaks(const std::string &className="PeaksWorkspace") const
Create a IPeaksWorkspace.
MatrixWorkspace_sptr create(const MatrixWorkspace_const_sptr &parent, size_t NVectors=size_t(-1), size_t XLength=size_t(-1), size_t YLength=size_t(-1)) const
Create a new instance of the same type of workspace as that given as argument.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Implements the AsType policy.
Definition: AsType.h:54