Mantid
Loading...
Searching...
No Matches
ChainableFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2015 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
10#include "MantidKernel/System.h"
11#include <memory>
12#include <stdexcept>
13
14namespace Mantid {
15namespace Kernel {
16
19template <typename Factory, typename Product, typename Argument>
20class DLLExport ChainableFactory : public Chainable<Factory> {
21public:
27 std::unique_ptr<Product> create(const Argument &argument) const {
28 if (this->canInterpret(argument)) {
29 return std::unique_ptr<Product>(this->createRaw(argument));
30 } else {
31 if (this->hasSuccessor()) {
32 return Chainable<Factory>::m_successor->create(argument);
33 } else {
34 throw std::invalid_argument("No successor MDUnitFactory");
35 }
36 }
37 }
38
39private:
41 virtual Product *createRaw(const Argument &argument) const = 0;
42
44 virtual bool canInterpret(const Argument &unitString) const = 0;
45};
46
47} // namespace Kernel
48} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
ChainableFactory : Chain of Responsiblity generic factory.
virtual bool canInterpret(const Argument &unitString) const =0
Indicate an ability to intepret the string.
virtual Product * createRaw(const Argument &argument) const =0
Create the product.
std::unique_ptr< Product > create(const Argument &argument) const
Factory method wrapper.
Helper class which provides the Collimation Length for SANS instruments.