|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include "Teuchos_ConfigDefs.hpp" 00030 #include "Teuchos_XMLParser.hpp" 00031 #include "Teuchos_XMLObject.hpp" 00032 #include "Teuchos_GlobalMPISession.hpp" 00033 #include "Teuchos_StringInputSource.hpp" 00034 #include "Teuchos_Version.hpp" 00035 #include "Teuchos_ParameterList.hpp" 00036 #include "Teuchos_XMLParameterListWriter.hpp" 00037 #include "Teuchos_XMLParameterListReader.hpp" 00038 00039 using std::string; 00040 using Teuchos::ParameterList; 00041 using Teuchos::XMLObject; 00042 using Teuchos::XMLParser; 00043 using Teuchos::XMLParameterListReader; 00044 using Teuchos::XMLParameterListWriter; 00045 using Teuchos::StringInputSource; 00046 00047 /* Test of Teuchos XMLParser class */ 00048 00049 int main(int argc, char** argv) 00050 { 00051 std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl; 00052 00053 bool testfailed = false; 00054 double tmp; 00055 00056 Teuchos::GlobalMPISession mpiSession(&argc, &argv); 00057 00058 try 00059 { 00060 00061 /* create a ParameterList object */ 00062 ParameterList problem("Problem"); 00063 ParameterList solver("Solver"); 00064 ParameterList prec("Preconditioner"); 00065 prec.set("type", "ILUk"); // set some of these to isUsed for completeness 00066 { 00067 std::string l_tmp = prec.get<std::string>("type"); 00068 } 00069 prec.set("k", 2); 00070 solver.set("Preconditioner",prec); 00071 solver.set("type", "gmres"); // set some of these to isUsed for completeness 00072 { 00073 std::string l_tmp = solver.get<std::string>("type"); 00074 } 00075 solver.set("maxiters", 1000); 00076 solver.set("restarts", 100); 00077 solver.set("special1","\"&\""); // test the XML outputting and parsing for correctness 00078 solver.set("special2","\'&\'"); // test the XML outputting and parsing for correctness 00079 solver.set("special3","\"&\'"); // test the XML outputting and parsing for correctness 00080 solver.set("tol", 1.0e-10); // set some of these to isUsed for completeness 00081 { 00082 tmp = solver.get<double>("tol"); 00083 } 00084 problem.set("Solver",solver); 00085 00086 std::cout << "*** ParameterList (original)" << std::endl; 00087 std::cout << problem << std::endl; 00088 00089 /* create an XML object from the ParameterList */ 00090 XMLParameterListWriter xml2pl; 00091 XMLObject xmlprob1 = xml2pl.toXML(problem); 00092 00093 /* write the XML to a std::string */ 00094 std::ostringstream ss; 00095 ss << xmlprob1; 00096 std::string strproblem = ss.str(); 00097 00098 std::cout << "*** XML from ParameterListParameterListWriter.toXML().toString()" << std::endl; 00099 std::cout << xmlprob1 << std::endl; 00100 00101 /* create a input source, parser to read the std::string */ 00102 StringInputSource src(strproblem); 00103 XMLParser parser(src.stream()); 00104 00105 /* parse XML in a std::string */ 00106 XMLObject xmlprob2 = parser.parse(); 00107 00108 std::cout << "*** XML from XMLParser.parse()" << std::endl; 00109 std::cout << xmlprob2 << std::endl; 00110 00111 /* convert the new XML object to a ParameterList */ 00112 XMLParameterListReader pl2xml; 00113 ParameterList problem2 = pl2xml.toParameterList(xmlprob2); 00114 00115 std::cout << "*** ParameterList from XMLParameterListReader.toParameterList()" << std::endl; 00116 std::cout << problem2 << std::endl; 00117 00118 /* check that the new parameter list matches the old one */ 00119 if (problem2 != problem) { 00120 testfailed = true; 00121 } 00122 } 00123 catch(std::exception& e) 00124 { 00125 std::cerr << e.what() << std::endl; 00126 testfailed = true; 00127 } 00128 00129 if (testfailed) { 00130 std::cout << "End Result: TEST FAILED" << std::endl; 00131 return -1; 00132 } 00133 00134 std::cout << "End Result: TEST PASSED" << std::endl; 00135 return 0; 00136 }
1.7.4