Mantid
Loading...
Searching...
No Matches
ParameterFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidGeometry/DllConfig.h"
14#include "MantidKernel/Logger.h"
16
17#include <map>
18#include <vector>
19
20namespace Mantid {
21
22namespace Kernel {
23class Logger;
24}
25
26namespace Geometry {
27
28//----------------------------------------------------------------------
29// Forward declaration
30//----------------------------------------------------------------------
31class Parameter;
32
39class MANTID_GEOMETRY_DLL ParameterFactory {
40public:
41 template <class C> static void subscribe(const std::string &className);
42
43 static std::shared_ptr<Parameter> create(const std::string &className, const std::string &name,
44 const std::string &visible = "true");
45
46private:
53
56 using FactoryMap = std::map<std::string, std::unique_ptr<AbstractFactory>>;
59};
60
65template <class C> void ParameterFactory::subscribe(const std::string &className) {
66 auto it = s_map.find(className);
67 if (!className.empty() && it == s_map.cend()) {
68 s_map[className] = std::make_unique<Kernel::Instantiator<C, Parameter>>();
69 } else {
70 throw std::runtime_error("Parameter type" + className + " is already registered.\n");
71 }
72}
73
74} // namespace Geometry
75} // namespace Mantid
The ParameterFactory class creates parameters for the instrument ParameterMap.
ParameterFactory()
Private default constructor.
ParameterFactory & operator=(const ParameterFactory &)
Private assignment operator.
ParameterFactory(const ParameterFactory &)
Private copy constructor.
std::map< std::string, std::unique_ptr< AbstractFactory > > FactoryMap
static void subscribe(const std::string &className)
Templated method for parameter subscription.
static FactoryMap s_map
The map holding the registered class names and their instantiators.
The base class for instantiators.
Definition: Instantiator.h:25
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.