Mantid
Loading...
Searching...
No Matches
Vector3DParameter.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 <boost/algorithm/string.hpp>
11#include <boost/format.hpp>
12
13namespace Mantid {
14namespace MDAlgorithms {
15
23template <typename Derived, typename ElemType>
24class MANTID_MDALGORITHMS_DLL Vector3DParameter : public Mantid::API::ImplicitFunctionParameter {
25public:
26 Vector3DParameter(ElemType a, ElemType b, ElemType c);
29 std::string toXMLString() const;
30 Derived &operator=(const Derived &other);
31 bool operator==(const Derived &other) const;
32 bool operator!=(const Derived &other) const;
33 ElemType getX() const;
34 ElemType getY() const;
35 ElemType getZ() const;
36 virtual bool isValid() const;
37 ElemType &operator[](int index);
38
39protected:
40 std::vector<ElemType> m_vector;
42};
43
44template <typename Derived, typename ElemType> bool Vector3DParameter<Derived, ElemType>::isValid() const {
45 return m_isValid;
46}
47
48template <typename Derived, typename ElemType>
50 if (&other != this) {
51 this->m_isValid = other.m_isValid;
52 this->m_vector.swap(std::vector<ElemType>(3));
53 std::copy(other.m_vector.begin(), other.m_vector.end(), this->m_vector.begin());
54 }
55 return *(dynamic_cast<Derived *>(this));
56}
57
58template <typename Derived, typename ElemType>
59bool Vector3DParameter<Derived, ElemType>::operator==(const Derived &other) const {
60 return std::equal(m_vector.begin(), m_vector.end(), other.m_vector.begin());
61}
62
63template <typename Derived, typename ElemType>
64bool Vector3DParameter<Derived, ElemType>::operator!=(const Derived &other) const {
65 return !(*this == other);
66}
67
68template <typename Derived, typename ElemType>
70 : m_vector(3) {
71 m_isValid = other.isValid();
72 if (true == other.m_isValid) {
73 m_vector[0] = other.m_vector[0];
74 m_vector[1] = other.m_vector[1];
75 m_vector[2] = other.m_vector[2];
76 }
77}
78
79template <typename Derived, typename ElemType>
80Vector3DParameter<Derived, ElemType>::Vector3DParameter() : m_vector(3, 0), m_isValid(false) {}
81
82template <typename Derived, typename ElemType>
83Vector3DParameter<Derived, ElemType>::Vector3DParameter(ElemType a, ElemType b, ElemType c) : m_vector(3) {
84 m_vector[0] = a;
85 m_vector[1] = b;
86 m_vector[2] = c;
87 m_isValid = true;
88}
89
90template <typename Derived, typename ElemType> ElemType Vector3DParameter<Derived, ElemType>::getX() const {
91 return m_vector[0];
92}
93
94template <typename Derived, typename ElemType> ElemType Vector3DParameter<Derived, ElemType>::getY() const {
95 return m_vector[1];
96}
97
98template <typename Derived, typename ElemType> ElemType Vector3DParameter<Derived, ElemType>::getZ() const {
99 return m_vector[2];
100}
101
102template <typename Derived, typename ElemType> std::string Vector3DParameter<Derived, ElemType>::toXMLString() const {
103 std::string valueXMLtext = boost::str(boost::format("%.4f, %.4f, %.4f") % m_vector[0] % m_vector[1] % m_vector[2]);
104 return this->parameterXMLTemplate(valueXMLtext);
105}
106
107template <typename Derived, typename ElemType> ElemType &Vector3DParameter<Derived, ElemType>::operator[](int index) {
108 return m_vector[index];
109}
110
111//-----------------------------------------------------------------------------------------------------------------//
112// Macro for generating concrete types of Vector3DParameters.
113//
114// Use of macro enables parameter names to be assigned to each type.
115// Most of the work is done in the VectorParamter base class, which utilises
116// CRTP.
117//-----------------------------------------------------------------------------------------------------------------//
118#define DECLARE_3D_VECTOR_PARAMETER(classname, type_) \
119 class classname : public Mantid::MDAlgorithms::Vector3DParameter<classname, double> { \
120 public: \
121 using SuperType = Vector3DParameter<classname, type_> SuperType; \
122 static std::string parameterName() { return #classname; } \
123 classname(type_ a, type_ b, type_ c) : SuperType(a, b, c) {} \
124 classname() : SuperType() {} \
125 std::string getName() const { return #classname; } \
126 classname *clone() const { return new classname(m_vector[0], m_vector[1], m_vector[2]); } \
127 };
128} // namespace MDAlgorithms
129} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Abstract parameter type for use with IImplicitFunctions.
Vector3DParameter is abstract type implementing curiously recurring template pattern to implement com...
bool operator==(const Derived &other) const
bool operator!=(const Derived &other) const
Derived & operator=(const Derived &other)
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)