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/DllConfig.h"
11#include <memory>
12#include <stdexcept>
13
14namespace Mantid {
15namespace Kernel {
16
19template <typename Factory, typename Product, typename Argument> class ChainableFactory : public Chainable<Factory> {
20public:
26 std::unique_ptr<Product> create(const Argument &argument) const {
27 if (this->canInterpret(argument)) {
28 return std::unique_ptr<Product>(this->createRaw(argument));
29 } else {
30 if (this->hasSuccessor()) {
31 return Chainable<Factory>::m_successor->create(argument);
32 } else {
33 throw std::invalid_argument("No successor MDUnitFactory");
34 }
35 }
36 }
37
38private:
40 virtual Product *createRaw(const Argument &argument) const = 0;
41
43 virtual bool canInterpret(const Argument &unitString) const = 0;
44};
45
46} // namespace Kernel
47} // namespace Mantid
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.