Mantid
Loading...
Searching...
No Matches
ImplicitFunctionParameter.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 <memory>
13#include <sstream>
14#include <vector>
15
16#include "MantidAPI/DllConfig.h"
17
18#ifndef Q_MOC_RUN
19#include <boost/algorithm/string.hpp>
20#include <boost/format.hpp>
21#endif
22
23#include <Poco/DOM/AutoPtr.h>
24#include <Poco/DOM/DOMWriter.h>
25#include <Poco/DOM/Document.h>
26#include <Poco/DOM/Element.h>
27#include <Poco/DOM/Text.h>
28
29namespace Mantid {
30namespace API {
37class MANTID_API_DLL ImplicitFunctionParameter {
38
39public:
40 virtual std::string getName() const = 0;
41
42 virtual bool isValid() const = 0;
43
44 virtual std::string toXMLString() const = 0;
45
46 virtual ImplicitFunctionParameter *clone() const = 0;
47
48 virtual ~ImplicitFunctionParameter() = default;
49
50protected:
51 bool m_isValid{false};
52
53 std::string parameterXMLTemplate(const std::string &valueXMLtext) const {
54 using namespace Poco::XML;
55 AutoPtr<Document> pDoc = new Document;
56 AutoPtr<Element> paramElement = pDoc->createElement("Parameter");
57
58 pDoc->appendChild(paramElement);
59 AutoPtr<Element> typeElement = pDoc->createElement("Type");
60 AutoPtr<Text> typeText = pDoc->createTextNode(this->getName());
61 typeElement->appendChild(typeText);
62 paramElement->appendChild(typeElement);
63
64 AutoPtr<Element> valueElement = pDoc->createElement("Value");
65 AutoPtr<Text> valueText = pDoc->createTextNode(valueXMLtext);
66 valueElement->appendChild(valueText);
67 paramElement->appendChild(valueElement);
68
69 std::stringstream xmlstream;
70
71 DOMWriter writer;
72 writer.writeNode(xmlstream, pDoc);
73 return xmlstream.str();
74 }
75};
76
77//------------------------------------------------------------------------------------
78// ElementTraits TypeTraits region
79//------------------------------------------------------------------------------------
80
85template <typename T> struct ElementTraits {};
86
89template <> struct ElementTraits<size_t> {
90 using ValueType = size_t;
91 static std::string formatCS(const ValueType &value) { return boost::str(boost::format("%u,") % value); }
92 static std::string format(const ValueType &value) { return boost::str(boost::format("%u") % value); }
93};
94
97template <> struct ElementTraits<bool> {
98 using ValueType = bool;
99 static std::string formatCS(const ValueType &value) { return boost::str(boost::format("%u,") % value); }
100 static std::string format(const ValueType &value) { return boost::str(boost::format("%u") % value); }
101};
102
105template <> struct ElementTraits<double> {
106 using ValueType = double;
107 static std::string formatCS(const ValueType &value) { return boost::str(boost::format("%.4f,") % value); }
108 static std::string format(const ValueType &value) { return boost::str(boost::format("%.4f") % value); }
109};
110
113template <> struct ElementTraits<float> {
114 using ValueType = double;
115 static std::string formatCS(const ValueType &value) { return boost::str(boost::format("%.4f,") % value); }
116 static std::string format(const ValueType &value) { return boost::str(boost::format("%.4f") % value); }
117};
118
119//------------------------------------------------------------------------------------
120// End ElementTraits TypeTraits region
121//------------------------------------------------------------------------------------
122} // namespace API
123} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
std::string getName(const IMDDimension &self)
Abstract parameter type for use with IImplicitFunctions.
std::string parameterXMLTemplate(const std::string &valueXMLtext) const
virtual ~ImplicitFunctionParameter()=default
virtual std::string getName() const =0
virtual ImplicitFunctionParameter * clone() const =0
virtual std::string toXMLString() const =0
Helper class which provides the Collimation Length for SANS instruments.
static std::string format(const ValueType &value)
static std::string formatCS(const ValueType &value)
static std::string formatCS(const ValueType &value)
static std::string format(const ValueType &value)
static std::string format(const ValueType &value)
static std::string formatCS(const ValueType &value)
static std::string format(const ValueType &value)
static std::string formatCS(const ValueType &value)
Default ElementTraits SFINAE Typetraits are used to provide the correct formatting based on the eleme...