test/XML/cxx_main.cpp

Go to the documentation of this file.
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_XMLObject.hpp"
00031 #include "Teuchos_GlobalMPISession.hpp"
00032 #include "Teuchos_StringInputSource.hpp"
00033 #include "Teuchos_FileInputSource.hpp"
00034 #include "Teuchos_Version.hpp"
00035 
00036 
00037 using std::string;
00038 using Teuchos::XMLObject;
00039 using Teuchos::StringInputSource;
00040 using Teuchos::FileInputSource;
00041 
00042 /* Test of Teuchos XML handling classes */
00043 
00044 int main(int argc, char** argv)
00045 {
00046   std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
00047 
00048   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00049 
00050   try
00051     {
00052       /* create an XML object */
00053       XMLObject problem("Problem");
00054       XMLObject solver("Solver");
00055       XMLObject prec("Preconditioner");
00056 
00057       solver.addAttribute("type", "gmres");
00058       solver.addInt("maxiters", 1000);
00059       solver.addInt("restarts", 100);
00060       solver.addDouble("tol", 1.0e-10);
00061 
00062       solver.addChild(prec);
00063 
00064       prec.addAttribute("type", "ILUk");
00065       prec.addInt("k", 2);
00066 
00067       problem.addChild(solver);
00068 
00069       std::string str = problem.toString();
00070       std::cerr << str << std::endl;
00071 
00072       /* parse XML in a std::string */
00073       StringInputSource src(str);
00074       XMLObject reread = src.getObject();
00075       
00076       std::cerr << reread << std::endl;
00077 
00078       /* write to a file, and then read and parse the file */
00079       std::ofstream of("tmp.xml");
00080       of << reread << std::endl;
00081       
00082       FileInputSource fileSrc("tmp.xml");
00083       XMLObject fileXML = fileSrc.getObject();
00084       
00085       std::cerr << fileXML << std::endl;
00086 
00087       return 0;
00088     }
00089   catch(std::exception& e)
00090     {
00091       std::cerr << e.what() << std::endl;
00092     }
00093 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 09:57:28 2011 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.3