Mantid
Loading...
Searching...
No Matches
WorkspaceFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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 +
7#pragma once
8
9/* Used to register classes into the factory. creates a global object in an
10 * anonymous namespace. The object itself does nothing, but the comma operator
11 * is used in the call to its constructor to effect a call to the factory's
12 * subscribe method.
13 */
14#define DECLARE_WORKSPACE(classname) \
15 namespace { \
16 Mantid::Kernel::RegistrationHelper \
17 register_ws_##classname(((Mantid::API::WorkspaceFactory::Instance().subscribe<classname>(#classname)), 0)); \
18 }
19
20#include "MantidAPI/DllConfig.h"
25
26#include <memory>
27
28namespace Mantid {
29namespace API {
30class ITableWorkspace;
31class IPeaksWorkspace;
32class Workspace;
33
44class MANTID_API_DLL WorkspaceFactoryImpl : public Kernel::DynamicFactory<Workspace> {
45public:
48 MatrixWorkspace_sptr create(const MatrixWorkspace_const_sptr &parent, size_t NVectors = size_t(-1),
49 size_t XLength = size_t(-1), size_t YLength = size_t(-1)) const;
50 MatrixWorkspace_sptr create(const std::string &className, const size_t &NVectors, const size_t &XLength,
51 const size_t &YLength) const;
52
53 void initializeFromParent(const MatrixWorkspace &parent, MatrixWorkspace &child, const bool differentSize) const;
54
56 std::shared_ptr<ITableWorkspace> createTable(const std::string &className = "TableWorkspace") const;
57
59 std::shared_ptr<IPeaksWorkspace> createPeaks(const std::string &className = "PeaksWorkspace") const;
60
61private:
63
67 ~WorkspaceFactoryImpl() override = default;
68 // Unhide the inherited create method but make it private
69 using Kernel::DynamicFactory<Workspace>::create;
70};
71
73
74template <class T, class... InitArgs> std::shared_ptr<T> createWorkspace(InitArgs... args) {
75 auto ws = std::make_shared<T>();
76 ws->initialize(args...);
77 return ws;
78}
79
80} // namespace API
81} // namespace Mantid
82
83namespace Mantid {
84namespace Kernel {
85EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::WorkspaceFactoryImpl>;
86}
87} // namespace Mantid
Base MatrixWorkspace Abstract Class.
The WorkspaceFactory class is in charge of the creation of all types of workspaces.
WorkspaceFactoryImpl(const WorkspaceFactoryImpl &)=delete
WorkspaceFactoryImpl & operator=(const WorkspaceFactoryImpl &)=delete
~WorkspaceFactoryImpl() override=default
Private Destructor.
Base Workspace Abstract Class.
Definition: Workspace.h:30
The dynamic factory is a base dynamic factory for serving up objects in response to requests from oth...
Manage the lifetime of a class intended to be a singleton.
std::shared_ptr< T > createWorkspace(InitArgs... args)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...