Mantid
Loading...
Searching...
No Matches
Vector3DParameterParser.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
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13
14#include <boost/algorithm/string.hpp>
15
16namespace Poco {
17namespace DOM {
18class Element;
19}
20} // namespace Poco
21namespace Mantid {
22namespace MDAlgorithms {
30template <class VectorValueParameterType>
32public:
33 VectorValueParameterType *parseVectorParameter(std::string value);
34
35 Mantid::API::ImplicitFunctionParameter *createParameter(Poco::XML::Element *parameterElement) override;
36
37 void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override;
38};
39
41
42template <typename VectorValueParameterType>
44 std::vector<std::string> strs;
45 boost::split(strs, value, boost::is_any_of(","));
46
47 double nx, ny, nz;
48 try {
49 nx = std::stod(strs.at(0));
50 ny = std::stod(strs.at(1));
51 nz = std::stod(strs.at(2));
52 } catch (std::exception &ex) {
53 std::string message =
54 std::string(ex.what()) + " Failed to parse " + VectorValueParameterType::parameterName() + " value: " + value;
55 throw std::invalid_argument(message.c_str());
56 }
57 return new VectorValueParameterType(nx, ny, nz);
58}
59
60template <typename VectorValueParameterType>
63 std::string typeName = parameterElement->getChildElement("Type")->innerText();
64 if (VectorValueParameterType::parameterName() != typeName) {
65 return m_successor->createParameter(parameterElement);
66 } else {
67 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
68 return parseVectorParameter(sParameterValue);
69 }
70}
71
72template <typename VectorValueParameterType>
76 m_successor.swap(temp);
77}
78} // namespace MDAlgorithms
79} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
boost::interprocess::unique_ptr< ImplicitFunctionParameterParser, DeleterPolicy< ImplicitFunctionParameterParser > > SuccessorType
Successor type.
Abstract parameter type for use with IImplicitFunctions.
XML parser for vector value (3 elements) parameter types.
VectorValueParameterType * parseVectorParameter(std::string value)
Mantid::API::ImplicitFunctionParameter * createParameter(Poco::XML::Element *parameterElement) override
void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30