Mantid
Loading...
Searching...
No Matches
SingleValueParameter.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 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/System.h"
11#ifndef Q_MOC_RUN
12#include <boost/algorithm/string.hpp>
13#include <boost/format.hpp>
14#endif
15
16namespace Mantid {
17namespace API {
18
27template <typename Derived, typename ValType> class DLLExport SingleValueParameter : public ImplicitFunctionParameter {
28public:
29 using ValueType = ValType;
34 std::string toXMLString() const override;
35 Derived &operator=(const Derived &other);
36 bool operator==(const Derived &other) const;
37 bool operator!=(const Derived &other) const;
38 ValType getValue() const;
39 bool isValid() const override;
40
41protected:
42 ValType m_value;
44};
45
46//----------------------------------------------------------------
47/* Getter for the valid state.
48@return raw underlying value.
49*/
50template <typename Derived, typename ValType> ValType SingleValueParameter<Derived, ValType>::getValue() const {
51 return m_value;
52}
53
54//----------------------------------------------------------------
55/* Getter for the valid state.
56@return true if the object is in a valid state.
57*/
58template <typename Derived, typename ValType> bool SingleValueParameter<Derived, ValType>::isValid() const {
59 return m_isValid;
60}
61
62//----------------------------------------------------------------
63/* Overloaded assignement operator. Utilises CRTP to peform assignements in
64terms of derived class.
65@param other : object to use as origin for assignment.
66@return Ref to assigned object.
67*/
68template <typename Derived, typename ValType>
70 if (&other != this) {
71 this->m_isValid = other.m_isValid;
72 this->m_value = other.m_value;
73 }
74 return *(dynamic_cast<Derived *>(this));
75}
76
77//----------------------------------------------------------------
78/* Overloaded equals operator.
79@param other : object to use as rhs of comparison.
80@return true only if the two objects are considered equal.
81*/
82template <typename Derived, typename ValType>
84 return other.m_value == this->m_value;
85}
86
87//----------------------------------------------------------------
88/* Overloaded not equals operator.
89@param other : object to use as rhs of comparison.
90@return true only if the two objects are not considered equal.
91*/
92template <typename Derived, typename ValType>
94 return !(*this == other);
95}
96
97//----------------------------------------------------------------
98/* Copy constructor
99@param other : ref to object to use as origin for the new instance.
100*/
101template <typename Derived, typename ValType>
103 *this = other;
104}
105
106template <typename Derived, typename ValType>
109 m_value = other.m_value;
110 m_isValid = other.m_isValid;
111 return *this;
112}
113
115template <typename Derived, typename ValType>
117
118//----------------------------------------------------------------
119/* Constructor. Leads to a valid instance/state.
120@param value : Internal value for the object to wrap.
121*/
122template <typename Derived, typename ValType>
124
125//----------------------------------------------------------------
126/* Serializes the object to an xml string.
127@return xml string containing the underlying value.
128*/
129template <typename Derived, typename ValType> std::string SingleValueParameter<Derived, ValType>::toXMLString() const {
130 std::string valueXMLtext = ElementTraits<ValType>::format(m_value);
131 return this->parameterXMLTemplate(valueXMLtext);
132}
133
134//-----------------------------------------------------------------------------------------------------------------//
135// Macro for generating concrete types of SingleValueParameters.
136//
137// Use of macro enables parameter names to be assigned to each type.
138// Most of the work is done in the VectorParamter base class, which utilises
139// CRTP.
140//
141//-----------------------------------------------------------------------------------------------------------------//
142#define DECLARE_SINGLE_VALUE_PARAMETER(classname, type_) \
143 class classname : public Mantid::API::SingleValueParameter<classname, type_> { \
144 public: \
145 using SuperType = Mantid::API::SingleValueParameter<classname, type_>; \
146 static std::string parameterName() { return #classname; } \
147 classname(type_ value) : SuperType(value) {} \
148 classname() : SuperType() {} \
149 std::string getName() const override { return #classname; } \
150 classname *clone() const override { return new classname(m_value); } \
151 };
152} // namespace API
153} // namespace Mantid
const std::string & m_value
Definition: Algorithm.cpp:71
double value
The value of the point.
Definition: FitMW.cpp:51
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Abstract parameter type for use with IImplicitFunctions.
SingleValueParameter is a templated base class implementing CRTP.
SingleValueParameter()
Default constructor. Object is created in invalid state.
bool operator!=(const Derived &other) const
bool operator==(const Derived &other) const
SingleValueParameter< Derived, ValType > & operator=(const SingleValueParameter< Derived, ValType > &other)
std::string toXMLString() const override
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
Default ElementTraits SFINAE Typetraits are used to provide the correct formatting based on the eleme...