Mantid
Loading...
Searching...
No Matches
Instantiator.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#include <memory>
10
11namespace Mantid {
12namespace Kernel {
22template <class Base, typename... Args>
25{
26public:
29
31 virtual ~AbstractInstantiator() = default;
32
34 virtual std::shared_ptr<Base> createInstance(Args... args) const = 0;
35
38 virtual Base *createUnwrappedInstance(Args... args) const = 0;
39
40private:
45};
46
47// A template class for the easy instantiation of
48// instantiators.
49//
50// For the Instantiator to work, the class of which
51// instances are to be instantiated must have a no-argument
52// constructor.
53template <class C, class Base, typename... Args>
54class DLLExport Instantiator : public AbstractInstantiator<Base, Args...> {
55public:
57 Instantiator() = default;
58
62 std::shared_ptr<Base> createInstance(Args... args) const override { return std::make_shared<C>(args...); }
63
68 Base *createUnwrappedInstance(Args... args) const override { return static_cast<Base *>(new C(args...)); }
69};
70
71} // namespace Kernel
72} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
The base class for instantiators.
Definition: Instantiator.h:25
virtual ~AbstractInstantiator()=default
Destroys the AbstractInstantiator.
AbstractInstantiator()=default
Creates the AbstractInstantiator.
virtual Base * createUnwrappedInstance(Args... args) const =0
Creates an instance of a concrete subclass of Base, which is not wrapped in a shared_ptr.
AbstractInstantiator(const AbstractInstantiator &)
Private copy constructor.
virtual std::shared_ptr< Base > createInstance(Args... args) const =0
Creates an instance of a concrete subclass of Base.
AbstractInstantiator & operator=(const AbstractInstantiator &)
Private assignment operator.
The instantiator is a generic class for creating objects of the template type.
Definition: Instantiator.h:54
Instantiator()=default
Creates the Instantiator.
std::shared_ptr< Base > createInstance(Args... args) const override
Creates an instance of a concrete subclass of Base.
Definition: Instantiator.h:62
Base * createUnwrappedInstance(Args... args) const override
Creates an instance of a concrete subclass of Base that is not wrapped in a shared_ptr.
Definition: Instantiator.h:68
Helper class which provides the Collimation Length for SANS instruments.