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
15#include <map>
16#include <vector>
17
18namespace Mantid {
19
20namespace Kernel {
21class Logger;
22}
23
24namespace Geometry {
25
26//----------------------------------------------------------------------
27// Forward declaration
28//----------------------------------------------------------------------
29class Parameter;
30
37class MANTID_GEOMETRY_DLL ParameterFactory {
38public:
39 template <class C> static void subscribe(const std::string &className);
40
41 static std::shared_ptr<Parameter> create(const std::string &className, const std::string &name,
42 const std::string &visible = "true");
43
44private:
51
54 using FactoryMap = std::map<std::string, std::unique_ptr<AbstractFactory>>;
57};
58
63template <class C> void ParameterFactory::subscribe(const std::string &className) {
64 auto it = s_map.find(className);
65 if (!className.empty() && it == s_map.cend()) {
66 s_map[className] = std::make_unique<Kernel::Instantiator<C, Parameter>>();
67 } else {
68 throw std::runtime_error("Parameter type" + className + " is already registered.\n");
69 }
70}
71
72} // namespace Geometry
73} // namespace Mantid
std::string name
Definition Run.cpp:60
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.
Kernel::AbstractInstantiator< Parameter > AbstractFactory
A typedef for the instantiator.
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.
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.