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"
13#include <sstream>
14
15/* Register classes into the factory
16 *
17 */
18#define DECLARE_PARAMETER(classname, classtype) \
19 namespace { \
20 Mantid::Kernel::RegistrationHelper register_par_##classname( \
21 ((Mantid::Geometry::ParameterFactory::subscribe<Mantid::Geometry::ParameterType<classtype>>(#classname)), 0)); \
22 }
23
24namespace Mantid::Geometry {
25
30template <class Type> std::string ParameterType<Type>::asString() const {
31 std::ostringstream str;
32 str << m_value;
33 return str.str();
34}
35
37template <> std::string ParameterType<double>::asString() const {
38 std::ostringstream str;
39 str << std::setprecision(std::numeric_limits<double>::digits10);
40 str << m_value;
41 return str.str();
42}
43
45template <> std::string ParameterType<Kernel::V3D>::asString() const {
46 std::ostringstream str;
47 str << std::setprecision(std::numeric_limits<double>::digits10);
48 str << m_value;
49 return str.str();
50}
51
52// Initialize the static map
54
63std::string Parameter::getShortDescription() const {
64 size_t pos = m_description.find('.');
65 if (pos == std::string::npos) {
66 return std::string(m_description);
67 } else {
68 if (pos > 0) {
69 return m_description.substr(0, pos + 1);
70 } else {
71 return std::string("");
72 }
73 }
74}
75
83std::shared_ptr<Parameter> ParameterFactory::create(const std::string &className, const std::string &name,
84 const std::string &visible) {
85 std::shared_ptr<Parameter> p;
86 FactoryMap::const_iterator it = s_map.find(className);
87 if (it != s_map.end())
88 p = it->second->createInstance();
89 else
90 throw std::runtime_error("ParameterFactory:" + className + " is not registered.\n");
91 p->m_name = name;
92 p->m_type = className;
93 p->m_visible = visible == "true" ? true : false;
94 return p;
95}
96
97} // namespace Mantid::Geometry
98
99DECLARE_PARAMETER(int, int)
100DECLARE_PARAMETER(double, double)
101DECLARE_PARAMETER(bool, bool)
102DECLARE_PARAMETER(string, std::string)
const std::string & m_value
Definition: Algorithm.cpp:71
#define DECLARE_PARAMETER(classname, classtype)
Definition: Parameter.cpp:18
Store information about a fitting parameter such as its value if it is constrained or tied.
Definition: FitParameter.h:26
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:83
std::map< std::string, std::unique_ptr< AbstractFactory > > FactoryMap
static FactoryMap s_map
The map holding the registered class names and their instantiators.
std::string asString() const override
Returns the value of the property as a string.
Definition: Parameter.cpp:30
std::string m_description
whether the parameter should be visible in InstrumentViewer
Definition: Parameter.h:101
virtual std::string getShortDescription() const
get short description
Definition: Parameter.cpp:63
Class for quaternions.
Definition: Quat.h:39
Class for 3D vectors.
Definition: V3D.h:34