Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_XMLParameterListHelpers.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 
13 #include "Teuchos_CommHelpers.hpp"
14 
15 void Teuchos::updateParametersFromXmlFileAndBroadcast(
16  const std::string &xmlFileName,
17  const Ptr<ParameterList> &paramList,
18  const Comm<int> &comm,
19  bool overwrite
20  )
21 {
22  if (comm.getSize()==1)
23  updateParametersFromXmlFile(xmlFileName, paramList);
24  else {
25  if (comm.getRank()==0) {
26  XMLParameterListReader xmlPLReader;
27  xmlPLReader.setAllowsDuplicateSublists( false );
28  FileInputSource xmlFile(xmlFileName);
29  XMLObject xmlParams = xmlFile.getObject();
30  std::string xmlString = toString(xmlParams);
31  int strsize = static_cast<int>(xmlString.size());
32  broadcast<int, int>(comm, 0, &strsize);
33  broadcast<int, char>(comm, 0, strsize, &xmlString[0]);
34  updateParametersFromXmlString(xmlString, paramList,overwrite);
35  }
36  else {
37  int strsize;
38  broadcast<int, int>(comm, 0, &strsize);
39  std::string xmlString;
40  xmlString.resize(strsize);
41  broadcast<int, char>(comm, 0, strsize, &xmlString[0]);
42  updateParametersFromXmlString(xmlString, paramList,overwrite);
43  }
44  }
45 }
Writes an XML object to a parameter list.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlFile(const std::string &xmlFileName, const Ptr< ParameterList > &paramList)
Reads XML parameters from a file and updates those already in the given parameter list...
std::string toString(const any &rhs)
Converts the value in any to a std::string.
Additional ParameterList XML helper functions including parallel support.
Definition of XMLInputSource derived class for reading XML from a file.
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlString(const std::string &xmlStr, const Ptr< ParameterList > &paramList, bool overwrite=true)
Reads XML parameters from a std::string and updates those already in the given parameter list...