Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_XMLParameterListCoreHelpers.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
15#include <fstream>
16
17void Teuchos::updateParametersFromXmlFile(
18 const std::string &xmlFileName,
19 const Ptr<ParameterList> &paramList
20 )
21{
22 XMLParameterListReader xmlPLReader;
23 xmlPLReader.setAllowsDuplicateSublists( false );
24 FileInputSource xmlFile(xmlFileName);
25 XMLObject xmlParams = xmlFile.getObject();
26 paramList->setParameters(xmlPLReader.toParameterList(xmlParams));
27}
28
29
31Teuchos::getParametersFromXmlFile(const std::string &xmlFileName)
32{
33 RCP<ParameterList> pl = parameterList();
34 updateParametersFromXmlFile(xmlFileName, pl.ptr());
35 return pl;
36}
37
38
40Teuchos::getParametersFromXmlFile(
41 const std::string &xmlFileName,
42 RCP<DependencySheet> depSheet)
43{
44 XMLParameterListReader xmlPLReader;
45 xmlPLReader.setAllowsDuplicateSublists( false );
46 FileInputSource xmlFile(xmlFileName);
47 XMLObject xmlParams = xmlFile.getObject();
48 return xmlPLReader.toParameterList(xmlParams, depSheet);
49}
50
51
52void Teuchos::updateParametersFromXmlString(
53 const std::string &xmlStr,
54 const Ptr<ParameterList> &paramList,
55 bool overwrite
56 )
57{
58 XMLParameterListReader xmlPLReader;
59 xmlPLReader.setAllowsDuplicateSublists( false );
60 StringInputSource xmlStrSrc(xmlStr);
61 XMLObject xmlParams = xmlStrSrc.getObject();
62 if(overwrite) paramList->setParameters(xmlPLReader.toParameterList(xmlParams));
63 else paramList->setParametersNotAlreadySet(xmlPLReader.toParameterList(xmlParams));
64}
65
66
68Teuchos::getParametersFromXmlString(const std::string &xmlStr)
69{
70 RCP<ParameterList> pl = parameterList();
71 updateParametersFromXmlString(xmlStr, pl.ptr());
72 return pl;
73}
74
75
77Teuchos::getParametersFromXmlString(const std::string &xmlStr,
78 RCP<DependencySheet> depSheet)
79{
80 XMLParameterListReader xmlPLReader;
81 xmlPLReader.setAllowsDuplicateSublists( false );
82 StringInputSource xmlStrSrc(xmlStr);
83 XMLObject xmlParams = xmlStrSrc.getObject();
84 return xmlPLReader.toParameterList(xmlParams, depSheet);
85}
86
87
88void Teuchos::writeParameterListToXmlOStream(
89 const ParameterList &paramList,
90 std::ostream &xmlOut,
91 RCP<const DependencySheet> depSheet
92 )
93{
94 XMLParameterListWriter plWriter;
95 XMLObject xml = plWriter.toXML(paramList, depSheet);
96 xmlOut << xml << std::endl;
97}
98
99
100void Teuchos::writeParameterListToXmlFile(
101 const ParameterList &paramList,
102 const std::string &xmlFileName,
103 RCP<const DependencySheet> depSheet
104 )
105{
106 std::ofstream ofs(xmlFileName.c_str());
107 writeParameterListToXmlOStream(paramList,ofs, depSheet);
108}
Definition of XMLInputSource derived class for reading XML from a file.
Definition of XMLInputSource derived class for reading XML from a std::string.
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
Writes an XML object to a parameter list.
Writes a ParameterList to an XML object.
Smart reference counting pointer class for automatic garbage collection.