void Teuchos::updateParametersFromXmlFileAndBroadcast(
  const std::string &xmlFileName,
  const Ptr<ParameterList> &paramList,
  const Comm<int> &comm
  )
{
  if (comm.getSize()==1)
    updateParametersFromXmlFile(xmlFileName, paramList);
  else {
    if (comm.getRank()==0) {
      XMLParameterListReader xmlPLReader;
      xmlPLReader.setAllowsDuplicateSublists( false );
      FileInputSource xmlFile(xmlFileName);
      XMLObject xmlParams = xmlFile.getObject();
      std::string xmlString = toString(xmlParams);
      int strsize = xmlString.size();
      broadcast<int, int>(comm, 0, &strsize);
      broadcast<int, char>(comm, 0, strsize, &xmlString[0]);
      updateParametersFromXmlString(xmlString, paramList);
    }
    else {
      int strsize;
      broadcast<int, int>(comm, 0, &strsize);
      std::string xmlString;
      xmlString.resize(strsize);
      broadcast<int, char>(comm, 0, strsize, &xmlString[0]);
      updateParametersFromXmlString(xmlString, paramList);
    }
  }
}
示例#2
0
Teuchos::RCP<Teuchos::ParameterList>
Teuchos::getParametersFromXmlString(const std::string &xmlStr)
{
  RCP<ParameterList> pl = parameterList();
  updateParametersFromXmlString(xmlStr, pl.ptr());
  return pl;
}
 TEUCHOS_UNIT_TEST( ParameterList, ExistingSublistIsOkay )
 {
   std::string xmlstring(
       "<ParameterList>                   \n"
       "  <ParameterList name=\"SubList\">\n"
       "  </ParameterList>                \n"
       "</ParameterList>                  \n");
   RCP<ParameterList> plist = getParametersFromXmlString(xmlstring);
   updateParametersFromXmlString( xmlstring, plist() );
 }
 TEUCHOS_UNIT_TEST( ParameterList, XMLDuplicatedSublists )
 {
   ParameterList pl;
   TEST_THROW( updateParametersFromXmlFile(filename, inOutArg(pl) ), DuplicateParameterSublist );
   TEST_THROW( getParametersFromXmlFile(filename), DuplicateParameterSublist );
   TEST_THROW( getParametersFromXmlFile(filename,null), DuplicateParameterSublist );
   //
   std::ifstream fin(filename.c_str());
   std::string xmlstring( (std::istreambuf_iterator<char>(fin)),
                           std::istreambuf_iterator<char>()      );
   TEST_THROW( updateParametersFromXmlString(xmlstring,inOutArg(pl) ), DuplicateParameterSublist );
   TEST_THROW( getParametersFromXmlString(xmlstring), DuplicateParameterSublist );
   TEST_THROW( getParametersFromXmlString(xmlstring,null), DuplicateParameterSublist );
 }