- Timestamp:
- 03/12/24 20:09:55 (11 months ago)
- Location:
- XIOS2/trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS2/trunk/src/group_template.hpp
r1542 r2615 51 51 virtual void parse(xml::CXMLNode & node); 52 52 virtual void parse(xml::CXMLNode & node, bool withAttr); 53 virtual void parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList); 54 53 55 virtual void parseChild(xml::CXMLNode & node); 54 56 -
XIOS2/trunk/src/group_template_impl.hpp
r1542 r2615 252 252 } 253 253 254 //---------------------------------------------------------------255 256 template <class U, class V, class W>257 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node)258 {259 this->parse(node, true);260 }261 254 262 255 //--------------------------------------------------------------- … … 511 504 } 512 505 506 //--------------------------------------------------------------- 507 508 template <class U, class V, class W> 509 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node) 510 { 511 this->parse(node, true); 512 } 513 514 template <class U, class V, class W> 515 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) 516 { 517 ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList)", 518 <<"must not be called by this kind of object : "<<GetName() ) ; 519 } 520 513 521 template <class U, class V, class W> 514 522 void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr) … … 520 528 { 521 529 CGroupTemplate<U, V, W>::SuperClass::parse(node); 522 if (attributes.end() != attributes.find("src")) 523 { 524 StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 525 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 526 ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 527 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 528 529 if (!ifs.good()) 530 ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 531 << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 532 xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this); 533 } 530 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this); 534 531 } 535 532 -
XIOS2/trunk/src/node/context.cpp
r2428 r2615 113 113 xml::THashAttributes attributes = node.getAttributes(); 114 114 115 if (attributes.end() != attributes.find("src")) 116 { 117 StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 118 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 119 ERROR("void CContext::parse(xml::CXMLNode & node)", 120 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 121 if (!ifs.good()) 122 ERROR("CContext::parse(xml::CXMLNode & node)", 123 << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 124 xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this); 125 } 115 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"], *this); 126 116 127 117 if (node.getElementName().compare(CContext::GetName())) … … 162 152 } 163 153 CATCH_DUMP_ATTR 154 155 template <> 156 void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) 157 TRY 158 { 159 StdString name = node.getElementName(); 160 xml::THashAttributes attributes = node.getAttributes(); 161 CGroupTemplate<CContext, CContextGroup, CContextAttributes>::SuperClass::parse(node); 162 if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this, parseContextList); 163 164 if (!(node.goToChildElement())) 165 { 166 // no children ? 167 } 168 else 169 { 170 do // Parcours pour traitement. 171 { 172 173 StdString name = node.getElementName(); 174 attributes.clear(); 175 attributes = node.getAttributes(); 176 177 if (name.compare(CContextGroup::GetName()) == 0) 178 { 179 CContextGroup contextGroup ; 180 contextGroup.parse(node, true, parseContextList) ; 181 continue; 182 } 183 184 if (name.compare(CContext::GetName()) == 0) 185 { 186 if (attributes.end() == attributes.find("id")) 187 { 188 DEBUG("The context will not be processed because it is not identified (missing id)"); 189 continue; 190 } 191 else 192 { 193 if (parseContextList.empty() || parseContextList.count(attributes["id"]) > 0) 194 { 195 CContext::setCurrent(attributes["id"]) ; 196 CContext* context = CContext::create(attributes["id"]); 197 context->parse(node); 198 attributes.clear(); 199 } 200 continue; 201 } 202 } 203 204 DEBUG(<< "Dans le contexte \'" << CContext::getCurrent()->getId() 205 << "\', un objet de type \'" << CContextGroup::GetName() 206 << "\' ne peut contenir qu'un objet de type \'" << CContextGroup::GetName() 207 << "\' ou de type \'" << CContext::GetName() 208 << "\' (reçu : " << name << ") !"); 209 210 } while (node.goToNextElement()); 211 node.goToParentElement(); // Retour au parent 212 } 213 } 214 CATCH_DUMP_ATTR 215 216 217 164 218 165 219 //---------------------------------------------------------------- -
XIOS2/trunk/src/node/context.hpp
r1639 r2615 274 274 // Declare/Define CContextGroup and CContextDefinition 275 275 DECLARE_GROUP(CContext); 276 template <> 277 void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) ; 276 278 277 279 ///-------------------------------------------------------------- -
XIOS2/trunk/src/string_tools.hpp
r1585 r2615 9 9 { 10 10 std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) ; 11 string strTrim(const std::string& input) ; 11 12 12 13 inline std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) … … 20 21 } 21 22 23 inline string strTrim(const std::string& input) 24 { 25 return std::regex_replace(input, std::regex("^ +| +$"), "$1"); 26 } 27 22 28 } 23 29 #endif -
XIOS2/trunk/src/xml_parser.cpp
r1622 r2615 6 6 #include "object_template.hpp" 7 7 #include "group_template.hpp" 8 #include "string_tools.hpp" 8 9 9 10 namespace xios … … 11 12 namespace xml 12 13 { 14 15 string CXMLParser::currentIncludePath_="." ; 16 17 string CXMLParser::updateIncludePath(const string& filePath) 18 { 19 string path = strTrim(filePath) ; 20 vector<string> match=splitRegex(path+'/',"/" ) ; 21 22 // check if empty path 23 bool isEmpty=true ; 24 for(auto& m : match) 25 if (!m.empty()) 26 { 27 isEmpty=false ; 28 break ; 29 } 30 31 if (isEmpty) ERROR("string CXMLParser::updatePath(const string& filePath)", 32 << "File path to include an new XML is empty :'"<<filePath<<"'" ); 33 34 if (match.back().empty()) ERROR("string CXMLParser::updatePath(const string& filePath)", 35 << "File path to include an new XML must not be a directory but a file :'"<<filePath<<"'" ); 36 bool isAbsolutePath = match.front().empty() ; 37 38 if (isAbsolutePath) currentIncludePath_="" ; 39 for(int i=0; i<match.size()-1; ++i) if (! match[i].empty()) currentIncludePath_ = currentIncludePath_ + "/" + match[i] ; 40 41 string finalPath = currentIncludePath_ + "/" + match.back() ; 42 43 return finalPath ; 44 } 45 46 13 47 /// ////////////////////// Définitions ////////////////////// /// 14 48 … … 52 86 << "Root element should be named simulation (actual = \'" 53 87 << node.getElementName() << "\')!"); 54 55 std::set<StdString>::iterator it;56 std::set<StdString>::const_iterator itE = parseContextList.end();57 bool isParseAll = (parseContextList.empty());58 88 try 59 89 { 60 if (node.goToChildElement()) 61 { 62 do 63 { 64 CContextGroup* group_context = CContext::getRoot() ; 65 66 attributes = node.getAttributes(); 67 68 if (attributes.end() == attributes.find("id")) 69 { 70 DEBUG("The context will not be processed because it is not identified (missing id)"); 71 continue; 72 } 73 74 CContext::setCurrent(attributes["id"]) ; 75 76 if (isParseAll) 77 { 78 CContext* context = CContext::create(attributes["id"]); 79 context->parse(node); 80 81 attributes.clear(); 82 } 83 else 84 { 85 it = parseContextList.find(attributes["id"]); 86 if (itE != it) 87 { 88 CContext* context = CContext::create(*it); 89 context->parse(node); 90 91 attributes.clear(); 92 } 93 } 94 } while (node.goToNextElement()); 95 } 90 CContextGroup* rootContext = CContext::getRoot() ; 91 rootContext->parse(node, true, parseContextList) ; 96 92 } 97 93 catch(CException& e) -
XIOS2/trunk/src/xml_parser.hpp
r1622 r2615 21 21 static void ParseString(const StdString & xmlContent); 22 22 static void ParseStream(StdIStream & stream, const string& fluxId, const std::set<StdString>& parseList); 23 23 24 template <class T> 24 static void ParseInclude(StdIStream & stream, const string& fluxId, T & object); 25 static void ParseInclude(const string& fluxId, T & object); 26 27 template <class T> 28 static void ParseInclude(const string& fluxId, T & object, const std::set<StdString>& parseContextList); 29 30 static string updateIncludePath(const string& filePath) ; 25 31 32 private: 33 static string currentIncludePath_ ; // current include path for XML file 26 34 }; //class CXMLParser 27 /*28 template <class T>29 void CXMLParser::ParseInclude(StdIStream & stream, T& object)30 {31 StdOStringStream oss;32 while(!stream.eof() && !stream.fail ())33 oss.put(stream.get());34 try35 {36 const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 );37 rapidxml::xml_document<char> doc;38 doc.parse<0>(const_cast<char*>(xmlcontent.c_str()));39 CXMLNode node(doc.first_node());40 object.parse(node);41 }42 catch (rapidxml::parse_error & exc)43 {44 ERROR("CXMLParser::ParseStream(StdIStream & stream)",45 << "RapidXML error : " << exc.what() << " !");46 }47 }48 */49 35 }// namespace xml 50 36 } // namespace xios -
XIOS2/trunk/src/xml_parser_decl.cpp
r1558 r2615 7 7 namespace xml 8 8 { 9 template void CXMLParser::ParseInclude<CContext>( StdIStream & stream,const string& fluxId, CContext& object) ;9 template void CXMLParser::ParseInclude<CContext>(const string& fluxId, CContext& object) ; 10 10 11 11 # define macro(T) \ 12 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(StdIStream & stream, const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ; 13 12 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ; 14 13 macro( Context ) 15 14 macro( Axis ) … … 40 39 macro( ReorderDomain ) 41 40 macro( ExtractDomain ) 41 42 # undef macro 43 # define macro(T) \ 44 template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object, const std::set<StdString>& parseContextList) ; 45 macro( Context ) 46 # undef macro 42 47 } 43 48 } -
XIOS2/trunk/src/xml_parser_impl.hpp
r1622 r2615 9 9 namespace xml 10 10 { 11 template <class T> void CXMLParser::ParseInclude(StdIStream & stream,const string& fluxId, T& object)11 template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object) 12 12 { 13 string parentPath = currentIncludePath_ ; 14 string filePath = updateIncludePath(fluxId) ; 15 16 StdIFStream stream(filePath, StdIFStream::in ) ; 17 if ( (stream.rdstate() & std::ifstream::failbit ) != 0 ) 18 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 19 <<endl<< "Can not open <"<<fluxId<<"> file" ); 20 21 if (!stream.good()) 22 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 23 << "[ filename = " << fluxId << " ] Bad xml stream !"); 24 13 25 StdOStringStream oss; 14 26 while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); … … 20 32 CXMLNode node(doc.first_node()); 21 33 object.parse(node); 34 currentIncludePath_ = parentPath ; 35 } 36 catch (rapidxml::parse_error & exc) 37 { 38 const char* ptr = exc.where<char>() ; 39 const char* begin = xmlcontent.c_str() ; 40 const char* content=oss.str().c_str() ; 41 size_t pos=ptr-begin ; 42 int lineNumber = 1 ; 43 int columnNumber = 0 ; 44 const char* line; 45 const char* endLine; 46 47 for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;} 48 for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ; 49 string strLine(line,endLine-line) ; 50 51 ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl 52 << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 53 << strLine<<endl 54 << string(columnNumber-1,'x')<<'^'<<endl) 55 // <<" Error : " << exc.what() ) 56 } 57 } 58 59 template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object, const std::set<StdString>& parseContextList) 60 { 61 62 string parentPath = currentIncludePath_ ; // save current path 63 string filePath = updateIncludePath(fluxId) ; // path is updated 64 65 StdIFStream stream(filePath, StdIFStream::in ) ; 66 if ( (stream.rdstate() & std::ifstream::failbit ) != 0 ) 67 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 68 <<endl<< "Can not open <"<<fluxId<<"> file" ); 69 70 if (!stream.good()) 71 ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId, T& object)", 72 << "[ filename = " << fluxId << " ] Bad xml stream !"); 73 74 75 StdOStringStream oss; 76 while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); 77 const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 78 try 79 { 80 rapidxml::xml_document<char> doc; 81 doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 82 CXMLNode node(doc.first_node()); 83 object.parse(node, true, parseContextList); 84 currentIncludePath_ = parentPath ; // restore include path 22 85 } 23 86 catch (rapidxml::parse_error & exc)
Note: See TracChangeset
for help on using the changeset viewer.