xml_parser_impl.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __XIOS_CXML_PARSER_IMPL__
  2. #define __XIOS_CXML_PARSER_IMPL__
  3. /// XIOS headers ///
  4. #include "xml_parser.hpp"
  5. namespace xios
  6. {
  7. namespace xml
  8. {
  9. template <class T> void CXMLParser::ParseInclude(StdIStream & stream, const string& fluxId, T& object)
  10. {
  11. StdOStringStream oss;
  12. while(!stream.eof() && !stream.fail ()) oss.put(stream.get());
  13. const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 );
  14. try
  15. {
  16. rapidxml::xml_document<char> doc;
  17. doc.parse<0>(const_cast<char*>(xmlcontent.c_str()));
  18. CXMLNode node(doc.first_node());
  19. object.parse(node);
  20. }
  21. catch (rapidxml::parse_error & exc)
  22. {
  23. const char* ptr = exc.where<char>() ;
  24. const char* begin = xmlcontent.c_str() ;
  25. const char* content=oss.str().c_str() ;
  26. size_t pos=ptr-begin ;
  27. int lineNumber = 1 ;
  28. int columnNumber = 0 ;
  29. const char* line;
  30. const char* endLine;
  31. for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;}
  32. for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ;
  33. string strLine(line,endLine-line) ;
  34. ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl
  35. << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl
  36. << strLine<<endl
  37. << string(columnNumber-1,'x')<<'^'<<endl
  38. <<" Error : " << exc.what() )
  39. }
  40. }
  41. } // namespace xml
  42. } // namespace xios
  43. #endif // __XIOS_CXML_PARSER_IMPL__