Mantid
Loading...
Searching...
No Matches
VectorParameterParser.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//----------------------------------------------------------------------
12#include "MantidKernel/System.h"
13
15
16#include <Poco/DOM/DOMParser.h>
17#include <Poco/DOM/Document.h>
18#include <Poco/DOM/Element.h>
19#include <Poco/DOM/NodeFilter.h>
20#include <Poco/DOM/NodeIterator.h>
21#include <Poco/DOM/NodeList.h>
22#include <Poco/File.h>
23#include <Poco/Path.h>
24#ifndef Q_MOC_RUN
25#include <boost/lexical_cast.hpp>
26#endif
27
28namespace Mantid {
29namespace API {
37template <class VectorValueParameterType>
39public:
40 VectorValueParameterType *parseVectorParameter(std::string sValue);
41
42 Mantid::API::ImplicitFunctionParameter *createParameter(Poco::XML::Element *parameterElement) override;
43
44 VectorValueParameterType *createWithoutDelegation(Poco::XML::Element *parameterElement);
45
46 void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override;
47};
48
50
51//----------------------------------------------------------------------
52/* Parse the value aspect of the parameter only.
53@param sValue : parameter value in string form.
54@return new parameter object.
55*/
56template <typename VectorValueParameterType>
57VectorValueParameterType *VectorParameterParser<VectorValueParameterType>::parseVectorParameter(std::string sValue) {
58 std::vector<std::string> strs;
59 boost::split(strs, sValue, boost::is_any_of(","));
60
61 auto product = new VectorValueParameterType(strs.size());
62 using ValType = typename VectorValueParameterType::ValueType;
63
64 for (size_t i = 0; i < strs.size(); i++) {
65 boost::erase_all(strs[i], " ");
66 ValType value = boost::lexical_cast<ValType>(strs[i]);
67 product->addValue(i, value);
68 }
69 return product;
70}
71
72//----------------------------------------------------------------------
73/* Create parameter from xml element.
74@param parameterElement : XML element containing the parameter info.
75@return new parameter object.
76*/
77template <typename VectorValueParameterType>
80 std::string typeName = parameterElement->getChildElement("Type")->innerText();
81 if (VectorValueParameterType::parameterName() != typeName) {
82 if (!m_successor) {
83 throw std::runtime_error("No successor ParameterParser!");
84 }
85 return m_successor->createParameter(parameterElement);
86 } else {
87 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
88 return parseVectorParameter(sParameterValue);
89 }
90}
91
92//------------------------------------------------------------------------------
93/* Creates a parameter from an xml element. This is single-shot. Does not defer
94to successor if it fails!.
95@param parameterElement : xml Element
96@return A fully constructed VectorValueParameterType.
97*/
98template <class VectorValueParameterType>
99VectorValueParameterType *
101 std::string typeName = parameterElement->getChildElement("Type")->innerText();
102 if (VectorValueParameterType::parameterName() != typeName) {
103 throw std::runtime_error("The attempted ::createWithoutDelegation failed. "
104 "The type provided does not match this parser.");
105 } else {
106 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
107 return parseVectorParameter(sParameterValue);
108 }
109}
110
111//----------------------------------------------------------------------
112/* Setter for a successor parser.
113@param paramParser : successor
114*/
115template <typename VectorValueParameterType>
119 m_successor.swap(temp);
120}
121} // namespace API
122} // namespace Mantid
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
boost::interprocess::unique_ptr< ImplicitFunctionParameterParser, DeleterPolicy< ImplicitFunctionParameterParser > > SuccessorType
Successor type.
Abstract parameter type for use with IImplicitFunctions.
XML parser for vector value (n elements) parameter types.
void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override
VectorValueParameterType * createWithoutDelegation(Poco::XML::Element *parameterElement)
VectorValueParameterType * parseVectorParameter(std::string sValue)
Mantid::API::ImplicitFunctionParameter * createParameter(Poco::XML::Element *parameterElement) override
Helper class which provides the Collimation Length for SANS instruments.