Mantid
Loading...
Searching...
No Matches
ImplicitFunctionParserFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8
9#include <Poco/DOM/DOMParser.h>
10#include <Poco/DOM/Document.h>
11#include <Poco/DOM/Element.h>
12#include <Poco/DOM/NodeList.h>
13
14namespace Mantid::API {
15
16std::shared_ptr<ImplicitFunctionParser> ImplicitFunctionParserFactoryImpl::create(const std::string &xmlString) const {
17 UNUSED_ARG(xmlString);
18 throw std::runtime_error("Use of create in this context is forbidden. Use "
19 "createUnwrappedInstead.");
20}
21
24 const std::string &name = functionElement->localName();
25 if (name != "Function") {
26 throw std::runtime_error("Root node must be a Funtion element. Unable to determine parsers.");
27 }
28
29 Poco::XML::Element *typeElement = functionElement->getChildElement("Type");
30 std::string functionParserName = typeElement->innerText() + "Parser";
31 ImplicitFunctionParser *functionParser = this->createUnwrapped(functionParserName);
32
33 Poco::XML::Element *parametersElement = functionElement->getChildElement("ParameterList");
34
35 // Get the parameter parser for the current function parser and append that to
36 // the function parser.
38 Mantid::API::ImplicitFunctionParameterParserFactory::Instance().createImplicitFunctionParameterParserFromXML(
39 parametersElement);
40 functionParser->setParameterParser(paramParser);
41
42 Poco::AutoPtr<Poco::XML::NodeList> childFunctions = functionElement->getElementsByTagName("Function");
43 ImplicitFunctionParser *childParser = nullptr;
44 for (unsigned long i = 0; i < childFunctions->length(); i++) {
45 // Recursive call to handle nested parameters.
46 ImplicitFunctionParser *tempParser =
47 createImplicitFunctionParserFromXML(dynamic_cast<Poco::XML::Element *>(childFunctions->item(i)));
48 if (i == 0) {
49 childParser = tempParser;
50 // Add the first child function parser to the parent (composite) directly.
51 functionParser->setSuccessorParser(childParser);
52 } else {
53 // Add all other function parsers are added as successors to those before
54 // them in the loop.
55 childParser->setSuccessorParser(tempParser);
56 childParser = tempParser;
57 }
58 }
59
60 return functionParser;
61}
62
65 using namespace Poco::XML;
66 DOMParser pParser;
67 AutoPtr<Document> pDoc = pParser.parseString(functionXML);
68 Element *pRootElem = pDoc->documentElement();
69
71}
72} // namespace Mantid::API
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
ImplicitFunctionParser * createImplicitFunctionParserFromXML(const std::string &functionXML) const
std::shared_ptr< ImplicitFunctionParser > create(const std::string &xmlString) const override
Creates a new instance of the class with the given name.
XML Parser for function types.
virtual void setParameterParser(ImplicitFunctionParameterParser *parser)=0
virtual void setSuccessorParser(ImplicitFunctionParser *parser)=0
virtual ImplicitFunctionParser * createUnwrapped(const std::string &className) const
Creates a new instance of the class with the given name, which is not wrapped in a boost shared_ptr.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...