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 "MantidKernel/System.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
30namespace Mantid {
31namespace API {
40template <class SingleValueParameterType>
42public:
43 Mantid::API::ImplicitFunctionParameter *createParameter(Poco::XML::Element *parameterElement) override;
44
45 SingleValueParameterType *createWithoutDelegation(Poco::XML::Element *parameterElement);
46
47 void setSuccessorParser(Mantid::API::ImplicitFunctionParameterParser *paramParser) override;
48};
49
51
52//------------------------------------------------------------------------------
53/* Creates a parameter from an xml element, otherwise defers to a successor
54parser.
55@param parameterElement : xml Element
56@return A fully constructed ImplicitFunctionParameter.
57*/
58template <class SingleValueParameterType>
61 using ValType = typename SingleValueParameterType::ValueType;
62 std::string typeName = parameterElement->getChildElement("Type")->innerText();
63 if (SingleValueParameterType::parameterName() != typeName) {
64 return m_successor->createParameter(parameterElement);
65 } else {
66 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
67 ValType value = boost::lexical_cast<ValType>(sParameterValue);
68 return new SingleValueParameterType(value);
69 }
70}
71
72//------------------------------------------------------------------------------
73/* Creates a parameter from an xml element. This is single-shot. Does not defer
74to successor if it fails!.
75@param parameterElement : xml Element
76@return A fully constructed SingleValueParameterType.
77*/
78template <class SingleValueParameterType>
79SingleValueParameterType *
81 using ValType = typename SingleValueParameterType::ValueType;
82 std::string typeName = parameterElement->getChildElement("Type")->innerText();
83 if (SingleValueParameterType::parameterName() != typeName) {
84 throw std::runtime_error("The attempted ::createWithoutDelegation failed. "
85 "The type provided does not match this parser.");
86 } else {
87 std::string sParameterValue = parameterElement->getChildElement("Value")->innerText();
88 ValType value = boost::lexical_cast<ValType>(sParameterValue);
89 return new SingleValueParameterType(value);
90 }
91}
92
93//------------------------------------------------------------------------------
94/* Sets the successor parser
95@param parameterParser : the parser to defer to if the current instance can't
96handle the parameter type.
97*/
98template <class SingleValueParameterType>
102 m_successor.swap(temp);
103}
104} // namespace API
105} // 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 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.