Mantid
Loading...
Searching...
No Matches
SingleValueParameterParser.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
13#include "MantidAPI/DllConfig.h"
14
15#include <Poco/DOM/DOMParser.h>
16#include <Poco/DOM/Document.h>
17#include <Poco/DOM/Element.h>
18#include <Poco/DOM/NodeFilter.h>
19#include <Poco/DOM/NodeIterator.h>
20#include <Poco/DOM/NodeList.h>
21#include <Poco/File.h>
22#include <Poco/Path.h>
23
25
26#ifndef Q_MOC_RUN
27#include <boost/lexical_cast.hpp>
28#endif
29
30#include <stdexcept>
31#include <string>
32
33namespace Mantid {
34namespace API {
43template <class SingleValueParameterType>
45public:
46 Mantid::API::ImplicitFunctionParameter *createParameter(Poco::XML::Element *parameterElement) override;
47
48 SingleValueParameterType *createWithoutDelegation(Poco::XML::Element *parameterElement);
49
51};
52
54
55//------------------------------------------------------------------------------
56/* Creates a parameter from an xml element, otherwise defers to a successor
57parser.
58@param parameterElement : xml Element
59@return A fully constructed ImplicitFunctionParameter.
60*/
61template <class SingleValueParameterType>
64 using ValType = typename SingleValueParameterType::ValueType;
65 std::string typeName = parameterElement->getChildElement("Type")->innerText();
66 if (SingleValueParameterType::parameterName() != typeName) {
67 return m_successor->createParameter(parameterElement);
68 } else {
69 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
70 ValType value = boost::lexical_cast<ValType>(sParameterValue);
71 return new SingleValueParameterType(value);
72 }
73}
74
75//------------------------------------------------------------------------------
76/* Creates a parameter from an xml element. This is single-shot. Does not defer
77to successor if it fails!.
78@param parameterElement : xml Element
79@return A fully constructed SingleValueParameterType.
80*/
81template <class SingleValueParameterType>
82SingleValueParameterType *
84 using ValType = typename SingleValueParameterType::ValueType;
85 std::string typeName = parameterElement->getChildElement("Type")->innerText();
86 if (SingleValueParameterType::parameterName() != typeName) {
87 throw std::runtime_error("The attempted ::createWithoutDelegation failed. "
88 "The type provided does not match this parser.");
89 } else {
90 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
91 ValType value = boost::lexical_cast<ValType>(sParameterValue);
92 return new SingleValueParameterType(value);
93 }
94}
95
96//------------------------------------------------------------------------------
97/* Sets the successor parser
98@param parameterParser : the parser to defer to if the current instance can't
99handle the parameter type.
100*/
101template <class SingleValueParameterType>
107} // namespace API
108} // 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 single value parameter types.
SingleValueParameterType * createWithoutDelegation(Poco::XML::Element *parameterElement)
void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override
Mantid::API::ImplicitFunctionParameter * createParameter(Poco::XML::Element *parameterElement) override
Helper class which provides the Collimation Length for SANS instruments.