xml_group_reader.cc

Go to the documentation of this file.
00001 // $Id: xml_group_reader.cc,v 1.3 2007/06/11 03:26:43 edwards Exp $
00002 /*! \file
00003  *  \brief Read an XML group as a string
00004  */
00005 
00006 #include "io/xml_group_reader.h"
00007 
00008 namespace Chroma 
00009 {
00010 
00011   // Read group and return as a string
00012   GroupXML_t readXMLGroup(XMLReader& xml_in, 
00013                           const std::string& path, const std::string& type_name)
00014   {
00015     GroupXML_t group;
00016 
00017 //    QDPIO::cout << __func__ << ": here is the current context XX";
00018 //    xml_in.printCurrentContext(cout);
00019 //    QDPIO::cout << "XX" << endl;
00020 
00021     try
00022     {
00023       XMLReader xml_tmp(xml_in, path);
00024       std::ostringstream os;
00025       xml_tmp.print(os);
00026       read(xml_tmp, type_name, group.id);
00027       group.xml = os.str();
00028       group.path = "/" + path;
00029     }
00030     catch(const std::string& e) 
00031     {
00032       QDPIO::cerr << __func__ << ": caught exception reading XML: " << e << endl;
00033       QDP_abort(1);
00034     }
00035 
00036     return group;
00037   }
00038 
00039 
00040   // Read group and return as a string
00041   multi1d<GroupXML_t> readXMLArrayGroup(XMLReader& xml_in, 
00042                                         const std::string& path, 
00043                                         const std::string& type_name)
00044   {
00045     multi1d<GroupXML_t> group;
00046 
00047 //    QDPIO::cout << __func__ << ": here is the current context XX";
00048 //    xml_in.printCurrentContext(cout);
00049 //    QDPIO::cout << "XX" << endl;
00050 
00051     try
00052     {
00053       XMLReader xml_tmp(xml_in, path);
00054       group.resize(xml_tmp.count("elem"));
00055 
00056       for(int i=0; i < group.size(); i++) 
00057       {
00058         // Create the query for the element 
00059         std::ostringstream element_xpath;
00060         element_xpath << "elem[" << (i+1) << "]";
00061 
00062         XMLReader xml_elem(xml_tmp, element_xpath.str());
00063         std::ostringstream os;
00064         xml_elem.print(os);
00065         read(xml_elem, type_name, group[i].id);
00066         group[i].xml = os.str();
00067         group[i].path = "/elem";
00068       }
00069     }
00070     catch(const std::string& e) 
00071     {
00072       QDPIO::cerr << __func__ << ": caught exception reading XML: " << e << endl;
00073       QDP_abort(1);
00074     }
00075 
00076     return group;
00077   }
00078 
00079 }  // end namespace Chroma

Generated on Sun Mar 14 04:38:18 2010 for CHROMA by  doxygen 1.4.7