Mantid
Loading...
Searching...
No Matches
Parameter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10#include "MantidKernel/Quat.h"
12#include "MantidKernel/V3D.h"
14#include <sstream>
15#include <type_traits>
16
17/* Register classes into the factory
18 *
19 */
20#define DECLARE_PARAMETER(classname, classtype) \
21 namespace { \
22 Mantid::Kernel::RegistrationHelper register_par_##classname( \
23 ((Mantid::Geometry::ParameterFactory::subscribe<Mantid::Geometry::ParameterType<classtype>>(#classname)), 0)); \
24 }
25
26namespace Mantid::Geometry {
27
32template <class Type> std::string ParameterType<Type>::asString() const {
33 std::ostringstream str;
34 if constexpr (std::is_same_v<Type, double> || std::is_same_v<Type, Kernel::V3D>) {
35 str << std::setprecision(std::numeric_limits<double>::digits10);
36 }
37 str << m_value;
38 return str.str();
39}
40
42// The headers declare these with MANTID_GEOMETRY_EXTERN_TEMPLATE, which already carries the export
43// attribute, so gcc warns that the one here is ignored.
44GNU_DIAG_OFF("attributes")
45template class MANTID_GEOMETRY_DLL ParameterType<int>;
46template class MANTID_GEOMETRY_DLL ParameterType<double>;
47template class MANTID_GEOMETRY_DLL ParameterType<bool>;
48template class MANTID_GEOMETRY_DLL ParameterType<std::string>;
49template class MANTID_GEOMETRY_DLL ParameterType<Kernel::V3D>;
50template class MANTID_GEOMETRY_DLL ParameterType<Kernel::Quat>;
51template class MANTID_GEOMETRY_DLL ParameterType<FitParameter>;
52GNU_DIAG_ON("attributes")
54
55// Initialize the static map
56ParameterFactory::FactoryMap ParameterFactory::s_map;
57
66std::string Parameter::getShortDescription() const {
67 size_t pos = m_description.find('.');
68 if (pos == std::string::npos) {
69 return std::string(m_description);
70 } else {
71 if (pos > 0) {
72 return m_description.substr(0, pos + 1);
73 } else {
74 return std::string("");
75 }
76 }
77}
78
86std::shared_ptr<Parameter> ParameterFactory::create(const std::string &className, const std::string &name,
87 const std::string &visible) {
88 std::shared_ptr<Parameter> p;
89 FactoryMap::const_iterator it = s_map.find(className);
90 if (it != s_map.end())
91 p = it->second->createInstance();
92 else
93 throw std::runtime_error("ParameterFactory:" + className + " is not registered.\n");
94 p->m_name = name;
95 p->m_type = className;
96 p->m_visible = visible == "true" ? true : false;
97 return p;
98}
99
100} // namespace Mantid::Geometry
101
102DECLARE_PARAMETER(int, int)
103DECLARE_PARAMETER(double, double)
104DECLARE_PARAMETER(bool, bool)
105DECLARE_PARAMETER(string, std::string)
const std::string & m_value
Definition Algorithm.cpp:72
std::string name
Definition Run.cpp:60
#define DECLARE_PARAMETER(classname, classtype)
Definition Parameter.cpp:20
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Store information about a fitting parameter such as its value if it is constrained or tied.
The ParameterFactory class creates parameters for the instrument ParameterMap.
static std::shared_ptr< Parameter > create(const std::string &className, const std::string &name, const std::string &visible="true")
Creates an instance of a parameter.
Definition Parameter.cpp:86
static FactoryMap s_map
The map holding the registered class names and their instantiators.
Templated class for parameters of type Type.
Definition Parameter.h:114
std::string asString() const override
Returns the value of the property as a string.
Definition Parameter.cpp:32
Base class for parameters of an instrument.
Definition Parameter.h:42
Class for quaternions.
Definition Quat.h:38
Class for 3D vectors.
Definition V3D.h:35
STL namespace.